about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/unifi.nix
blob: 70f26d9783be5a975d62e61e1ad985466ebb7d8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ config, lib, pkgs, options }:

with lib;

let
  cfg = config.services.prometheus.exporters.unifi;
in
{
  port = 9130;
  extraOpts = {
    unifiAddress = mkOption {
      type = types.str;
      example = "https://10.0.0.1:8443";
      description = lib.mdDoc ''
        URL of the UniFi Controller API.
      '';
    };

    unifiInsecure = mkOption {
      type = types.bool;
      default = false;
      description = lib.mdDoc ''
        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 = lib.mdDoc ''
        username for authentication against UniFi Controller API.
      '';
    };

    unifiPassword = mkOption {
      type = types.str;
      description = lib.mdDoc ''
        Password for authentication against UniFi Controller API.
      '';
    };

    unifiTimeout = mkOption {
      type = types.str;
      default = "5s";
      example = "2m";
      description = lib.mdDoc ''
        Timeout including unit for UniFi Controller API requests.
      '';
    };
  };
  serviceOpts = {
    serviceConfig = {
      ExecStart = ''
        ${pkgs.prometheus-unifi-exporter}/bin/unifi_exporter \
          -telemetry.addr ${cfg.listenAddress}:${toString cfg.port} \
          -unifi.addr ${cfg.unifiAddress} \
          -unifi.username ${escapeShellArg cfg.unifiUsername} \
          -unifi.password ${escapeShellArg cfg.unifiPassword} \
          -unifi.timeout ${cfg.unifiTimeout} \
          ${optionalString cfg.unifiInsecure "-unifi.insecure" } \
          ${concatStringsSep " \\\n  " cfg.extraFlags}
      '';
    };
  };
}