at master 2.3 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 options, 6 ... 7}: 8 9let 10 cfg = config.services.prometheus.exporters.junos-czerwonk; 11 inherit (lib) 12 mkOption 13 types 14 escapeShellArg 15 mkIf 16 concatStringsSep 17 ; 18 19 configFile = 20 if cfg.configuration != null then configurationFile else (escapeShellArg cfg.configurationFile); 21 22 configurationFile = pkgs.writeText "prometheus-junos-czerwonk-exporter.conf" ( 23 builtins.toJSON (cfg.configuration) 24 ); 25in 26{ 27 port = 9326; 28 extraOpts = { 29 environmentFile = mkOption { 30 type = types.nullOr types.str; 31 default = null; 32 description = '' 33 File containing env-vars to be substituted into the exporter's config. 34 ''; 35 }; 36 configurationFile = mkOption { 37 type = types.nullOr types.path; 38 default = null; 39 description = '' 40 Specify the JunOS exporter configuration file to use. 41 ''; 42 }; 43 configuration = mkOption { 44 type = types.nullOr types.attrs; 45 default = null; 46 description = '' 47 JunOS exporter configuration as nix attribute set. Mutually exclusive with the `configurationFile` option. 48 ''; 49 example = { 50 devices = [ 51 { 52 host = "router1"; 53 key_file = "/path/to/key"; 54 } 55 ]; 56 }; 57 }; 58 telemetryPath = mkOption { 59 type = types.str; 60 default = "/metrics"; 61 description = '' 62 Path under which to expose metrics. 63 ''; 64 }; 65 }; 66 serviceOpts = { 67 serviceConfig = { 68 DynamicUser = false; 69 EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ]; 70 RuntimeDirectory = "prometheus-junos-czerwonk-exporter"; 71 ExecStartPre = [ 72 "${pkgs.writeShellScript "subst-secrets-junos-czerwonk-exporter" '' 73 umask 0077 74 ${pkgs.envsubst}/bin/envsubst -i ${configFile} -o ''${RUNTIME_DIRECTORY}/junos-exporter.json 75 ''}" 76 ]; 77 ExecStart = '' 78 ${pkgs.prometheus-junos-czerwonk-exporter}/bin/junos_exporter \ 79 -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ 80 -web.telemetry-path ${cfg.telemetryPath} \ 81 -config.file ''${RUNTIME_DIRECTORY}/junos-exporter.json \ 82 ${concatStringsSep " \\\n " cfg.extraFlags} 83 ''; 84 }; 85 }; 86}