summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/prometheus/exporters
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2022-12-03 02:22:48 +0100
committerGitHub <noreply@github.com>2022-12-03 02:22:48 +0100
commit068e7cb3409852b18ff9eceac7932dba4d1e1fb2 (patch)
treeea24cde6c3beca739c011eeafcfd1d72fabe376a /nixos/modules/services/monitoring/prometheus/exporters
parentcee75d23a9825985cad20b0deaac752766f6725c (diff)
parenta587e528c50d11b4d4e26a7dbd0b4ec6bd511bf3 (diff)
downloadnixpkgs-068e7cb3409852b18ff9eceac7932dba4d1e1fb2.tar
nixpkgs-068e7cb3409852b18ff9eceac7932dba4d1e1fb2.tar.gz
nixpkgs-068e7cb3409852b18ff9eceac7932dba4d1e1fb2.tar.bz2
nixpkgs-068e7cb3409852b18ff9eceac7932dba4d1e1fb2.tar.lz
nixpkgs-068e7cb3409852b18ff9eceac7932dba4d1e1fb2.tar.xz
nixpkgs-068e7cb3409852b18ff9eceac7932dba4d1e1fb2.tar.zst
nixpkgs-068e7cb3409852b18ff9eceac7932dba4d1e1fb2.zip
Merge pull request #201817 from jhh/nut-exporter
Diffstat (limited to 'nixos/modules/services/monitoring/prometheus/exporters')
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/nut.nix50
1 files changed, 50 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/nut.nix b/nixos/modules/services/monitoring/prometheus/exporters/nut.nix
new file mode 100644
index 00000000000..1c86b48b450
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/exporters/nut.nix
@@ -0,0 +1,50 @@
+{ config, lib, pkgs, options }:
+
+with lib;
+
+let
+  cfg = config.services.prometheus.exporters.nut;
+in
+{
+  port = 9199;
+  extraOpts = {
+    nutServer = mkOption {
+      type = types.str;
+      default = "127.0.0.1";
+      description = lib.mdDoc ''
+        Hostname or address of the NUT server
+      '';
+    };
+    nutUser = mkOption {
+      type = types.str;
+      default = "";
+      example = "nut";
+      description = lib.mdDoc ''
+        The user to log in into NUT server. If set, passwordPath should
+        also be set.
+
+        Default NUT configs usually permit reading variables without
+        authentication.
+      '';
+    };
+    passwordPath = mkOption {
+      type = types.nullOr types.path;
+      default = null;
+      apply = final: if final == null then null else toString final;
+      description = lib.mdDoc ''
+        A run-time path to the nutUser password file, which should be
+        provisioned outside of Nix store.
+      '';
+    };
+  };
+  serviceOpts = {
+    script = ''
+      ${optionalString (cfg.passwordPath != null)
+      "export NUT_EXPORTER_PASSWORD=$(cat ${toString cfg.passwordPath})"}
+      ${pkgs.prometheus-nut-exporter}/bin/nut_exporter \
+        --nut.server=${cfg.nutServer} \
+        --web.listen-address="${cfg.listenAddress}:${toString cfg.port}" \
+        ${optionalString (cfg.nutUser != "") "--nut.username=${cfg.nutUser}"}
+    '';
+  };
+}