···
+
{ config, pkgs, lib, ... }:
+
cfg = config.services.prometheus.snmpExporter;
+
mkConfigFile = pkgs.writeText "snmp.yml" (if cfg.configurationPath == null then builtins.toJSON cfg.configuration else builtins.readFile cfg.configurationPath);
+
services.prometheus.snmpExporter = {
+
enable = mkEnableOption "Prometheus snmp exporter";
+
User name under which snmp exporter shall be run.
+
Group under which snmp exporter shall be run.
+
listenAddress = mkOption {
+
type = types.nullOr types.str;
+
Address to listen on for web interface and telemetry.
+
configurationPath = mkOption {
+
type = types.nullOr types.path;
+
Path to a snmp exporter configuration file. Mutually exclusive with 'configuration' option.
+
example = "./snmp.yml";
+
configuration = mkOption {
+
type = types.nullOr types.attrs;
+
Snmp exporter configuration as nix attribute set. Mutually exclusive with 'configurationPath' option.
+
"community" = "public";
+
default = "logger:stderr";
+
Set the log target and format.
+
type = types.enum ["debug" "info" "warn" "error" "fatal"];
+
Only log messages with the given severity or above.
+
openFirewall = mkOption {
+
Open port in firewall for incoming connections.
+
config = mkIf cfg.enable {
+
networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port;
+
assertion = (cfg.configurationPath == null) != (cfg.configuration == null);
+
message = "Please ensure you have either 'configuration' or 'configurationPath' set!";
+
systemd.services.prometheus-snmp-exporter = {
+
wantedBy = [ "multi-user.target" ];
+
after = [ "network.target" ];
+
${pkgs.prometheus-snmp-exporter.bin}/bin/snmp_exporter \
+
-config.file ${mkConfigFile} \
+
-log.format ${cfg.logFormat} \
+
-log.level ${cfg.logLevel} \
+
-web.listen-address ${optionalString (cfg.listenAddress != null) cfg.listenAddress}:${toString cfg.port}
+
WorkingDirectory = "/tmp";