10 cfg = config.services.prometheus.exporters.mail;
25 if cfg.configuration != null then configurationFile else (escapeShellArg cfg.configFile);
27 configurationFile = pkgs.writeText "prometheus-mail-exporter.conf" (
29 # removes the _module attribute, null values and converts attrNames to lowercase
32 if name == "servers" then
33 nameValuePair (toLower name) (
36 (mapAttrs' (n: v: nameValuePair (toLower n) v) (
37 filterAttrs (n: v: !(n == "_module" || v == null)) srv
43 nameValuePair (toLower name) value
44 ) (filterAttrs (n: _: !(n == "_module")) cfg.configuration)
48 serverOptions.options = {
52 Value for label 'configname' which will be added to all metrics.
58 Hostname of the server that should be probed.
70 example = "exporteruser@domain.tld";
72 Content of 'From' Header for probing mails.
77 example = "exporteruser@domain.tld";
79 Content of 'To' Header for probing mails.
82 detectionDir = mkOption {
84 example = "/var/spool/mail/exporteruser/new";
86 Directory in which new mails for the exporter user are placed.
87 Note that this needs to exist when the exporter starts.
91 type = types.nullOr types.str;
93 example = "exporteruser@domain.tld";
95 Username to use for SMTP authentication.
98 passphrase = mkOption {
99 type = types.nullOr types.str;
102 Password to use for SMTP authentication.
107 exporterOptions.options = {
108 monitoringInterval = mkOption {
112 Time interval between two probe attempts.
115 mailCheckTimeout = mkOption {
118 Timeout until mails are considered "didn't make it".
121 disableFileDeletion = mkOption {
125 Disables the exporter's function to delete probing mails.
129 type = types.listOf (types.submodule serverOptions);
131 example = literalExpression ''
134 server = "smtp.domain.tld";
136 from = "exporteruser@domain.tld";
137 to = "exporteruser@domain.tld";
138 detectionDir = "/path/to/Maildir/new";
142 List of servers that should be probed.
144 *Note:* if your mailserver has {manpage}`rspamd(8)` configured,
145 it can happen that emails from this exporter are marked as spam.
147 It's possible to work around the issue with a config like this:
150 services.rspamd.locals."multimap.conf".text = '''
151 ALLOWLIST_PROMETHEUS {
152 filter = "email:domain:tld";
154 map = "''${pkgs.writeText "allowmap" "domain.tld"}";
167 environmentFile = mkOption {
168 type = types.nullOr types.str;
171 File containing env-vars to be substituted into the exporter's config.
174 configFile = mkOption {
175 type = types.nullOr types.path;
178 Specify the mailexporter configuration file to use.
181 configuration = mkOption {
182 type = types.nullOr (types.submodule exporterOptions);
185 Specify the mailexporter configuration file to use.
188 telemetryPath = mkOption {
190 default = "/metrics";
192 Path under which to expose metrics.
199 EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ];
200 RuntimeDirectory = "prometheus-mail-exporter";
202 "${pkgs.writeShellScript "subst-secrets-mail-exporter" ''
204 ${pkgs.envsubst}/bin/envsubst -i ${configFile} -o ''${RUNTIME_DIRECTORY}/mail-exporter.json
208 ${pkgs.prometheus-mail-exporter}/bin/mailexporter \
209 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
210 --web.telemetry-path ${cfg.telemetryPath} \
211 --config.file ''${RUNTIME_DIRECTORY}/mail-exporter.json \
212 ${concatStringsSep " \\\n " cfg.extraFlags}