Merge pull request #265696 from Stunkymonkey/nixos-exportarr

nixos/exportarr: init

authored by

Felix Bühler and committed by
GitHub
f2fc5b41 582f1e73

+110 -8
+2
nixos/doc/manual/release-notes/rl-2311.section.md
··· 127 127 128 128 - [ZITADEL](https://zitadel.com), a turnkey identity and access management platform. Available as [services.zitadel](#opt-services.zitadel.enable). 129 129 130 + - [exportarr](https://github.com/onedr0p/exportarr), Prometheus Exporters for Bazarr, Lidarr, Prowlarr, Radarr, Readarr, and Sonarr. Available as [services.prometheus.exporters.exportarr-bazarr](#opt-services.prometheus.exporters.exportarr-bazarr.enable)/[services.prometheus.exporters.exportarr-lidarr](#opt-services.prometheus.exporters.exportarr-lidarr.enable)/[services.prometheus.exporters.exportarr-prowlarr](#opt-services.prometheus.exporters.exportarr-prowlarr.enable)/[services.prometheus.exporters.exportarr-radarr](#opt-services.prometheus.exporters.exportarr-radarr.enable)/[services.prometheus.exporters.exportarr-readarr](#opt-services.prometheus.exporters.exportarr-readarr.enable)/[services.prometheus.exporters.exportarr-sonarr](#opt-services.prometheus.exporters.exportarr-sonarr.enable). 131 + 130 132 - [netclient](https://github.com/gravitl/netclient), an automated WireGuard® Management Client. Available as [services.netclient](#opt-services.netclient.enable). 131 133 132 134 - [trunk-ng](https://github.com/ctron/trunk), A fork of `trunk`: Build, bundle & ship your Rust WASM application to the web
+38 -8
nixos/modules/services/monitoring/prometheus/exporters.nix
··· 2 2 3 3 let 4 4 inherit (lib) concatStrings foldl foldl' genAttrs literalExpression maintainers 5 - mapAttrsToList mkDefault mkEnableOption mkIf mkMerge mkOption 6 - optional types mkOptionDefault flip attrNames; 5 + mapAttrs mapAttrsToList mkDefault mkEnableOption mkIf mkMerge mkOption 6 + optional types mkOptionDefault flip attrNames; 7 7 8 8 cfg = config.services.prometheus.exporters; 9 9 ··· 20 20 # systemd service must be provided by specifying either 21 21 # `serviceOpts.script` or `serviceOpts.serviceConfig.ExecStart` 22 22 23 - exporterOpts = genAttrs [ 23 + exporterOpts = (genAttrs [ 24 24 "apcupsd" 25 25 "artifactory" 26 26 "bind" ··· 34 34 "domain" 35 35 "dovecot" 36 36 "fastly" 37 + "flow" 37 38 "fritzbox" 38 39 "graphite" 39 40 "idrac" 40 41 "imap-mailstat" 41 42 "influxdb" 42 43 "ipmi" 43 - "json" 44 44 "jitsi" 45 + "json" 45 46 "junos-czerwonk" 46 47 "kea" 47 48 "keylight" ··· 74 75 "scaphandre" 75 76 "script" 76 77 "shelly" 77 - "snmp" 78 78 "smartctl" 79 79 "smokeping" 80 + "snmp" 80 81 "sql" 81 82 "statsd" 82 83 "surfboard" ··· 88 89 "v2ray" 89 90 "varnish" 90 91 "wireguard" 91 - "flow" 92 92 "zfs" 93 - ] (name: 94 - import (./. + "/exporters/${name}.nix") { inherit config lib pkgs options; } 93 + ] 94 + (name: 95 + import (./. + "/exporters/${name}.nix") { inherit config lib pkgs options; } 96 + )) // (mapAttrs 97 + (name: params: 98 + import (./. + "/exporters/${params.name}.nix") { inherit config lib pkgs options; type = params.type ; }) 99 + { 100 + exportarr-bazarr = { 101 + name = "exportarr"; 102 + type = "bazarr"; 103 + }; 104 + exportarr-lidarr = { 105 + name = "exportarr"; 106 + type = "lidarr"; 107 + }; 108 + exportarr-prowlarr = { 109 + name = "exportarr"; 110 + type = "prowlarr"; 111 + }; 112 + exportarr-radarr = { 113 + name = "exportarr"; 114 + type = "radarr"; 115 + }; 116 + exportarr-readarr = { 117 + name = "exportarr"; 118 + type = "readarr"; 119 + }; 120 + exportarr-sonarr = { 121 + name = "exportarr"; 122 + type = "sonarr"; 123 + }; 124 + } 95 125 ); 96 126 97 127 mkExporterOpts = ({ name, port }: {
+55
nixos/modules/services/monitoring/prometheus/exporters/exportarr.nix
··· 1 + { config, lib, pkgs, options, type }: 2 + 3 + let 4 + cfg = config.services.prometheus.exporters."exportarr-${type}"; 5 + exportarrEnvironment = ( 6 + lib.mapAttrs (_: toString) cfg.environment 7 + ) // { 8 + PORT = toString cfg.port; 9 + URL = cfg.url; 10 + API_KEY_FILE = lib.mkIf (cfg.apiKeyFile != null) "%d/api-key"; 11 + }; 12 + in 13 + { 14 + port = 9708; 15 + extraOpts = { 16 + url = lib.mkOption { 17 + type = lib.types.str; 18 + default = "http://127.0.0.1"; 19 + description = lib.mdDoc '' 20 + The full URL to Sonarr, Radarr, or Lidarr. 21 + ''; 22 + }; 23 + 24 + apiKeyFile = lib.mkOption { 25 + type = lib.types.nullOr lib.types.path; 26 + default = null; 27 + description = lib.mdDoc '' 28 + File containing the api-key. 29 + ''; 30 + }; 31 + 32 + package = lib.mkPackageOptionMD pkgs "exportarr" { }; 33 + 34 + environment = lib.mkOption { 35 + type = lib.types.attrsOf lib.types.str; 36 + default = { }; 37 + description = lib.mdDoc '' 38 + See [the configuration guide](https://github.com/onedr0p/exportarr#configuration) for available options. 39 + ''; 40 + example = { 41 + PROWLARR__BACKFILL = true; 42 + }; 43 + }; 44 + }; 45 + serviceOpts = { 46 + serviceConfig = { 47 + LoadCredential = lib.optionalString (cfg.apiKeyFile != null) "api-key:${cfg.apiKeyFile}"; 48 + ExecStart = ''${cfg.package}/bin/exportarr ${type} "$@"''; 49 + ProcSubset = "pid"; 50 + ProtectProc = "invisible"; 51 + SystemCallFilter = ["@system-service" "~@privileged"]; 52 + }; 53 + environment = exportarrEnvironment; 54 + }; 55 + }
+15
nixos/tests/prometheus-exporters.nix
··· 257 257 ''; 258 258 }; 259 259 260 + exportarr-sonarr = { 261 + nodeName = "exportarr_sonarr"; 262 + exporterConfig = { 263 + enable = true; 264 + url = "http://127.0.0.1:8989"; 265 + # testing for real data is tricky, because the api key can not be preconfigured 266 + apiKeyFile = pkgs.writeText "dummy-api-key" "eccff6a992bc2e4b88e46d064b26bb4e"; 267 + }; 268 + exporterTest = '' 269 + wait_for_unit("prometheus-exportarr-sonarr-exporter.service") 270 + wait_for_open_port(9707) 271 + succeed("curl -sSf 'http://localhost:9707/metrics") 272 + ''; 273 + }; 274 + 260 275 fastly = { 261 276 exporterConfig = { 262 277 enable = true;