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