diff options
Diffstat (limited to 'nixos/modules/services/logging')
-rw-r--r-- | nixos/modules/services/logging/logrotate.nix | 1 | ||||
-rw-r--r-- | nixos/modules/services/logging/logstash.nix | 69 | ||||
-rw-r--r-- | nixos/modules/services/logging/syslog-ng.nix | 38 |
3 files changed, 86 insertions, 22 deletions
diff --git a/nixos/modules/services/logging/logrotate.nix b/nixos/modules/services/logging/logrotate.nix index 6887ab1e8052..0186452de95e 100644 --- a/nixos/modules/services/logging/logrotate.nix +++ b/nixos/modules/services/logging/logrotate.nix @@ -21,6 +21,7 @@ in config = mkOption { default = ""; + type = types.lines; description = '' The contents of the logrotate config file ''; diff --git a/nixos/modules/services/logging/logstash.nix b/nixos/modules/services/logging/logstash.nix index df81ac142dc3..41f71be2365c 100644 --- a/nixos/modules/services/logging/logstash.nix +++ b/nixos/modules/services/logging/logstash.nix @@ -4,6 +4,9 @@ with lib; let cfg = config.services.logstash; + pluginPath = lib.concatStringsSep ":" cfg.plugins; + havePluginPath = lib.length cfg.plugins > 0; + ops = lib.optionalString; in @@ -20,12 +23,50 @@ in description = "Enable logstash."; }; + 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."; + }; + + 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."; + }; + enableWeb = mkOption { type = types.bool; default = false; description = "Enable the logstash web interface."; }; + 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."; + }; + inputConfig = mkOption { type = types.lines; default = ''stdin { type => "example" }''; @@ -79,19 +120,25 @@ in wantedBy = [ "multi-user.target" ]; environment = { JAVA_HOME = jre; }; serviceConfig = { - ExecStart = "${logstash}/bin/logstash agent -f ${writeText "logstash.conf" '' - input { - ${cfg.inputConfig} - } + ExecStart = + "${cfg.package}/bin/logstash agent " + + "-w ${toString cfg.filterWorkers} " + + ops havePluginPath "--pluginpath ${pluginPath} " + + "--watchdog-timeout ${toString cfg.watchdogTimeout} " + + "-f ${writeText "logstash.conf" '' + input { + ${cfg.inputConfig} + } - filter { - ${cfg.filterConfig} - } + filter { + ${cfg.filterConfig} + } - output { - ${cfg.outputConfig} - } - ''} ${optionalString cfg.enableWeb "-- web"}"; + output { + ${cfg.outputConfig} + } + ''} " + + ops cfg.enableWeb "-- web -a ${cfg.address} -p ${cfg.port}"; }; }; }; diff --git a/nixos/modules/services/logging/syslog-ng.nix b/nixos/modules/services/logging/syslog-ng.nix index 4a16b19134a0..f3991a411ec4 100644 --- a/nixos/modules/services/logging/syslog-ng.nix +++ b/nixos/modules/services/logging/syslog-ng.nix @@ -7,8 +7,7 @@ let cfg = config.services.syslog-ng; syslogngConfig = pkgs.writeText "syslog-ng.conf" '' - @version: 3.5 - @include "scl.conf" + ${cfg.configHeader} ${cfg.extraConfig} ''; @@ -44,13 +43,13 @@ in { The package providing syslog-ng binaries. ''; }; - serviceName = mkOption { - type = types.str; - default = "syslog-ng"; + listenToJournal = mkOption { + type = types.bool; + default = true; description = '' - The name of the systemd service that runs syslog-ng. Set this to - <literal>syslog</literal> if you want journald to automatically - forward all logs to syslog-ng. + Whether syslog-ng should listen to the syslog socket used + by journald, and therefore receive all logs that journald + produces. ''; }; extraModulePaths = mkOption { @@ -72,16 +71,33 @@ in { Configuration added to the end of <literal>syslog-ng.conf</literal>. ''; }; + configHeader = mkOption { + type = types.lines; + default = '' + @version: 3.5 + @include "scl.conf" + ''; + description = '' + The very first lines of the configuration file. Should usually contain + the syslog-ng version header. + ''; + }; }; }; config = mkIf cfg.enable { - systemd.services."${cfg.serviceName}" = { - wantedBy = [ "multi-user.target" ]; + systemd.sockets.syslog = mkIf cfg.listenToJournal { + wantedBy = [ "sockets.target" ]; + socketConfig.Service = "syslog-ng.service"; + }; + systemd.services.syslog-ng = { + description = "syslog-ng daemon"; preStart = "mkdir -p /{var,run}/syslog-ng"; + wantedBy = optional (!cfg.listenToJournal) "multi-user.target"; + after = [ "multi-user.target" ]; # makes sure hostname etc is set serviceConfig = { Type = "notify"; - Sockets = "syslog.socket"; + Sockets = if cfg.listenToJournal then "syslog.socket" else null; StandardOutput = "null"; Restart = "on-failure"; ExecStart = "${cfg.package}/sbin/syslog-ng ${concatStringsSep " " syslogngOptions}"; |