-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prometheus-dmarc-exporter: init at 0.5.1
- Loading branch information
Showing
8 changed files
with
703 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ let | |
"blackbox" | ||
"buildkite-agent" | ||
"collectd" | ||
"dmarc" | ||
"dnsmasq" | ||
"domain" | ||
"dovecot" | ||
|
117 changes: 117 additions & 0 deletions
117
nixos/modules/services/monitoring/prometheus/exporters/dmarc.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
pkgs/servers/monitoring/prometheus/dmarc-exporter/default.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" | ||
'' |
14 changes: 14 additions & 0 deletions
14
pkgs/servers/monitoring/prometheus/dmarc-exporter/poetry-git-overlay.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
}; | ||
} | ||
); | ||
|
||
} |
Oops, something went wrong.