Skip to content

Commit

Permalink
Add lumberjack output
Browse files Browse the repository at this point in the history
  • Loading branch information
bpaquet committed Mar 23, 2016
1 parent 65206bc commit e448e17
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
29 changes: 29 additions & 0 deletions docs/outputs/lumberjack.md
@@ -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.
63 changes: 63 additions & 0 deletions lib/outputs/output_lumberjack.js
@@ -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();
};
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -44,7 +44,8 @@
"maxmind": "0.6.x",
"maxmind-geolite-mirror": "1.0.x",
"http-proxy-agent": "1.x",
"https-proxy-agent": "1.x"
"https-proxy-agent": "1.x",
"lumberjack-protocol": "git://github.com/bpaquet/node-lumberjack-protocol.git"
},
"directories": {
"test": "./test",
Expand Down

0 comments on commit e448e17

Please sign in to comment.