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