From 097eb8257edf3ae428ae41d7ce404c75117f293f Mon Sep 17 00:00:00 2001 From: Jeff Hutchison Date: Fri, 18 Nov 2022 11:26:10 -0500 Subject: [PATCH 1/3] maintainers: add jhh --- maintainers/maintainer-list.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index 7a28c252764..54a1b853d40 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -6486,6 +6486,12 @@ githubId = 6445082; name = "Joseph Lukasik"; }; + jhh = { + email = "jeff@j3ff.io"; + github = "jhh"; + githubId = 14412; + name = "Jeff Hutchison"; + }; jhhuh = { email = "jhhuh.note@gmail.com"; github = "jhhuh"; From 0dc5bbbde9bd7e50c0438c9f1be8880424e0ce6a Mon Sep 17 00:00:00 2001 From: Jeff Hutchison Date: Thu, 24 Nov 2022 07:48:45 -0500 Subject: [PATCH 2/3] prometheus-nut-exporter: init at 2.4.2 --- .../monitoring/prometheus/nut-exporter.nix | 22 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 1 + 2 files changed, 23 insertions(+) create mode 100644 pkgs/servers/monitoring/prometheus/nut-exporter.nix diff --git a/pkgs/servers/monitoring/prometheus/nut-exporter.nix b/pkgs/servers/monitoring/prometheus/nut-exporter.nix new file mode 100644 index 00000000000..9877d7639bd --- /dev/null +++ b/pkgs/servers/monitoring/prometheus/nut-exporter.nix @@ -0,0 +1,22 @@ +{ lib, buildGoModule, fetchFromGitHub }: + +buildGoModule rec { + pname = "nut-exporter"; + version = "2.4.2"; + + src = fetchFromGitHub { + owner = "DRuggeri"; + repo = "nut_exporter"; + rev = "v${version}"; + sha256 = "sha256-fymVx6FJGII2PmWXVfeCRTxfO+35bmyn/9iL0iPuBgo="; + }; + + vendorSha256 = "sha256-ji8JlEYChPBakt5y6+zcm1l04VzZ0/fjfGFJ9p+1KHE="; + + meta = with lib; { + description = "Prometheus exporter for Network UPS Tools"; + homepage = "https://github.com/DRuggeri/nut_exporter"; + license = licenses.asl20; + maintainers = with maintainers; [ jhh ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 41ff5fb69f5..b28e862ae88 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -24348,6 +24348,7 @@ with pkgs; prometheus-node-exporter = callPackage ../servers/monitoring/prometheus/node-exporter.nix { inherit (darwin.apple_sdk.frameworks) CoreFoundation IOKit; }; + prometheus-nut-exporter = callPackage ../servers/monitoring/prometheus/nut-exporter.nix { }; prometheus-openldap-exporter = callPackage ../servers/monitoring/prometheus/openldap-exporter.nix { buildGoModule = buildGo118Module; # nixosTests.prometheus-exporter.ldap fails with 1.19 }; From a587e528c50d11b4d4e26a7dbd0b4ec6bd511bf3 Mon Sep 17 00:00:00 2001 From: Jeff Hutchison Date: Thu, 24 Nov 2022 07:50:09 -0500 Subject: [PATCH 3/3] Add prometheus-nut-exporter module --- .../monitoring/prometheus/exporters.nix | 1 + .../monitoring/prometheus/exporters/nut.nix | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/exporters/nut.nix diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 8826d80a70c..22b78981b2c 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -51,6 +51,7 @@ let "nginx" "nginxlog" "node" + "nut" "openldap" "openvpn" "pihole" 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}"} + ''; + }; +}