2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-07-11 16:22:16 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2012-07-11 16:22:16 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.logstash;
|
2014-10-05 18:57:15 +01:00
|
|
|
ops = lib.optionalString;
|
2018-08-03 11:23:56 +01:00
|
|
|
verbosityFlag = "--log.level " + cfg.logLevel;
|
|
|
|
|
2017-06-13 21:36:08 +01:00
|
|
|
logstashConf = pkgs.writeText "logstash.conf" ''
|
|
|
|
input {
|
|
|
|
${cfg.inputConfig}
|
|
|
|
}
|
|
|
|
|
|
|
|
filter {
|
|
|
|
${cfg.filterConfig}
|
|
|
|
}
|
|
|
|
|
|
|
|
output {
|
|
|
|
${cfg.outputConfig}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
logstashSettingsYml = pkgs.writeText "logstash.yml" cfg.extraSettings;
|
|
|
|
|
2018-11-08 10:59:03 +00:00
|
|
|
logstashSettingsDir = pkgs.runCommand "logstash-settings" {
|
|
|
|
inherit logstashSettingsYml;
|
|
|
|
preferLocalBuild = true;
|
|
|
|
} ''
|
2017-06-13 21:36:08 +01:00
|
|
|
mkdir -p $out
|
|
|
|
ln -s $logstashSettingsYml $out/logstash.yml
|
|
|
|
'';
|
2012-07-11 16:22:16 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "logstash" "address" ] [ "services" "logstash" "listenAddress" ])
|
|
|
|
(mkRemovedOptionModule [ "services" "logstash" "enableWeb" ] "The web interface was removed from logstash")
|
|
|
|
];
|
|
|
|
|
2012-07-11 16:22:16 +01:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2014-09-05 14:28:24 +01:00
|
|
|
|
2012-07-11 16:22:16 +01:00
|
|
|
services.logstash = {
|
2014-09-05 14:28:24 +01:00
|
|
|
|
2012-07-11 16:22:16 +01:00
|
|
|
enable = mkOption {
|
2014-09-05 14:28:24 +01:00
|
|
|
type = types.bool;
|
2012-07-11 16:22:16 +01:00
|
|
|
default = false;
|
2014-09-05 14:28:24 +01:00
|
|
|
description = "Enable logstash.";
|
2012-07-11 16:22:16 +01:00
|
|
|
};
|
|
|
|
|
2014-10-05 18:57:15 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.logstash;
|
2016-01-17 18:34:55 +00:00
|
|
|
defaultText = "pkgs.logstash";
|
2019-09-06 14:02:56 +01:00
|
|
|
example = literalExample "pkgs.logstash";
|
2014-10-05 18:57:15 +01:00
|
|
|
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.";
|
|
|
|
};
|
|
|
|
|
2017-06-13 21:36:08 +01:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/logstash";
|
|
|
|
description = ''
|
|
|
|
A path to directory writable by logstash that it uses to store data.
|
|
|
|
Plugins will also have access to this path.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-10-13 20:13:34 +01:00
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.enum [ "debug" "info" "warn" "error" "fatal" ];
|
|
|
|
default = "warn";
|
|
|
|
description = "Logging verbosity level.";
|
|
|
|
};
|
|
|
|
|
2014-10-05 18:57:15 +01:00
|
|
|
filterWorkers = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1;
|
|
|
|
description = "The quantity of filter workers to run.";
|
|
|
|
};
|
|
|
|
|
2016-12-20 17:27:29 +00:00
|
|
|
listenAddress = mkOption {
|
2014-10-05 18:57:15 +01:00
|
|
|
type = types.str;
|
2017-12-09 09:46:13 +00:00
|
|
|
default = "127.0.0.1";
|
2014-10-05 18:57:15 +01:00
|
|
|
description = "Address on which to start webserver.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "9292";
|
|
|
|
description = "Port on which to start webserver.";
|
|
|
|
};
|
|
|
|
|
2012-07-11 16:22:16 +01:00
|
|
|
inputConfig = mkOption {
|
2014-09-05 14:28:24 +01:00
|
|
|
type = types.lines;
|
2021-01-24 09:19:10 +00:00
|
|
|
default = "generator { }";
|
2014-09-05 14:28:24 +01:00
|
|
|
description = "Logstash input configuration.";
|
2016-02-29 00:47:12 +00:00
|
|
|
example = ''
|
2013-10-31 14:59:59 +00:00
|
|
|
# Read from journal
|
|
|
|
pipe {
|
2015-09-24 10:42:32 +01:00
|
|
|
command => "''${pkgs.systemd}/bin/journalctl -f -o json"
|
2013-10-31 14:59:59 +00:00
|
|
|
type => "syslog" codec => json {}
|
|
|
|
}
|
|
|
|
'';
|
2012-07-11 16:22:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
filterConfig = mkOption {
|
2014-09-05 14:28:24 +01:00
|
|
|
type = types.lines;
|
2016-12-20 17:26:49 +00:00
|
|
|
default = "";
|
2014-09-05 14:28:24 +01:00
|
|
|
description = "logstash filter configuration.";
|
2016-02-29 00:47:12 +00:00
|
|
|
example = ''
|
2013-10-31 14:59:59 +00:00
|
|
|
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",
|
2016-06-21 02:21:55 +01:00
|
|
|
"MESSAGE", "PRIORITY", "SYSLOG_FACILITY"
|
2013-10-31 14:59:59 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
2012-07-11 16:22:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
outputConfig = mkOption {
|
2014-09-05 14:28:24 +01:00
|
|
|
type = types.lines;
|
2021-01-24 09:19:10 +00:00
|
|
|
default = "stdout { codec => rubydebug }";
|
2014-09-05 14:28:24 +01:00
|
|
|
description = "Logstash output configuration.";
|
2013-10-31 14:59:59 +00:00
|
|
|
example = ''
|
2016-12-20 17:26:49 +00:00
|
|
|
redis { host => ["localhost"] data_type => "list" key => "logstash" codec => json }
|
|
|
|
elasticsearch { }
|
2013-10-31 14:59:59 +00:00
|
|
|
'';
|
2012-07-11 16:22:16 +01:00
|
|
|
};
|
2014-09-05 14:28:24 +01:00
|
|
|
|
2017-06-13 21:36:08 +01:00
|
|
|
extraSettings = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra Logstash settings in YAML format.";
|
|
|
|
example = ''
|
|
|
|
pipeline:
|
|
|
|
batch:
|
|
|
|
size: 125
|
|
|
|
delay: 5
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-07-11 16:22:16 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2013-10-12 11:28:48 +01:00
|
|
|
config = mkIf cfg.enable {
|
2021-03-22 13:19:34 +00:00
|
|
|
systemd.services.logstash = {
|
2014-06-18 12:36:53 +01:00
|
|
|
description = "Logstash Daemon";
|
2012-10-30 13:18:51 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2015-09-06 13:52:36 +01:00
|
|
|
path = [ pkgs.bash ];
|
2013-10-12 11:28:48 +01:00
|
|
|
serviceConfig = {
|
2017-06-13 21:36:08 +01:00
|
|
|
ExecStartPre = ''${pkgs.coreutils}/bin/mkdir -p "${cfg.dataDir}" ; ${pkgs.coreutils}/bin/chmod 700 "${cfg.dataDir}"'';
|
|
|
|
ExecStart = concatStringsSep " " (filter (s: stringLength s != 0) [
|
|
|
|
"${cfg.package}/bin/logstash"
|
|
|
|
"-w ${toString cfg.filterWorkers}"
|
2020-06-08 05:04:15 +01:00
|
|
|
(concatMapStringsSep " " (x: "--path.plugins ${x}") cfg.plugins)
|
2017-06-13 21:36:08 +01:00
|
|
|
"${verbosityFlag}"
|
|
|
|
"-f ${logstashConf}"
|
2018-08-03 11:23:56 +01:00
|
|
|
"--path.settings ${logstashSettingsDir}"
|
|
|
|
"--path.data ${cfg.dataDir}"
|
2017-06-13 21:36:08 +01:00
|
|
|
]);
|
2013-10-12 11:28:48 +01:00
|
|
|
};
|
2012-07-11 16:22:16 +01:00
|
|
|
};
|
2013-10-12 11:28:48 +01:00
|
|
|
};
|
2012-07-11 16:22:16 +01:00
|
|
|
}
|