1 { config, lib, pkgs, options, ... }:
4 cfg = config.services.prometheus.exporters.dmarc;
5 inherit (lib) mkOption types optionalString;
7 json = builtins.toJSON {
8 inherit (cfg) folders port;
9 listen_addr = cfg.listenAddress;
10 storage_path = "$STATE_DIRECTORY";
11 imap = (builtins.removeAttrs cfg.imap [ "passwordFile" ]) // { password = "$IMAP_PASSWORD"; use_ssl = true; };
12 poll_interval_seconds = cfg.pollIntervalSeconds;
13 deduplication_max_seconds = cfg.deduplicationMaxSeconds;
16 disable_existing_loggers = false;
25 default = "localhost";
27 Hostname of IMAP server to connect to.
34 Port of the IMAP server to connect to.
39 example = "postmaster@example.org";
41 Login username for the IMAP connection.
44 passwordFile = mkOption {
46 example = "/run/secrets/dovecot_pw";
48 File containing the login password for the IMAP connection.
57 IMAP mailbox that is checked for incoming DMARC aggregate reports
64 IMAP mailbox that successfully processed reports are moved to.
71 IMAP mailbox that emails are moved to that could not be processed.
75 pollIntervalSeconds = mkOption {
76 type = types.ints.unsigned;
79 How often to poll the IMAP server in seconds.
82 deduplicationMaxSeconds = mkOption {
83 type = types.ints.unsigned;
85 defaultText = "7 days (in seconds)";
87 How long individual report IDs will be remembered to avoid
88 counting double delivered reports twice.
95 Whether to declare enable `--debug`.
100 path = with pkgs; [ envsubst coreutils ];
102 StateDirectory = "prometheus-dmarc-exporter";
103 WorkingDirectory = "/var/lib/prometheus-dmarc-exporter";
104 ExecStart = "${pkgs.writeShellScript "setup-cfg" ''
105 export IMAP_PASSWORD="$(<${cfg.imap.passwordFile})"
107 -i ${pkgs.writeText "dmarc-exporter.json.template" json} \
108 -o ''${STATE_DIRECTORY}/dmarc-exporter.json
110 exec ${pkgs.dmarc-metrics-exporter}/bin/dmarc-metrics-exporter \
111 --configuration /var/lib/prometheus-dmarc-exporter/dmarc-exporter.json \
112 ${optionalString cfg.debug "--debug"}