1{ config, lib, pkgs }: 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 = {}; 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.str; 40 default = "logger:stderr"; 41 description = '' 42 Set the log target and format. 43 ''; 44 }; 45 46 logLevel = mkOption { 47 type = types.enum ["debug" "info" "warn" "error" "fatal"]; 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-eporter-conf.yml" (builtins.toJSON cfg.configuration)}"; 58 in { 59 serviceConfig = { 60 DynamicUser = true; 61 ExecStart = '' 62 ${pkgs.prometheus-snmp-exporter.bin}/bin/snmp_exporter \ 63 -config.file ${configFile} \ 64 -log.format ${cfg.logFormat} \ 65 -log.level ${cfg.logLevel} \ 66 -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ 67 ${concatStringsSep " \\\n " cfg.extraFlags} 68 ''; 69 }; 70 }; 71}