2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-07-11 17:22:16 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2012-07-11 17:22:16 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.logstash;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2014-09-05 15:28:24 +02:00
|
|
|
|
2012-07-11 17:22:16 +02:00
|
|
|
services.logstash = {
|
2014-09-05 15:28:24 +02:00
|
|
|
|
2012-07-11 17:22:16 +02:00
|
|
|
enable = mkOption {
|
2014-09-05 15:28:24 +02:00
|
|
|
type = types.bool;
|
2012-07-11 17:22:16 +02:00
|
|
|
default = false;
|
2014-09-05 15:28:24 +02:00
|
|
|
description = "Enable logstash.";
|
2012-07-11 17:22:16 +02:00
|
|
|
};
|
|
|
|
|
2014-06-18 13:36:53 +02:00
|
|
|
enableWeb = mkOption {
|
2014-09-05 15:28:24 +02:00
|
|
|
type = types.bool;
|
2014-06-18 13:36:53 +02:00
|
|
|
default = false;
|
2014-09-05 15:28:24 +02:00
|
|
|
description = "Enable the logstash web interface.";
|
2014-06-18 13:36:53 +02:00
|
|
|
};
|
|
|
|
|
2012-07-11 17:22:16 +02:00
|
|
|
inputConfig = mkOption {
|
2014-09-05 15:28:24 +02:00
|
|
|
type = types.lines;
|
2013-10-12 12:28:48 +02:00
|
|
|
default = ''stdin { type => "example" }'';
|
2014-09-05 15:28:24 +02:00
|
|
|
description = "Logstash input configuration.";
|
2013-10-31 15:59:59 +01:00
|
|
|
example = ''
|
|
|
|
# Read from journal
|
|
|
|
pipe {
|
|
|
|
command => "${pkgs.systemd}/bin/journalctl -f -o json"
|
|
|
|
type => "syslog" codec => json {}
|
|
|
|
}
|
|
|
|
'';
|
2012-07-11 17:22:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
filterConfig = mkOption {
|
2014-09-05 15:28:24 +02:00
|
|
|
type = types.lines;
|
2013-10-12 12:28:48 +02:00
|
|
|
default = ''noop {}'';
|
2014-09-05 15:28:24 +02:00
|
|
|
description = "logstash filter configuration.";
|
2013-10-31 15:59:59 +01:00
|
|
|
example = ''
|
|
|
|
if [type] == "syslog" {
|
|
|
|
# Keep only relevant systemd fields
|
|
|
|
# http://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html
|
|
|
|
prune {
|
|
|
|
whitelist_names => [
|
|
|
|
"type", "@timestamp", "@version",
|
|
|
|
"MESSAGE", "PRIORITY", "SYSLOG_FACILITY",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
2012-07-11 17:22:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
outputConfig = mkOption {
|
2014-09-05 15:28:24 +02:00
|
|
|
type = types.lines;
|
2013-10-12 12:28:48 +02:00
|
|
|
default = ''stdout { debug => true debug_format => "json"}'';
|
2014-09-05 15:28:24 +02:00
|
|
|
description = "Logstash output configuration.";
|
2013-10-31 15:59:59 +01:00
|
|
|
example = ''
|
|
|
|
redis { host => "localhost" data_type => "list" key => "logstash" codec => json }
|
|
|
|
elasticsearch { embedded => true }
|
|
|
|
'';
|
2012-07-11 17:22:16 +02:00
|
|
|
};
|
2014-09-05 15:28:24 +02:00
|
|
|
|
2012-07-11 17:22:16 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2013-10-12 12:28:48 +02:00
|
|
|
config = mkIf cfg.enable {
|
2013-01-16 12:33:18 +01:00
|
|
|
systemd.services.logstash = with pkgs; {
|
2014-06-18 13:36:53 +02:00
|
|
|
description = "Logstash Daemon";
|
2012-10-30 14:18:51 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2014-07-21 17:24:18 +02:00
|
|
|
environment = { JAVA_HOME = jre; };
|
2013-10-12 12:28:48 +02:00
|
|
|
serviceConfig = {
|
2014-07-21 17:24:18 +02:00
|
|
|
ExecStart = "${logstash}/bin/logstash agent -f ${writeText "logstash.conf" ''
|
2013-10-12 12:28:48 +02:00
|
|
|
input {
|
|
|
|
${cfg.inputConfig}
|
|
|
|
}
|
2012-07-11 17:22:16 +02:00
|
|
|
|
2013-10-12 12:28:48 +02:00
|
|
|
filter {
|
|
|
|
${cfg.filterConfig}
|
|
|
|
}
|
2012-07-11 17:22:16 +02:00
|
|
|
|
2013-10-12 12:28:48 +02:00
|
|
|
output {
|
|
|
|
${cfg.outputConfig}
|
|
|
|
}
|
2014-06-18 13:36:53 +02:00
|
|
|
''} ${optionalString cfg.enableWeb "-- web"}";
|
2013-10-12 12:28:48 +02:00
|
|
|
};
|
2012-07-11 17:22:16 +02:00
|
|
|
};
|
2013-10-12 12:28:48 +02:00
|
|
|
};
|
2012-07-11 17:22:16 +02:00
|
|
|
}
|