Add prometheus-nut-exporter module

This commit is contained in:
Jeff Hutchison 2022-11-24 07:50:09 -05:00
parent 0dc5bbbde9
commit a587e528c5
No known key found for this signature in database
GPG Key ID: 26960A62CBEEC91D
2 changed files with 51 additions and 0 deletions

View File

@ -51,6 +51,7 @@ let
"nginx"
"nginxlog"
"node"
"nut"
"openldap"
"openvpn"
"pihole"

View File

@ -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}"}
'';
};
}