2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-07-11 15:22:16 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2012-07-11 15:22:16 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.logstash;
|
2014-10-05 17:57:15 +00:00
|
|
|
pluginPath = lib.concatStringsSep ":" cfg.plugins;
|
|
|
|
havePluginPath = lib.length cfg.plugins > 0;
|
|
|
|
ops = lib.optionalString;
|
2014-10-13 19:13:34 +00:00
|
|
|
verbosityFlag = {
|
|
|
|
debug = "--debug";
|
|
|
|
info = "--verbose";
|
|
|
|
warn = ""; # intentionally empty
|
|
|
|
error = "--quiet";
|
|
|
|
fatal = "--silent";
|
|
|
|
}."${cfg.logLevel}";
|
2012-07-11 15:22:16 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2014-09-05 13:28:24 +00:00
|
|
|
|
2012-07-11 15:22:16 +00:00
|
|
|
services.logstash = {
|
2014-09-05 13:28:24 +00:00
|
|
|
|
2012-07-11 15:22:16 +00:00
|
|
|
enable = mkOption {
|
2014-09-05 13:28:24 +00:00
|
|
|
type = types.bool;
|
2012-07-11 15:22:16 +00:00
|
|
|
default = false;
|
2014-09-05 13:28:24 +00:00
|
|
|
description = "Enable logstash.";
|
2012-07-11 15:22:16 +00:00
|
|
|
};
|
|
|
|
|
2014-10-05 17:57:15 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.logstash;
|
|
|
|
example = literalExample "pkgs.logstash";
|
|
|
|
description = "Logstash package to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [ ];
|
|
|
|
example = literalExample "[ pkgs.logstash-contrib ]";
|
|
|
|
description = "The paths to find other logstash plugins in.";
|
|
|
|
};
|
|
|
|
|
2014-10-13 19:13:34 +00:00
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.enum [ "debug" "info" "warn" "error" "fatal" ];
|
|
|
|
default = "warn";
|
|
|
|
description = "Logging verbosity level.";
|
|
|
|
};
|
|
|
|
|
2014-10-05 17:57:15 +00:00
|
|
|
watchdogTimeout = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 10;
|
|
|
|
description = "Set watchdog timeout value in seconds.";
|
|
|
|
};
|
|
|
|
|
|
|
|
filterWorkers = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1;
|
|
|
|
description = "The quantity of filter workers to run.";
|
|
|
|
};
|
|
|
|
|
2014-06-18 11:36:53 +00:00
|
|
|
enableWeb = mkOption {
|
2014-09-05 13:28:24 +00:00
|
|
|
type = types.bool;
|
2014-06-18 11:36:53 +00:00
|
|
|
default = false;
|
2014-09-05 13:28:24 +00:00
|
|
|
description = "Enable the logstash web interface.";
|
2014-06-18 11:36:53 +00:00
|
|
|
};
|
|
|
|
|
2014-10-05 17:57:15 +00:00
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
|
|
|
description = "Address on which to start webserver.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "9292";
|
|
|
|
description = "Port on which to start webserver.";
|
|
|
|
};
|
|
|
|
|
2012-07-11 15:22:16 +00:00
|
|
|
inputConfig = mkOption {
|
2014-09-05 13:28:24 +00:00
|
|
|
type = types.lines;
|
2013-10-12 10:28:48 +00:00
|
|
|
default = ''stdin { type => "example" }'';
|
2014-09-05 13:28:24 +00:00
|
|
|
description = "Logstash input configuration.";
|
2015-09-24 09:42:32 +00:00
|
|
|
example = literalExample ''
|
2013-10-31 14:59:59 +00:00
|
|
|
# Read from journal
|
|
|
|
pipe {
|
2015-09-24 09:42:32 +00:00
|
|
|
command => "''${pkgs.systemd}/bin/journalctl -f -o json"
|
2013-10-31 14:59:59 +00:00
|
|
|
type => "syslog" codec => json {}
|
|
|
|
}
|
|
|
|
'';
|
2012-07-11 15:22:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
filterConfig = mkOption {
|
2014-09-05 13:28:24 +00:00
|
|
|
type = types.lines;
|
2013-10-12 10:28:48 +00:00
|
|
|
default = ''noop {}'';
|
2014-09-05 13:28:24 +00:00
|
|
|
description = "logstash filter configuration.";
|
2013-10-31 14:59:59 +00: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 15:22:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
outputConfig = mkOption {
|
2014-09-05 13:28:24 +00:00
|
|
|
type = types.lines;
|
2013-10-12 10:28:48 +00:00
|
|
|
default = ''stdout { debug => true debug_format => "json"}'';
|
2014-09-05 13:28:24 +00:00
|
|
|
description = "Logstash output configuration.";
|
2013-10-31 14:59:59 +00:00
|
|
|
example = ''
|
|
|
|
redis { host => "localhost" data_type => "list" key => "logstash" codec => json }
|
|
|
|
elasticsearch { embedded => true }
|
|
|
|
'';
|
2012-07-11 15:22:16 +00:00
|
|
|
};
|
2014-09-05 13:28:24 +00:00
|
|
|
|
2012-07-11 15:22:16 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2013-10-12 10:28:48 +00:00
|
|
|
config = mkIf cfg.enable {
|
2013-01-16 11:33:18 +00:00
|
|
|
systemd.services.logstash = with pkgs; {
|
2014-06-18 11:36:53 +00:00
|
|
|
description = "Logstash Daemon";
|
2012-10-30 13:18:51 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2014-07-21 15:24:18 +00:00
|
|
|
environment = { JAVA_HOME = jre; };
|
2015-09-06 12:52:36 +00:00
|
|
|
path = [ pkgs.bash ];
|
2013-10-12 10:28:48 +00:00
|
|
|
serviceConfig = {
|
2014-10-05 17:57:15 +00:00
|
|
|
ExecStart =
|
|
|
|
"${cfg.package}/bin/logstash agent " +
|
|
|
|
"-w ${toString cfg.filterWorkers} " +
|
|
|
|
ops havePluginPath "--pluginpath ${pluginPath} " +
|
2014-10-13 19:13:34 +00:00
|
|
|
"${verbosityFlag} " +
|
2014-10-05 17:57:15 +00:00
|
|
|
"--watchdog-timeout ${toString cfg.watchdogTimeout} " +
|
|
|
|
"-f ${writeText "logstash.conf" ''
|
|
|
|
input {
|
|
|
|
${cfg.inputConfig}
|
|
|
|
}
|
2012-07-11 15:22:16 +00:00
|
|
|
|
2014-10-05 17:57:15 +00:00
|
|
|
filter {
|
|
|
|
${cfg.filterConfig}
|
|
|
|
}
|
2012-07-11 15:22:16 +00:00
|
|
|
|
2014-10-05 17:57:15 +00:00
|
|
|
output {
|
|
|
|
${cfg.outputConfig}
|
|
|
|
}
|
|
|
|
''} " +
|
|
|
|
ops cfg.enableWeb "-- web -a ${cfg.address} -p ${cfg.port}";
|
2013-10-12 10:28:48 +00:00
|
|
|
};
|
2012-07-11 15:22:16 +00:00
|
|
|
};
|
2013-10-12 10:28:48 +00:00
|
|
|
};
|
2012-07-11 15:22:16 +00:00
|
|
|
}
|