1{ config, lib, pkgs, options }: 2 3with lib; 4 5let 6 cfg = config.services.prometheus.exporters.snmp; 7in 8{ 9 port = 9116; 10 extraOpts = { 11 configurationPath = mkOption { 12 type = types.nullOr types.path; 13 default = null; 14 description = '' 15 Path to a snmp exporter configuration file. Mutually exclusive with 'configuration' option. 16 ''; 17 example = "./snmp.yml"; 18 }; 19 20 configuration = mkOption { 21 type = types.nullOr types.attrs; 22 default = null; 23 description = '' 24 Snmp exporter configuration as nix attribute set. Mutually exclusive with 'configurationPath' option. 25 ''; 26 example = '' 27 { 28 "default" = { 29 "version" = 2; 30 "auth" = { 31 "community" = "public"; 32 }; 33 }; 34 }; 35 ''; 36 }; 37 38 logFormat = mkOption { 39 type = types.enum ["logfmt" "json"]; 40 default = "logfmt"; 41 description = '' 42 Output format of log messages. 43 ''; 44 }; 45 46 logLevel = mkOption { 47 type = types.enum ["debug" "info" "warn" "error"]; 48 default = "info"; 49 description = '' 50 Only log messages with the given severity or above. 51 ''; 52 }; 53 }; 54 serviceOpts = let 55 configFile = if cfg.configurationPath != null 56 then cfg.configurationPath 57 else "${pkgs.writeText "snmp-exporter-conf.yml" (builtins.toJSON cfg.configuration)}"; 58 in { 59 serviceConfig = { 60 ExecStart = '' 61 ${pkgs.prometheus-snmp-exporter}/bin/snmp_exporter \ 62 --config.file=${escapeShellArg configFile} \ 63 --log.format=${escapeShellArg cfg.logFormat} \ 64 --log.level=${cfg.logLevel} \ 65 --web.listen-address=${cfg.listenAddress}:${toString cfg.port} \ 66 ${concatStringsSep " \\\n " cfg.extraFlags} 67 ''; 68 }; 69 }; 70}