1{ config, lib, pkgs }: 2 3with lib; 4 5let 6 cfg = config.services.prometheus.exporters.unifi; 7in 8{ 9 port = 9130; 10 extraOpts = { 11 unifiAddress = mkOption { 12 type = types.str; 13 example = "https://10.0.0.1:8443"; 14 description = '' 15 URL of the UniFi Controller API. 16 ''; 17 }; 18 19 unifiInsecure = mkOption { 20 type = types.bool; 21 default = false; 22 description = '' 23 If enabled skip the verification of the TLS certificate of the UniFi Controller API. 24 Use with caution. 25 ''; 26 }; 27 28 unifiUsername = mkOption { 29 type = types.str; 30 example = "ReadOnlyUser"; 31 description = '' 32 username for authentication against UniFi Controller API. 33 ''; 34 }; 35 36 unifiPassword = mkOption { 37 type = types.str; 38 description = '' 39 Password for authentication against UniFi Controller API. 40 ''; 41 }; 42 43 unifiTimeout = mkOption { 44 type = types.str; 45 default = "5s"; 46 example = "2m"; 47 description = '' 48 Timeout including unit for UniFi Controller API requests. 49 ''; 50 }; 51 }; 52 serviceOpts = { 53 serviceConfig = { 54 DynamicUser = true; 55 ExecStart = '' 56 ${pkgs.prometheus-unifi-exporter}/bin/unifi_exporter \ 57 -telemetry.addr ${cfg.listenAddress}:${toString cfg.port} \ 58 -unifi.addr ${cfg.unifiAddress} \ 59 -unifi.username ${cfg.unifiUsername} \ 60 -unifi.password ${cfg.unifiPassword} \ 61 -unifi.timeout ${cfg.unifiTimeout} \ 62 ${optionalString cfg.unifiInsecure "-unifi.insecure" } \ 63 ${concatStringsSep " \\\n " cfg.extraFlags} 64 ''; 65 }; 66 }; 67}