1 { config, lib, pkgs, options, ... }:
4 cfg = config.services.prometheus.exporters.mail;
18 configFile = if cfg.configuration != null then configurationFile else (escapeShellArg cfg.configFile);
20 configurationFile = pkgs.writeText "prometheus-mail-exporter.conf" (builtins.toJSON (
21 # removes the _module attribute, null values and converts attrNames to lowercase
22 mapAttrs' (name: value:
24 then nameValuePair (toLower name)
25 ((map (srv: (mapAttrs' (n: v: nameValuePair (toLower n) v)
26 (filterAttrs (n: v: !(n == "_module" || v == null)) srv)
28 else nameValuePair (toLower name) value
29 ) (filterAttrs (n: _: !(n == "_module")) cfg.configuration)
32 serverOptions.options = {
36 Value for label 'configname' which will be added to all metrics.
42 Hostname of the server that should be probed.
54 example = "exporteruser@domain.tld";
56 Content of 'From' Header for probing mails.
61 example = "exporteruser@domain.tld";
63 Content of 'To' Header for probing mails.
66 detectionDir = mkOption {
68 example = "/var/spool/mail/exporteruser/new";
70 Directory in which new mails for the exporter user are placed.
71 Note that this needs to exist when the exporter starts.
75 type = types.nullOr types.str;
77 example = "exporteruser@domain.tld";
79 Username to use for SMTP authentication.
82 passphrase = mkOption {
83 type = types.nullOr types.str;
86 Password to use for SMTP authentication.
91 exporterOptions.options = {
92 monitoringInterval = mkOption {
96 Time interval between two probe attempts.
99 mailCheckTimeout = mkOption {
102 Timeout until mails are considered "didn't make it".
105 disableFileDeletion = mkOption {
109 Disables the exporter's function to delete probing mails.
113 type = types.listOf (types.submodule serverOptions);
115 example = literalExpression ''
118 server = "smtp.domain.tld";
120 from = "exporteruser@domain.tld";
121 to = "exporteruser@domain.tld";
122 detectionDir = "/path/to/Maildir/new";
126 List of servers that should be probed.
128 *Note:* if your mailserver has {manpage}`rspamd(8)` configured,
129 it can happen that emails from this exporter are marked as spam.
131 It's possible to work around the issue with a config like this:
134 services.rspamd.locals."multimap.conf".text = '''
135 ALLOWLIST_PROMETHEUS {
136 filter = "email:domain:tld";
138 map = "''${pkgs.writeText "allowmap" "domain.tld"}";
151 environmentFile = mkOption {
152 type = types.nullOr types.str;
155 File containing env-vars to be substituted into the exporter's config.
158 configFile = mkOption {
159 type = types.nullOr types.path;
162 Specify the mailexporter configuration file to use.
165 configuration = mkOption {
166 type = types.nullOr (types.submodule exporterOptions);
169 Specify the mailexporter configuration file to use.
172 telemetryPath = mkOption {
174 default = "/metrics";
176 Path under which to expose metrics.
183 EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ];
184 RuntimeDirectory = "prometheus-mail-exporter";
186 "${pkgs.writeShellScript "subst-secrets-mail-exporter" ''
188 ${pkgs.envsubst}/bin/envsubst -i ${configFile} -o ''${RUNTIME_DIRECTORY}/mail-exporter.json
192 ${pkgs.prometheus-mail-exporter}/bin/mailexporter \
193 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
194 --web.telemetry-path ${cfg.telemetryPath} \
195 --config.file ''${RUNTIME_DIRECTORY}/mail-exporter.json \
196 ${concatStringsSep " \\\n " cfg.extraFlags}