2020-09-25 04:45:31 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
2022-12-17 10:02:37 +00:00
|
|
|
cfg = config.services.unpoller;
|
2020-09-25 04:45:31 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
configFile = pkgs.writeText "unpoller.json" (lib.generators.toJSON {} {
|
2021-12-06 16:07:01 +00:00
|
|
|
inherit (cfg) poller influxdb loki prometheus unifi;
|
2020-09-25 04:45:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
in {
|
2022-12-17 10:02:37 +00:00
|
|
|
imports = [
|
|
|
|
(lib.mkRenamedOptionModule [ "services" "unifi-poller" ] [ "services" "unpoller" ])
|
|
|
|
];
|
|
|
|
|
|
|
|
options.services.unpoller = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkEnableOption "unpoller";
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
poller = {
|
2024-09-19 14:19:46 +00:00
|
|
|
debug = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Turns on line numbers, microsecond logging, and a per-device log.
|
|
|
|
This may be noisy if you have a lot of devices. It adds one line per device.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
quiet = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Turns off per-interval logs. Only startup and error logs will be emitted.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
plugins = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = [];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Load additional plugins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
prometheus = {
|
2024-09-19 14:19:46 +00:00
|
|
|
disable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-05-24 13:37:59 +00:00
|
|
|
Whether to disable the prometheus output plugin.
|
2020-09-25 04:45:31 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
http_listen = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = "[::]:9130";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Bind the prometheus exporter to this IP or hostname.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
report_errors = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Whether to report errors.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
influxdb = {
|
2024-09-19 14:19:46 +00:00
|
|
|
disable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-05-24 13:37:59 +00:00
|
|
|
Whether to disable the influxdb output plugin.
|
2020-09-25 04:45:31 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
url = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = "http://127.0.0.1:8086";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
URL of the influxdb host.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
user = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = "unifipoller";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Username for the influxdb.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
pass = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2022-12-17 10:02:37 +00:00
|
|
|
default = pkgs.writeText "unpoller-influxdb-default.password" "unifipoller";
|
2024-09-19 14:19:46 +00:00
|
|
|
defaultText = lib.literalExpression "unpoller-influxdb-default.password";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Path of a file containing the password for influxdb.
|
|
|
|
This file needs to be readable by the unifi-poller user.
|
|
|
|
'';
|
|
|
|
apply = v: "file://${v}";
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
db = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = "unifi";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Database name. Database should exist.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
verify_ssl = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Verify the influxdb's certificate.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
interval = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = "30s";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Setting this lower than the Unifi controller's refresh
|
|
|
|
interval may lead to zeroes in your database.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
loki = {
|
2024-09-19 14:19:46 +00:00
|
|
|
url = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
URL of the Loki host.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
user = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
Username for Loki.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
pass = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2022-12-17 10:02:37 +00:00
|
|
|
default = pkgs.writeText "unpoller-loki-default.password" "";
|
|
|
|
defaultText = "unpoller-influxdb-default.password";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
Path of a file containing the password for Loki.
|
|
|
|
This file needs to be readable by the unifi-poller user.
|
|
|
|
'';
|
|
|
|
apply = v: "file://${v}";
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
verify_ssl = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
Verify Loki's certificate.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
tenant_id = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
Tenant ID to use in Loki.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
interval = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = "2m";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
How often the events are polled and pushed to Loki.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
timeout = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = "10s";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
Should be increased in case of timeout errors.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
unifi = let
|
|
|
|
controllerOptions = {
|
2024-09-19 14:19:46 +00:00
|
|
|
user = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = "unifi";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Unifi service user name.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
pass = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2022-12-17 10:02:37 +00:00
|
|
|
default = pkgs.writeText "unpoller-unifi-default.password" "unifi";
|
2024-09-19 14:19:46 +00:00
|
|
|
defaultText = lib.literalExpression "unpoller-unifi-default.password";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Path of a file containing the password for the unifi service user.
|
|
|
|
This file needs to be readable by the unifi-poller user.
|
|
|
|
'';
|
|
|
|
apply = v: "file://${v}";
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
url = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = "https://unifi:8443";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
URL of the Unifi controller.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
sites = lib.mkOption {
|
|
|
|
type = with lib.types; either (enum [ "default" "all" ]) (listOf str);
|
2020-09-25 04:45:31 +00:00
|
|
|
default = "all";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
List of site names for which statistics should be exported.
|
|
|
|
Or the string "default" for the default site or the string "all" for all sites.
|
|
|
|
'';
|
2024-09-19 14:19:46 +00:00
|
|
|
apply = lib.toList;
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
save_ids = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
Collect and save data from the intrusion detection system to influxdb and Loki.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
save_events = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
Collect and save data from UniFi events to influxdb and Loki.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
save_alarms = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
Collect and save data from UniFi alarms to influxdb and Loki.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
save_anomalies = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
Collect and save data from UniFi anomalies to influxdb and Loki.
|
2020-09-25 04:45:31 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
save_dpi = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Collect and save data from deep packet inspection.
|
|
|
|
Adds around 150 data points and impacts performance.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
save_sites = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Collect and save site data.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
hash_pii = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Hash, with md5, client names and MAC addresses. This attempts
|
|
|
|
to protect personally identifiable information.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
verify_ssl = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Verify the Unifi controller's certificate.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
2024-09-19 14:19:46 +00:00
|
|
|
dynamic = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-09-25 04:45:31 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
Let prometheus select which controller to poll when scraping.
|
|
|
|
Use with default credentials. See unifi-poller wiki for more.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
defaults = controllerOptions;
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
controllers = lib.mkOption {
|
|
|
|
type = with lib.types; listOf (submodule { options = controllerOptions; });
|
2020-09-25 04:45:31 +00:00
|
|
|
default = [];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
List of Unifi controllers to poll. Use defaults if empty.
|
|
|
|
'';
|
2024-09-19 14:19:46 +00:00
|
|
|
apply = map (lib.flip removeAttrs [ "_module" ]);
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2020-09-25 04:45:31 +00:00
|
|
|
users.groups.unifi-poller = { };
|
|
|
|
users.users.unifi-poller = {
|
|
|
|
description = "unifi-poller Service User";
|
|
|
|
group = "unifi-poller";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.unifi-poller = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
2022-12-17 10:02:37 +00:00
|
|
|
ExecStart = "${pkgs.unpoller}/bin/unpoller --config ${configFile}";
|
2020-09-25 04:45:31 +00:00
|
|
|
Restart = "always";
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectSystem = "full";
|
|
|
|
DevicePolicy = "closed";
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
User = "unifi-poller";
|
|
|
|
WorkingDirectory = "/tmp";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|