summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2021-12-03 17:59:53 +0100
committergithub-actions[bot] <github-actions[bot]@users.noreply.github.com>2021-12-03 19:30:47 +0000
commitc3e4c445aa6c38adb4214d28018446260ac9417e (patch)
tree82d99ea7dfde20f3dc0a4e97c92cf59a107573b2
parentpythonPackages.awkward: 1.5.1 -> 1.7.0 (diff)
downloadnixpkgs-c3e4c445aa6c38adb4214d28018446260ac9417e.tar.gz
nixos/prometheus-postfix-exporter: whitelist addr-family `AF_UNIX`
Otherwise, `postfix_up{path="/var/lib/postfix/queue/public/showq"}` will always be `0` indicating an postfix outage because this is a unix domain socket that cannot be connected to: 2021/12/03 14:50:46 Failed to scrape showq socket: dial unix /var/lib/postfix/queue/public/showq: socket: address family not supported by protocol (cherry picked from commit 8e6d403e65c62b052123e4a8eed295885d3dd4eb)
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/postfix.nix3
-rw-r--r--nixos/tests/prometheus-exporters.nix3
2 files changed, 6 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix b/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix
index f57589a59c7b..4d3c1fa267e5 100644
--- a/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix
+++ b/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix
@@ -76,6 +76,9 @@ in
serviceOpts = {
serviceConfig = {
DynamicUser = false;
+ # By default, each prometheus exporter only gets AF_INET & AF_INET6,
+ # but AF_UNIX is needed to read from the `showq`-socket.
+ RestrictAddressFamilies = [ "AF_UNIX" ];
ExecStart = ''
${pkgs.prometheus-postfix-exporter}/bin/postfix_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix
index d069854328a2..80052a40c3f8 100644
--- a/nixos/tests/prometheus-exporters.nix
+++ b/nixos/tests/prometheus-exporters.nix
@@ -861,6 +861,9 @@ let
wait_for_unit("prometheus-postfix-exporter.service")
wait_for_file("/var/lib/postfix/queue/public/showq")
wait_for_open_port(9154)
+ wait_until_succeeds(
+ "curl -sSf http://localhost:9154/metrics | grep 'postfix_up{path=\"/var/lib/postfix/queue/public/showq\"} 1'"
+ )
succeed(
"curl -sSf http://localhost:9154/metrics | grep 'postfix_smtpd_connects_total 0'"
)