1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.fritzboxExporter;
7in {
8 options = {
9 services.prometheus.fritzboxExporter = {
10 enable = mkEnableOption "prometheus fritzbox exporter";
11
12 port = mkOption {
13 type = types.int;
14 default = 9133;
15 description = ''
16 Port to listen on.
17 '';
18 };
19
20 gatewayAddress = mkOption {
21 type = types.str;
22 default = "fritz.box";
23 description = ''
24 The hostname or IP of the FRITZ!Box.
25 '';
26 };
27
28 gatewayPort = mkOption {
29 type = types.int;
30 default = 49000;
31 description = ''
32 The port of the FRITZ!Box UPnP service.
33 '';
34 };
35
36 extraFlags = mkOption {
37 type = types.listOf types.str;
38 default = [];
39 description = ''
40 Extra commandline options when launching the fritzbox exporter.
41 '';
42 };
43
44 openFirewall = mkOption {
45 type = types.bool;
46 default = false;
47 description = ''
48 Open port in firewall for incoming connections.
49 '';
50 };
51 };
52 };
53
54 config = mkIf cfg.enable {
55 networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port;
56
57 systemd.services.prometheus-fritzbox-exporter = {
58 description = "Prometheus exporter for FRITZ!Box via UPnP";
59 unitConfig.Documentation = "https://github.com/ndecker/fritzbox_exporter";
60 wantedBy = [ "multi-user.target" ];
61 serviceConfig = {
62 User = "nobody";
63 Restart = "always";
64 PrivateTmp = true;
65 WorkingDirectory = /tmp;
66 ExecStart = ''
67 ${pkgs.prometheus-fritzbox-exporter}/bin/fritzbox_exporter \
68 -listen-address :${toString cfg.port} \
69 -gateway-address ${cfg.gatewayAddress} \
70 -gateway-port ${toString cfg.gatewayPort} \
71 ${concatStringsSep " \\\n " cfg.extraFlags}
72 '';
73 };
74 };
75 };
76}