2024-12-10 20:26:33 +01:00
|
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
lib,
|
|
|
|
|
pkgs,
|
|
|
|
|
...
|
|
|
|
|
}:
|
|
|
|
|
with lib;
|
|
|
|
|
let
|
2019-02-17 19:08:47 +01:00
|
|
|
|
cfg = config.services.icingaweb2.modules.monitoring;
|
|
|
|
|
|
|
|
|
|
configIni = ''
|
|
|
|
|
[security]
|
|
|
|
|
protected_customvars = "${concatStringsSep "," cfg.generalConfig.protectedVars}"
|
|
|
|
|
'';
|
|
|
|
|
|
2024-12-10 20:26:33 +01:00
|
|
|
|
backendsIni =
|
|
|
|
|
let
|
|
|
|
|
formatBool = b: if b then "1" else "0";
|
|
|
|
|
in
|
|
|
|
|
concatStringsSep "\n" (
|
|
|
|
|
mapAttrsToList (name: config: ''
|
|
|
|
|
[${name}]
|
|
|
|
|
type = "ido"
|
|
|
|
|
resource = "${config.resource}"
|
|
|
|
|
disabled = "${formatBool config.disabled}"
|
|
|
|
|
'') cfg.backends
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
transportsIni = concatStringsSep "\n" (
|
|
|
|
|
mapAttrsToList (name: config: ''
|
|
|
|
|
[${name}]
|
|
|
|
|
type = "${config.type}"
|
|
|
|
|
${optionalString (config.instance != null) ''instance = "${config.instance}"''}
|
|
|
|
|
${optionalString (config.type == "local" || config.type == "remote") ''path = "${config.path}"''}
|
|
|
|
|
${optionalString (config.type != "local") ''
|
|
|
|
|
host = "${config.host}"
|
|
|
|
|
${optionalString (config.port != null) ''port = "${toString config.port}"''}
|
|
|
|
|
user${optionalString (config.type == "api") "name"} = "${config.username}"
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (config.type == "api") ''password = "${config.password}"''}
|
|
|
|
|
${optionalString (config.type == "remote") ''resource = "${config.resource}"''}
|
|
|
|
|
'') cfg.transports
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
in
|
|
|
|
|
{
|
2019-02-17 19:08:47 +01:00
|
|
|
|
options.services.icingaweb2.modules.monitoring = with types; {
|
|
|
|
|
enable = mkOption {
|
|
|
|
|
type = bool;
|
|
|
|
|
default = true;
|
2024-04-13 14:54:15 +02:00
|
|
|
|
description = "Whether to enable the icingaweb2 monitoring module.";
|
2019-02-17 19:08:47 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
generalConfig = {
|
|
|
|
|
mutable = mkOption {
|
|
|
|
|
type = bool;
|
|
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
|
description = "Make config.ini of the monitoring module mutable (e.g. via the web interface).";
|
2019-02-17 19:08:47 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
protectedVars = mkOption {
|
|
|
|
|
type = listOf str;
|
2024-12-10 20:26:33 +01:00
|
|
|
|
default = [
|
|
|
|
|
"*pw*"
|
|
|
|
|
"*pass*"
|
|
|
|
|
"community"
|
|
|
|
|
];
|
2024-04-13 14:54:15 +02:00
|
|
|
|
description = "List of string patterns for custom variables which should be excluded from user’s view.";
|
2019-02-17 19:08:47 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mutableBackends = mkOption {
|
|
|
|
|
type = bool;
|
|
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
|
description = "Make backends.ini of the monitoring module mutable (e.g. via the web interface).";
|
2019-02-17 19:08:47 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
backends = mkOption {
|
2024-12-10 20:26:33 +01:00
|
|
|
|
default = {
|
|
|
|
|
icinga = {
|
|
|
|
|
resource = "icinga_ido";
|
2019-02-17 19:08:47 +01:00
|
|
|
|
};
|
2024-12-10 20:26:33 +01:00
|
|
|
|
};
|
|
|
|
|
description = "Monitoring backends to define";
|
|
|
|
|
type = attrsOf (
|
|
|
|
|
submodule (
|
|
|
|
|
{ name, ... }:
|
|
|
|
|
{
|
|
|
|
|
options = {
|
|
|
|
|
name = mkOption {
|
|
|
|
|
visible = false;
|
|
|
|
|
default = name;
|
|
|
|
|
type = str;
|
|
|
|
|
description = "Name of this backend";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
resource = mkOption {
|
|
|
|
|
type = str;
|
|
|
|
|
description = "Name of the IDO resource";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
disabled = mkOption {
|
|
|
|
|
type = bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = "Disable this backend";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
2019-02-17 19:08:47 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mutableTransports = mkOption {
|
|
|
|
|
type = bool;
|
|
|
|
|
default = true;
|
2024-04-13 14:54:15 +02:00
|
|
|
|
description = "Make commandtransports.ini of the monitoring module mutable (e.g. via the web interface).";
|
2019-02-17 19:08:47 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
transports = mkOption {
|
2024-12-10 20:26:33 +01:00
|
|
|
|
default = { };
|
2024-04-13 14:54:15 +02:00
|
|
|
|
description = "Command transports to define";
|
2024-12-10 20:26:33 +01:00
|
|
|
|
type = attrsOf (
|
|
|
|
|
submodule (
|
|
|
|
|
{ name, ... }:
|
|
|
|
|
{
|
|
|
|
|
options = {
|
|
|
|
|
name = mkOption {
|
|
|
|
|
visible = false;
|
|
|
|
|
default = name;
|
|
|
|
|
type = str;
|
|
|
|
|
description = "Name of this transport";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type = mkOption {
|
|
|
|
|
type = enum [
|
|
|
|
|
"api"
|
|
|
|
|
"local"
|
|
|
|
|
"remote"
|
|
|
|
|
];
|
|
|
|
|
default = "api";
|
|
|
|
|
description = "Type of this transport";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
instance = mkOption {
|
|
|
|
|
type = nullOr str;
|
|
|
|
|
default = null;
|
|
|
|
|
description = "Assign a icinga instance to this transport";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
path = mkOption {
|
|
|
|
|
type = str;
|
|
|
|
|
description = "Path to the socket for local or remote transports";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
|
type = str;
|
|
|
|
|
description = "Host for the api or remote transport";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
|
type = nullOr str;
|
|
|
|
|
default = null;
|
|
|
|
|
description = "Port to connect to for the api or remote transport";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
|
type = str;
|
|
|
|
|
description = "Username for the api or remote transport";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
|
type = str;
|
|
|
|
|
description = "Password for the api transport";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
resource = mkOption {
|
|
|
|
|
type = str;
|
|
|
|
|
description = "SSH identity resource for the remote transport";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
2019-02-17 19:08:47 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = mkIf (config.services.icingaweb2.enable && cfg.enable) {
|
2024-12-10 20:26:33 +01:00
|
|
|
|
environment.etc =
|
|
|
|
|
{
|
|
|
|
|
"icingaweb2/enabledModules/monitoring" = {
|
|
|
|
|
source = "${pkgs.icingaweb2}/modules/monitoring";
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
// optionalAttrs (!cfg.generalConfig.mutable) {
|
|
|
|
|
"icingaweb2/modules/monitoring/config.ini".text = configIni;
|
|
|
|
|
}
|
|
|
|
|
// optionalAttrs (!cfg.mutableBackends) {
|
|
|
|
|
"icingaweb2/modules/monitoring/backends.ini".text = backendsIni;
|
|
|
|
|
}
|
|
|
|
|
// optionalAttrs (!cfg.mutableTransports) {
|
|
|
|
|
"icingaweb2/modules/monitoring/commandtransports.ini".text = transportsIni;
|
|
|
|
|
};
|
2019-02-17 19:08:47 +01:00
|
|
|
|
};
|
|
|
|
|
}
|