1 { config, lib, pkgs, ... }: with lib; let
2 cfg = config.services.icingaweb2.modules.monitoring;
6 protected_customvars = "${concatStringsSep "," cfg.generalConfig.protectedVars}"
10 formatBool = b: if b then "1" else "0";
11 in concatStringsSep "\n" (mapAttrsToList (name: config: ''
14 resource = "${config.resource}"
15 disabled = "${formatBool config.disabled}"
18 transportsIni = concatStringsSep "\n" (mapAttrsToList (name: config: ''
20 type = "${config.type}"
21 ${optionalString (config.instance != null) ''instance = "${config.instance}"''}
22 ${optionalString (config.type == "local" || config.type == "remote") ''path = "${config.path}"''}
23 ${optionalString (config.type != "local") ''
24 host = "${config.host}"
25 ${optionalString (config.port != null) ''port = "${toString config.port}"''}
26 user${optionalString (config.type == "api") "name"} = "${config.username}"
28 ${optionalString (config.type == "api") ''password = "${config.password}"''}
29 ${optionalString (config.type == "remote") ''resource = "${config.resource}"''}
33 options.services.icingaweb2.modules.monitoring = with types; {
37 description = "Whether to enable the icingaweb2 monitoring module.";
44 description = "Make config.ini of the monitoring module mutable (e.g. via the web interface).";
47 protectedVars = mkOption {
49 default = [ "*pw*" "*pass*" "community" ];
50 description = "List of string patterns for custom variables which should be excluded from user’s view.";
54 mutableBackends = mkOption {
57 description = "Make backends.ini of the monitoring module mutable (e.g. via the web interface).";
61 default = { icinga = { resource = "icinga_ido"; }; };
62 description = "Monitoring backends to define";
63 type = attrsOf (submodule ({ name, ... }: {
69 description = "Name of this backend";
74 description = "Name of the IDO resource";
80 description = "Disable this backend";
86 mutableTransports = mkOption {
89 description = "Make commandtransports.ini of the monitoring module mutable (e.g. via the web interface).";
92 transports = mkOption {
94 description = "Command transports to define";
95 type = attrsOf (submodule ({ name, ... }: {
101 description = "Name of this transport";
105 type = enum [ "api" "local" "remote" ];
107 description = "Type of this transport";
110 instance = mkOption {
113 description = "Assign a icinga instance to this transport";
118 description = "Path to the socket for local or remote transports";
123 description = "Host for the api or remote transport";
129 description = "Port to connect to for the api or remote transport";
132 username = mkOption {
134 description = "Username for the api or remote transport";
137 password = mkOption {
139 description = "Password for the api transport";
142 resource = mkOption {
144 description = "SSH identity resource for the remote transport";
151 config = mkIf (config.services.icingaweb2.enable && cfg.enable) {
152 environment.etc = { "icingaweb2/enabledModules/monitoring" = { source = "${pkgs.icingaweb2}/modules/monitoring"; }; }
153 // optionalAttrs (!cfg.generalConfig.mutable) { "icingaweb2/modules/monitoring/config.ini".text = configIni; }
154 // optionalAttrs (!cfg.mutableBackends) { "icingaweb2/modules/monitoring/backends.ini".text = backendsIni; }
155 // optionalAttrs (!cfg.mutableTransports) { "icingaweb2/modules/monitoring/commandtransports.ini".text = transportsIni; };