From f412df1f6bf9104e3444375946434fe3cd35de26 Mon Sep 17 00:00:00 2001 From: WilliButz Date: Fri, 6 Jul 2018 21:13:13 +0200 Subject: [PATCH 1/4] nixos/prometheus-postfix-exporter: set default group The postfix exporter needs to access postfix's `queue/public/` directory to read the `showq` socket inside. Instead of making the public directory world accessible, this sets the postfix exporter's group to `postdrop` by default, when the postfix service is enabled. --- .../modules/services/monitoring/prometheus/exporters.nix | 2 ++ .../services/monitoring/prometheus/exporters/postfix.nix | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index cc71451bf206..4d15fb12ff73 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -229,6 +229,8 @@ in })] ++ [(mkIf config.services.nginx.enable { systemd.services.prometheus-nginx-exporter.after = [ "nginx.service" ]; systemd.services.prometheus-nginx-exporter.requires = [ "nginx.service" ]; + })] ++ [(mkIf config.services.postfix.enable { + services.prometheus.exporters.postfix.group = mkDefault config.services.postfix.setgidGroup; })] ++ (mapAttrsToList (name: conf: mkExporterConf { inherit name; diff --git a/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix b/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix index 3b6ef1631f89..e818b6e37b3f 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix @@ -8,6 +8,15 @@ in { port = 9154; extraOpts = { + group = mkOption { + type = types.str; + description = '' + Group under which the postfix exporter shall be run. + It should match the group that is allowed to access the + showq socket in the queue/public/ directory. + Defaults to services.postfix.setgidGroup when postfix is enabled. + ''; + }; telemetryPath = mkOption { type = types.str; default = "/metrics"; From 0e3f6318312f8510287b15f15b42823b0695883c Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Fri, 25 Sep 2020 14:27:29 +0200 Subject: [PATCH 2/4] prometheus postfix exporter test: check showq --- nixos/tests/prometheus-exporters.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index fdcc40721324..5b9fff5a4f2f 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -466,10 +466,12 @@ let }; exporterTest = '' wait_for_unit("prometheus-postfix-exporter.service") + wait_for_file("/var/lib/postfix/queue/public/showq") wait_for_open_port(9154) succeed( "curl -sSf http://localhost:9154/metrics | grep -q 'postfix_smtpd_connects_total 0'" ) + succeed("curl -sSf http://localhost:9154/metrics | grep -q 'postfix_up{.*} 1'") ''; }; From e80fa279688262b3c3d390ba8e55eaed598eac24 Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Fri, 25 Sep 2020 14:28:32 +0200 Subject: [PATCH 3/4] nixos/prometheus/postfix: correct default showqPath --- .../services/monitoring/prometheus/exporters/postfix.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix b/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix index e818b6e37b3f..237620a6220d 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix @@ -35,10 +35,10 @@ in }; showqPath = mkOption { type = types.path; - default = "/var/spool/postfix/public/showq"; - example = "/var/lib/postfix/queue/public/showq"; + default = "/var/lib/postfix/queue/public/showq"; + example = "/var/spool/postfix/public/showq"; description = '' - Path where Postfix places it's showq socket. + Path where Postfix places its showq socket. ''; }; systemd = { From edcb73f6b52d0b9f7f0208b089bdb05eb5b854c7 Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Fri, 25 Sep 2020 14:29:16 +0200 Subject: [PATCH 4/4] nixos/prometheus/postfix: enable systemd by default --- .../monitoring/prometheus/exporters/postfix.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix b/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix index 237620a6220d..f57589a59c7b 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix @@ -42,9 +42,13 @@ in ''; }; systemd = { - enable = mkEnableOption '' - reading metrics from the systemd-journal instead of from a logfile - ''; + enable = mkOption { + type = types.bool; + default = true; + description = '' + Whether to enable reading metrics from the systemd journal instead of from a logfile + ''; + }; unit = mkOption { type = types.str; default = "postfix.service";