Skip to content

Commit

Permalink
prometheus-dmarc-exporter: init at 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma27 committed Feb 28, 2022
1 parent 972c309 commit 5cee9c9
Show file tree
Hide file tree
Showing 8 changed files with 703 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/modules/services/monitoring/prometheus/exporters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let
"blackbox"
"buildkite-agent"
"collectd"
"dmarc"
"dnsmasq"
"domain"
"dovecot"
Expand Down
117 changes: 117 additions & 0 deletions nixos/modules/services/monitoring/prometheus/exporters/dmarc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{ config, lib, pkgs, options }:

with lib;

let
cfg = config.services.prometheus.exporters.dmarc;

json = builtins.toJSON {
inherit (cfg) folders port;
listen_addr = cfg.listenAddress;
storage_path = "$STATE_DIRECTORY";
imap = (builtins.removeAttrs cfg.imap [ "passwordFile" ]) // { password = "$IMAP_PASSWORD"; use_ssl = true; };
poll_interval_seconds = cfg.pollIntervalSeconds;
deduplication_max_seconds = cfg.deduplicationMaxSeconds;
logging = {
version = 1;
disable_existing_loggers = false;
};
};
in {
port = 9797;
extraOpts = {
imap = {
host = mkOption {
type = types.str;
default = "localhost";
description = ''
Hostname of IMAP server to connect to.
'';
};
port = mkOption {
type = types.port;
default = 993;
description = ''
Port of the IMAP server to connect to.
'';
};
username = mkOption {
type = types.str;
example = "[email protected]";
description = ''
Login username for the IMAP connection.
'';
};
passwordFile = mkOption {
type = types.str;
example = "/run/secrets/dovecot_pw";
description = ''
File containing the login password for the IMAP connection.
'';
};
};
folders = {
inbox = mkOption {
type = types.str;
default = "INBOX";
description = ''
IMAP mailbox that is checked for incoming DMARC aggregate reports
'';
};
done = mkOption {
type = types.str;
default = "Archive";
description = ''
IMAP mailbox that successfully processed reports are moved to.
'';
};
error = mkOption {
type = types.str;
default = "Invalid";
description = ''
IMAP mailbox that emails are moved to that could not be processed.
'';
};
};
pollIntervalSeconds = mkOption {
type = types.ints.unsigned;
default = 60;
description = ''
How often to poll the IMAP server in seconds.
'';
};
deduplicationMaxSeconds = mkOption {
type = types.ints.unsigned;
default = 604800;
defaultText = "7 days (in seconds)";
description = ''
How long individual report IDs will be remembered to avoid
counting double delivered reports twice.
'';
};
debug = mkOption {
type = types.bool;
default = false;
description = ''
Whether to declare enable <literal>--debug</literal>.
'';
};
};
serviceOpts = {
path = with pkgs; [ envsubst coreutils ];
serviceConfig = {
StateDirectory = "prometheus-dmarc-exporter";
WorkingDirectory = "/var/lib/prometheus-dmarc-exporter";
ExecStart = "${pkgs.writeShellScript "setup-cfg" ''
export IMAP_PASSWORD="$(<${cfg.imap.passwordFile})"
envsubst \
-i ${pkgs.writeText "dmarc-exporter.json.template" json} \
-o ''${STATE_DIRECTORY}/dmarc-exporter.json
exec ${pkgs.prometheus-dmarc-exporter}/bin/prometheus-dmarc-exporter \
--configuration /var/lib/prometheus-dmarc-exporter/dmarc-exporter.json \
${optionalString cfg.debug "--debug"}
''}";
};
};
}
48 changes: 48 additions & 0 deletions pkgs/servers/monitoring/prometheus/dmarc-exporter/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ poetry2nix, pkgs, lib }:

let
inherit (poetry2nix.mkPoetryPackages {
projectDir = ./.;
overrides = [
poetry2nix.defaultPoetryOverrides
(import ./poetry-git-overlay.nix { inherit pkgs; })
(self: super: {
more-properties = super.more-properties.overridePythonAttrs (old: {
src = pkgs.fetchFromGitHub {
owner = "madman-bob";
repo = "python-more-properties";
rev = old.version;
sha256 = "sha256-dKG97rw5IG19m7u3ZDBM2yGScL5cFaKBvGZxPVJaUTE=";
};
postPatch = ''
sed -i -e '/dataclasses/d' requirements.txt
cp ./pypi_upload/setup.py setup.py
substituteInPlace setup.py \
--replace "parents[1]" "parents[0]"
'';
});
dataclasses-serialization = super.dataclasses-serialization.overridePythonAttrs (old: {
src = pkgs.fetchFromGitHub {
owner = "madman-bob";
repo = "python-dataclasses-serialization";
rev = old.version;
sha256 = "sha256-jLMR2D01KgzHHRP0zduMBJt8xgBmIquWLCjZYLo2/AA=";
};
postPatch = ''
sed -i -e '/dataclasses/d' requirements.txt
cp ./pypi_upload/setup.py setup.py
substituteInPlace setup.py \
--replace "parents[1]" "parents[0]"
'';
});
dataclasses = null;
})
];
}) python;
env = python.withPackages (p: [ p.dmarc-metrics-exporter ]);
in

pkgs.writeShellScriptBin "prometheus-dmarc-exporter" ''
export PYTHONPATH="${env}/lib/${env.libPrefix}/site-packages''${PYTHONPATH:+:}''${PYTHONPATH}"
exec ${env}/bin/python3 -m dmarc_metrics_exporter "$@"
''
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ pkgs }:
self: super: {

dmarc-metrics-exporter = super.dmarc-metrics-exporter.overridePythonAttrs (
_: {
src = pkgs.fetchgit {
url = "https://github.com/jgosmann/dmarc-metrics-exporter.git";
rev = "3f1a0161d7ed51b9de48c056dcbc545b6375e872";
sha256 = "18sndv32ig0xq7s42hvkdxbb9qxvycmnrawm3x22cp7zfidgfkh2";
};
}
);

}
Loading

0 comments on commit 5cee9c9

Please sign in to comment.