From 51ddcb481f73e90137a19b2948a77185d885b794 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 12 Apr 2025 02:53:40 +0200 Subject: [PATCH 1/2] prometheus-mailman3-exporter: init at 0.9.1 --- .../prometheus-mailman3-exporter/package.nix | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 pkgs/by-name/pr/prometheus-mailman3-exporter/package.nix diff --git a/pkgs/by-name/pr/prometheus-mailman3-exporter/package.nix b/pkgs/by-name/pr/prometheus-mailman3-exporter/package.nix new file mode 100644 index 000000000000..b15a356c6e37 --- /dev/null +++ b/pkgs/by-name/pr/prometheus-mailman3-exporter/package.nix @@ -0,0 +1,63 @@ +{ + lib, + python3, + stdenv, + fetchFromGitHub, + fetchpatch2, +}: + +let + python = python3.withPackages ( + pp: with pp; [ + certifi + charset-normalizer + idna + prometheus-client + requests + six + urllib3 + ] + ); +in +stdenv.mkDerivation rec { + pname = "mailman3-exporter"; + version = "0.9.1"; + + src = fetchFromGitHub { + owner = "rivimey"; + repo = "mailman3_exporter"; + tag = version; + hash = "sha256-IupfZ3/MXBYpIyH8kJRc+WYabzSZyIu1WDITKTB5+Zc="; + }; + + patches = [ + # https://github.com/rivimey/mailman3_exporter/pull/3 + (fetchpatch2 { + url = "https://github.com/MarcelCoding/mailman3_exporter/commit/65070106451c6aafe8956387111343e490e34df8.patch?full_index=1"; + hash = "sha256-2XM0ktLC4+7/PEgeToVR84Gfjx1UKxl/+jo6JGnVZMw="; + }) + # https://github.com/rivimey/mailman3_exporter/pull/4 + (fetchpatch2 { + url = "https://github.com/MarcelCoding/mailman3_exporter/commit/a7850a1e9ce65f91683eef67eb1c6537c2c2eb77.patch?full_index=1"; + hash = "sha256-bBIin/7Y1bWrvxCuw1kJG8gaoKjkKdQnxfqpRipvyFs="; + }) + ]; + + buildInputs = [ + python + ]; + + installPhase = '' + install -D mailman_exporter.py $out/bin/mailman3_exporter + ''; + + meta = { + description = "Mailman3 Exporter for Prometheus"; + homepage = "https://github.com/rivimey/mailman3_exporter"; + # no license in repo + license = lib.licenses.unfree; + maintainers = with lib.maintainers; [ marcel ]; + mainProgram = "mailman3_exporter"; + platforms = lib.platforms.all; + }; +} From d33d1dda8f50f1cf681ff8806bede4c9b5e8d599 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 12 Apr 2025 03:42:54 +0200 Subject: [PATCH 2/2] nixos/prometheus-mailman3-exporter: init module --- .../monitoring/prometheus/exporters.nix | 1 + .../prometheus/exporters/mailman3.nix | 77 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/exporters/mailman3.nix diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 258d13e3c7c7..0e92249ccba8 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -85,6 +85,7 @@ let "libvirt" "lnd" "mail" + "mailman3" "mikrotik" "modemmanager" "mongodb" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/mailman3.nix b/nixos/modules/services/monitoring/prometheus/exporters/mailman3.nix new file mode 100644 index 000000000000..cbfede2bb9e2 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/mailman3.nix @@ -0,0 +1,77 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.prometheus.exporters.mailman3; +in +{ + port = 9934; + extraOpts = { + logLevel = lib.mkOption { + type = lib.types.enum [ + "debug" + "info" + "warning" + "error" + "critical" + ]; + default = "info"; + description = '' + Detail level to log. + ''; + }; + + mailman = { + addr = lib.mkOption { + type = lib.types.str; + default = "http://127.0.0.1:8001"; + description = '' + Mailman3 Core REST API address. + ''; + }; + + user = lib.mkOption { + type = lib.types.str; + default = "restadmin"; + description = '' + Mailman3 Core REST API username. + ''; + }; + + passFile = lib.mkOption { + type = lib.types.str; + default = config.services.mailman.restApiPassFile; + defaultText = lib.literalExpression "config.services.mailman.restApiPassFile"; + description = '' + Mailman3 Core REST API password. + ''; + }; + }; + }; + serviceOpts = { + serviceConfig = { + LoadCredential = [ + "password:${cfg.mailman.passFile}" + ]; + ExecStart = + let + addr = "${ + if (lib.hasInfix ":" cfg.listenAddress) then "[${cfg.listenAddress}]" else cfg.listenAddress + }:${toString cfg.port}"; + in + '' + ${lib.getExe pkgs.prometheus-mailman3-exporter} \ + --log-level ${cfg.logLevel} \ + --web.listen ${addr} \ + --mailman.address ${cfg.mailman.addr} \ + --mailman.user ${cfg.mailman.user} \ + --mailman.password-file %d/password \ + ${lib.concatStringsSep " \\\n " cfg.extraFlags} + ''; + }; + }; +}