diff options
author | Pascal Bach <pascal.bach@nextrem.ch> | 2017-03-07 23:47:05 +0100 |
---|---|---|
committer | Robin Gloster <mail@glob.in> | 2017-03-17 15:41:22 +0100 |
commit | 3728143cbcead48f387dd7297f76138a82ed04de (patch) | |
tree | 5a81b8caf398eeab0c0fcfd629cd0d3e3448432b /nixos/modules/services/monitoring | |
parent | 017fddb4be7d5c074a0b3e2dfb26b88d5e90ceaf (diff) | |
download | nixlib-3728143cbcead48f387dd7297f76138a82ed04de.tar nixlib-3728143cbcead48f387dd7297f76138a82ed04de.tar.gz nixlib-3728143cbcead48f387dd7297f76138a82ed04de.tar.bz2 nixlib-3728143cbcead48f387dd7297f76138a82ed04de.tar.lz nixlib-3728143cbcead48f387dd7297f76138a82ed04de.tar.xz nixlib-3728143cbcead48f387dd7297f76138a82ed04de.tar.zst nixlib-3728143cbcead48f387dd7297f76138a82ed04de.zip |
prometheus-unifi-exporter: init at 0.4.0
Diffstat (limited to 'nixos/modules/services/monitoring')
-rw-r--r-- | nixos/modules/services/monitoring/prometheus/unifi-exporter.nix | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/unifi-exporter.nix b/nixos/modules/services/monitoring/prometheus/unifi-exporter.nix new file mode 100644 index 000000000000..e3059e485098 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/unifi-exporter.nix @@ -0,0 +1,104 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.services.prometheus.unifiExporter; +in { + options = { + services.prometheus.unifiExporter = { + enable = mkEnableOption "prometheus unifi exporter"; + + port = mkOption { + type = types.int; + default = 9130; + description = '' + Port to listen on. + ''; + }; + + unifiAddress = mkOption { + type = types.str; + example = "https://10.0.0.1:8443"; + description = '' + URL of the UniFi Controller API. + ''; + }; + + unifiInsecure = mkOption { + type = types.bool; + default = false; + description = '' + If enabled skip the verification of the TLS certificate of the UniFi Controller API. + Use with caution. + ''; + }; + + unifiUsername = mkOption { + type = types.str; + example = "ReadOnlyUser"; + description = '' + username for authentication against UniFi Controller API. + ''; + }; + + unifiPassword = mkOption { + type = types.str; + description = '' + Password for authentication against UniFi Controller API. + ''; + }; + + unifiTimeout = mkOption { + type = types.str; + default = "5s"; + example = "2m"; + description = '' + Timeout including unit for UniFi Controller API requests. + ''; + }; + + extraFlags = mkOption { + type = types.listOf types.str; + default = []; + description = '' + Extra commandline options when launching the unifi exporter. + ''; + }; + + openFirewall = mkOption { + type = types.bool; + default = false; + description = '' + Open port in firewall for incoming connections. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port; + + systemd.services.prometheus-unifi-exporter = { + description = "Prometheus exporter for UniFi Controller metrics"; + unitConfig.Documentation = "https://github.com/mdlayher/unifi_exporter"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + User = "nobody"; + Restart = "always"; + PrivateTmp = true; + WorkingDirectory = /tmp; + ExecStart = '' + ${pkgs.prometheus-unifi-exporter}/bin/unifi_exporter \ + -telemetry.addr :${toString cfg.port} \ + -unifi.addr ${cfg.unifiAddress} \ + -unifi.username ${cfg.unifiUsername} \ + -unifi.password ${cfg.unifiPassword} \ + -unifi.timeout ${cfg.unifiTimeout} \ + ${optionalString cfg.unifiInsecure "-unifi.insecure" } \ + ${concatStringsSep " \\\n " cfg.extraFlags} + ''; + }; + }; + }; +} |