forked from bpaquet/node-logstash
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Lumberjack output plugin | ||
--- | ||
|
||
Status : core plugin, maintained. | ||
|
||
|
||
This plugin is used to sent data to logstash server, using lumberjack protocol. | ||
The connection must be secured with TLS. | ||
|
||
Example: | ||
Config using url: ``output://lumberjack://localhost:5044?ca=ca.crt`` | ||
|
||
Config using logstash format: | ||
```` | ||
output { | ||
lumberjack { | ||
host => localhost | ||
port => 5044 | ||
ca => "ca.crt" | ||
} | ||
} | ||
```` | ||
|
||
Parameters: | ||
|
||
* ``host``: ip of the logstash server. | ||
* ``port``: port of the logstash server. | ||
* ``ssl_ca``, ``ssl_key``, ``ssl_cert``, ``ssl_rejectUnauthorized``: TLS params. More doc at [ssl](../ssl.md). | ||
* ``max_queue_size``: number of message to store in memory before dropping. Default: 500. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var base_output = require('../lib/base_output'), | ||
util = require('util'), | ||
logger = require('log4node'), | ||
error_buffer = require('../lib/error_buffer'), | ||
ssl_helper = require('../lib/ssl_helper'), | ||
lumberjack = require('lumberjack-protocol'); | ||
|
||
function OutputLumberJack() { | ||
base_output.BaseOutput.call(this); | ||
this.mergeConfig(ssl_helper.config()); | ||
this.mergeConfig(error_buffer.config(function() { | ||
return 'lumber jack to ' + this.host + ':' + this.port; | ||
})); | ||
this.mergeConfig({ | ||
name: 'Lumber Jack', | ||
host_field: 'host', | ||
port_field: 'port', | ||
optional_params: ['crt', 'key', 'ca', 'max_queue_size'], | ||
default_values: { | ||
max_queue_size: 500, | ||
}, | ||
start_hook: this.start, | ||
}); | ||
} | ||
|
||
util.inherits(OutputLumberJack, base_output.BaseOutput); | ||
|
||
OutputLumberJack.prototype.start = function(callback) { | ||
logger.info('Creating LumberJack output to', this.host + ':' + this.port, 'using ca', this.ca); | ||
var options = { | ||
maxQueueSize: this.max_queue_size, | ||
}; | ||
var tls_options = ssl_helper.merge_options(this, { | ||
host: this.host, | ||
port: this.port, | ||
}); | ||
console.log(tls_options); | ||
this.client = lumberjack.client(tls_options, options); | ||
this.client.on('dropped', function(count) { | ||
this.error_buffer.emit('error', new Error('Dropping data, queue size :' + count)); | ||
}.bind(this)); | ||
callback(); | ||
}; | ||
|
||
OutputLumberJack.prototype.process = function(data) { | ||
if (this.client) { | ||
this.client.writeDataFrame(data, function() { | ||
this.error_buffer.emit('ok'); | ||
}.bind(this)); | ||
} | ||
}; | ||
|
||
OutputLumberJack.prototype.close = function(callback) { | ||
logger.info('Closing LumberJack output to', this.host + ':' + this.port); | ||
if (this.client) { | ||
this.client.close(); | ||
} | ||
callback(); | ||
}; | ||
|
||
exports.create = function() { | ||
return new OutputLumberJack(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters