8 cfg = config.services.unpoller;
10 configFile = pkgs.writeText "unpoller.json" (
11 lib.generators.toJSON { } {
25 (lib.mkRenamedOptionModule [ "services" "unifi-poller" ] [ "services" "unpoller" ])
28 options.services.unpoller = {
29 enable = lib.mkEnableOption "unpoller";
32 debug = lib.mkOption {
33 type = lib.types.bool;
36 Turns on line numbers, microsecond logging, and a per-device log.
37 This may be noisy if you have a lot of devices. It adds one line per device.
40 quiet = lib.mkOption {
41 type = lib.types.bool;
44 Turns off per-interval logs. Only startup and error logs will be emitted.
47 plugins = lib.mkOption {
48 type = with lib.types; listOf str;
51 Load additional plugins.
57 disable = lib.mkOption {
58 type = lib.types.bool;
61 Whether to disable the prometheus output plugin.
64 http_listen = lib.mkOption {
66 default = "[::]:9130";
68 Bind the prometheus exporter to this IP or hostname.
71 report_errors = lib.mkOption {
72 type = lib.types.bool;
75 Whether to report errors.
81 disable = lib.mkOption {
82 type = lib.types.bool;
85 Whether to disable the influxdb output plugin.
90 default = "http://127.0.0.1:8086";
92 URL of the influxdb host.
97 default = "unifipoller";
99 Username for the influxdb.
102 pass = lib.mkOption {
103 type = lib.types.path;
104 default = pkgs.writeText "unpoller-influxdb-default.password" "unifipoller";
105 defaultText = lib.literalExpression "unpoller-influxdb-default.password";
107 Path of a file containing the password for influxdb.
108 This file needs to be readable by the unifi-poller user.
110 apply = v: "file://${v}";
113 type = lib.types.str;
116 Database name. Database should exist.
119 verify_ssl = lib.mkOption {
120 type = lib.types.bool;
123 Verify the influxdb's certificate.
126 interval = lib.mkOption {
127 type = lib.types.str;
130 Setting this lower than the Unifi controller's refresh
131 interval may lead to zeroes in your database.
138 type = lib.types.str;
141 URL of the Loki host.
144 user = lib.mkOption {
145 type = lib.types.str;
151 pass = lib.mkOption {
152 type = lib.types.path;
153 default = pkgs.writeText "unpoller-loki-default.password" "";
154 defaultText = "unpoller-influxdb-default.password";
156 Path of a file containing the password for Loki.
157 This file needs to be readable by the unifi-poller user.
159 apply = v: "file://${v}";
161 verify_ssl = lib.mkOption {
162 type = lib.types.bool;
165 Verify Loki's certificate.
168 tenant_id = lib.mkOption {
169 type = lib.types.str;
172 Tenant ID to use in Loki.
175 interval = lib.mkOption {
176 type = lib.types.str;
179 How often the events are polled and pushed to Loki.
182 timeout = lib.mkOption {
183 type = lib.types.str;
186 Should be increased in case of timeout errors.
193 controllerOptions = {
194 user = lib.mkOption {
195 type = lib.types.str;
198 Unifi service user name.
201 pass = lib.mkOption {
202 type = lib.types.path;
203 default = pkgs.writeText "unpoller-unifi-default.password" "unifi";
204 defaultText = lib.literalExpression "unpoller-unifi-default.password";
206 Path of a file containing the password for the unifi service user.
207 This file needs to be readable by the unifi-poller user.
209 apply = v: "file://${v}";
212 type = lib.types.str;
213 default = "https://unifi:8443";
215 URL of the Unifi controller.
218 sites = lib.mkOption {
227 List of site names for which statistics should be exported.
228 Or the string "default" for the default site or the string "all" for all sites.
232 save_ids = lib.mkOption {
233 type = lib.types.bool;
236 Collect and save data from the intrusion detection system to influxdb and Loki.
239 save_events = lib.mkOption {
240 type = lib.types.bool;
243 Collect and save data from UniFi events to influxdb and Loki.
246 save_alarms = lib.mkOption {
247 type = lib.types.bool;
250 Collect and save data from UniFi alarms to influxdb and Loki.
253 save_anomalies = lib.mkOption {
254 type = lib.types.bool;
257 Collect and save data from UniFi anomalies to influxdb and Loki.
260 save_dpi = lib.mkOption {
261 type = lib.types.bool;
264 Collect and save data from deep packet inspection.
265 Adds around 150 data points and impacts performance.
268 save_sites = lib.mkOption {
269 type = lib.types.bool;
272 Collect and save site data.
275 hash_pii = lib.mkOption {
276 type = lib.types.bool;
279 Hash, with md5, client names and MAC addresses. This attempts
280 to protect personally identifiable information.
283 verify_ssl = lib.mkOption {
284 type = lib.types.bool;
287 Verify the Unifi controller's certificate.
294 dynamic = lib.mkOption {
295 type = lib.types.bool;
298 Let prometheus select which controller to poll when scraping.
299 Use with default credentials. See unifi-poller wiki for more.
303 defaults = controllerOptions;
305 controllers = lib.mkOption {
309 options = controllerOptions;
313 List of Unifi controllers to poll. Use defaults if empty.
315 apply = map (lib.flip removeAttrs [ "_module" ]);
320 config = lib.mkIf cfg.enable {
321 users.groups.unifi-poller = { };
322 users.users.unifi-poller = {
323 description = "unifi-poller Service User";
324 group = "unifi-poller";
328 systemd.services.unifi-poller = {
329 wantedBy = [ "multi-user.target" ];
330 after = [ "network.target" ];
332 ExecStart = "${pkgs.unpoller}/bin/unpoller --config ${configFile}";
336 ProtectSystem = "full";
337 DevicePolicy = "closed";
338 NoNewPrivileges = true;
339 User = "unifi-poller";
340 WorkingDirectory = "/tmp";