1{ config, lib, pkgs, options }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.exporters.unpoller;
7
8 configFile = pkgs.writeText "prometheus-unpoller-exporter.json" (generators.toJSON {} {
9 poller = { inherit (cfg.log) debug quiet; };
10 unifi = { inherit (cfg) controllers; };
11 influxdb.disable = true;
12 datadog.disable = true; # workaround for https://github.com/unpoller/unpoller/issues/442
13 prometheus = {
14 http_listen = "${cfg.listenAddress}:${toString cfg.port}";
15 report_errors = cfg.log.prometheusErrors;
16 };
17 inherit (cfg) loki;
18 });
19
20in {
21 port = 9130;
22
23 extraOpts = {
24 inherit (options.services.unpoller.unifi) controllers;
25 inherit (options.services.unpoller) loki;
26 log = {
27 debug = mkEnableOption (lib.mdDoc "debug logging including line numbers, high resolution timestamps, per-device logs");
28 quiet = mkEnableOption (lib.mdDoc "startup and error logs only");
29 prometheusErrors = mkEnableOption (lib.mdDoc "emitting errors to prometheus");
30 };
31 };
32
33 serviceOpts.serviceConfig = {
34 ExecStart = "${pkgs.unpoller}/bin/unpoller --config ${configFile}";
35 DynamicUser = false;
36 };
37}