diff options
Diffstat (limited to 'nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/mail.nix')
-rw-r--r-- | nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/mail.nix | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/mail.nix b/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/mail.nix index 956bd96aa454..205188538a21 100644 --- a/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/mail.nix +++ b/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/mail.nix @@ -5,6 +5,8 @@ with lib; let cfg = config.services.prometheus.exporters.mail; + configFile = if cfg.configuration != null then configurationFile else (escapeShellArg cfg.configFile); + configurationFile = pkgs.writeText "prometheus-mail-exporter.conf" (builtins.toJSON ( # removes the _module attribute, null values and converts attrNames to lowercase mapAttrs' (name: value: @@ -20,41 +22,41 @@ let serverOptions.options = { name = mkOption { type = types.str; - description = '' + description = lib.mdDoc '' Value for label 'configname' which will be added to all metrics. ''; }; server = mkOption { type = types.str; - description = '' + description = lib.mdDoc '' Hostname of the server that should be probed. ''; }; port = mkOption { type = types.int; example = 587; - description = '' + description = lib.mdDoc '' Port to use for SMTP. ''; }; from = mkOption { type = types.str; example = "exporteruser@domain.tld"; - description = '' + description = lib.mdDoc '' Content of 'From' Header for probing mails. ''; }; to = mkOption { type = types.str; example = "exporteruser@domain.tld"; - description = '' + description = lib.mdDoc '' Content of 'To' Header for probing mails. ''; }; detectionDir = mkOption { type = types.path; example = "/var/spool/mail/exporteruser/new"; - description = '' + description = lib.mdDoc '' Directory in which new mails for the exporter user are placed. Note that this needs to exist when the exporter starts. ''; @@ -63,14 +65,14 @@ let type = types.nullOr types.str; default = null; example = "exporteruser@domain.tld"; - description = '' + description = lib.mdDoc '' Username to use for SMTP authentication. ''; }; passphrase = mkOption { type = types.nullOr types.str; default = null; - description = '' + description = lib.mdDoc '' Password to use for SMTP authentication. ''; }; @@ -80,20 +82,20 @@ let monitoringInterval = mkOption { type = types.str; example = "10s"; - description = '' + description = lib.mdDoc '' Time interval between two probe attempts. ''; }; mailCheckTimeout = mkOption { type = types.str; - description = '' + description = lib.mdDoc '' Timeout until mails are considered "didn't make it". ''; }; disableFileDeletion = mkOption { type = types.bool; default = false; - description = '' + description = lib.mdDoc '' Disables the exporter's function to delete probing mails. ''; }; @@ -113,8 +115,7 @@ let description = '' List of servers that should be probed. - <emphasis>Note:</emphasis> if your mailserver has <citerefentry> - <refentrytitle>rspamd</refentrytitle><manvolnum>8</manvolnum></citerefentry> configured, + <emphasis>Note:</emphasis> if your mailserver has <citerefentry><refentrytitle>rspamd</refentrytitle><manvolnum>8</manvolnum></citerefentry> configured, it can happen that emails from this exporter are marked as spam. It's possible to work around the issue with a config like this: @@ -137,24 +138,31 @@ in { port = 9225; extraOpts = { + environmentFile = mkOption { + type = types.nullOr types.str; + default = null; + description = lib.mdDoc '' + File containing env-vars to be substituted into the exporter's config. + ''; + }; configFile = mkOption { type = types.nullOr types.path; default = null; - description = '' + description = lib.mdDoc '' Specify the mailexporter configuration file to use. ''; }; configuration = mkOption { type = types.nullOr (types.submodule exporterOptions); default = null; - description = '' + description = lib.mdDoc '' Specify the mailexporter configuration file to use. ''; }; telemetryPath = mkOption { type = types.str; default = "/metrics"; - description = '' + description = lib.mdDoc '' Path under which to expose metrics. ''; }; @@ -162,13 +170,19 @@ in serviceOpts = { serviceConfig = { DynamicUser = false; + EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ]; + RuntimeDirectory = "prometheus-mail-exporter"; + ExecStartPre = [ + "${pkgs.writeShellScript "subst-secrets-mail-exporter" '' + umask 0077 + ${pkgs.envsubst}/bin/envsubst -i ${configFile} -o ''${RUNTIME_DIRECTORY}/mail-exporter.json + ''}" + ]; ExecStart = '' ${pkgs.prometheus-mail-exporter}/bin/mailexporter \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ --web.telemetry-path ${cfg.telemetryPath} \ - --config.file ${ - if cfg.configuration != null then configurationFile else (escapeShellArg cfg.configFile) - } \ + --config.file ''${RUNTIME_DIRECTORY}/mail-exporter.json \ ${concatStringsSep " \\\n " cfg.extraFlags} ''; }; |