···
1
+
{ config, pkgs, lib, ... }:
6
+
cfg = config.services.prometheus.snmpExporter;
7
+
mkConfigFile = pkgs.writeText "snmp.yml" (if cfg.configurationPath == null then builtins.toJSON cfg.configuration else builtins.readFile cfg.configurationPath);
10
+
services.prometheus.snmpExporter = {
11
+
enable = mkEnableOption "Prometheus snmp exporter";
17
+
User name under which snmp exporter shall be run.
23
+
default = "nogroup";
25
+
Group under which snmp exporter shall be run.
37
+
listenAddress = mkOption {
38
+
type = types.nullOr types.str;
41
+
Address to listen on for web interface and telemetry.
45
+
configurationPath = mkOption {
46
+
type = types.nullOr types.path;
49
+
Path to a snmp exporter configuration file. Mutually exclusive with 'configuration' option.
51
+
example = "./snmp.yml";
54
+
configuration = mkOption {
55
+
type = types.nullOr types.attrs;
58
+
Snmp exporter configuration as nix attribute set. Mutually exclusive with 'configurationPath' option.
65
+
"community" = "public";
72
+
logFormat = mkOption {
74
+
default = "logger:stderr";
76
+
Set the log target and format.
80
+
logLevel = mkOption {
81
+
type = types.enum ["debug" "info" "warn" "error" "fatal"];
84
+
Only log messages with the given severity or above.
88
+
openFirewall = mkOption {
92
+
Open port in firewall for incoming connections.
98
+
config = mkIf cfg.enable {
99
+
networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port;
101
+
assertions = singleton
103
+
assertion = (cfg.configurationPath == null) != (cfg.configuration == null);
104
+
message = "Please ensure you have either 'configuration' or 'configurationPath' set!";
107
+
systemd.services.prometheus-snmp-exporter = {
108
+
wantedBy = [ "multi-user.target" ];
109
+
after = [ "network.target" ];
111
+
${pkgs.prometheus-snmp-exporter.bin}/bin/snmp_exporter \
112
+
-config.file ${mkConfigFile} \
113
+
-log.format ${cfg.logFormat} \
114
+
-log.level ${cfg.logLevel} \
115
+
-web.listen-address ${optionalString (cfg.listenAddress != null) cfg.listenAddress}:${toString cfg.port}
121
+
Restart = "always";
123
+
WorkingDirectory = "/tmp";