107 lines
3.8 KiB
Nix
107 lines
3.8 KiB
Nix
{ config, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
mkAttrsOfSubmoduleOption = description: submoduleOptions: mkOption {
|
|
type = with types; attrsOf (submodule { options = submoduleOptions; });
|
|
default = {};
|
|
description = description;
|
|
};
|
|
|
|
mkSubmoduleOption = description: submoduleOptions: mkOption {
|
|
type = types.submodule { options = submoduleOptions; };
|
|
default = {};
|
|
description = description;
|
|
};
|
|
|
|
mkProbeOption = description: submoduleOptions: mkSubmoduleOption description ({
|
|
enable = mkEnableOption "Monitor target using this probe";
|
|
} // submoduleOptions);
|
|
|
|
mkProtocolsOption = mkOption {
|
|
type = with types; listOf (enum [ "ipv6" "ipv4" ]);
|
|
default = [ "ipv6" "ipv4" ];
|
|
description = "Protocols to retrieve metrics for";
|
|
};
|
|
|
|
mkTargetsListOption = mkOption {
|
|
type = with types; listOf str;
|
|
default = [];
|
|
};
|
|
|
|
listContains = searchValue: listToSearch: any (element: element == searchValue) listToSearch;
|
|
|
|
targetsForProbe = probeName: condition: attrNames (filterAttrs (targetName: targetConfig:
|
|
targetConfig.${probeName}.enable == true && (condition targetConfig.${probeName})
|
|
) config.profiles.clerie.monitoring-server.targets);
|
|
|
|
in {
|
|
|
|
options.profiles.clerie.monitoring-server = {
|
|
targets = mkAttrsOfSubmoduleOption "Monitoring targets config" {
|
|
_comment = mkOption {
|
|
type = types.str;
|
|
default = "";
|
|
};
|
|
clerie-uberspace = mkProbeOption "This target is a uberspace host managed by clerie" {};
|
|
http = mkProbeOption "Monitor HTTP" {
|
|
protocols = mkProtocolsOption;
|
|
transport = mkOption {
|
|
type = with types; listOf (enum [ "http" "https" ]);
|
|
default = [ "http" "https" ];
|
|
description = "HTTP transport modes to monitor";
|
|
};
|
|
};
|
|
icmp = mkProbeOption "Monitor HTTP" {
|
|
protocols = mkProtocolsOption;
|
|
};
|
|
synapse = mkProbeOption "Monitor Synapse Matrix server" {};
|
|
};
|
|
|
|
probeTargets = mkSubmoduleOption "Target per probe" {
|
|
blackbox-icmp4 = mkTargetsListOption;
|
|
blackbox-icmp6 = mkTargetsListOption;
|
|
blackbox-local-http4 = mkTargetsListOption;
|
|
blackbox-local-http6 = mkTargetsListOption;
|
|
blackbox-local-https4 = mkTargetsListOption;
|
|
blackbox-local-https6 = mkTargetsListOption;
|
|
node-exporter-uberspace = mkTargetsListOption;
|
|
blackbox-local-synapse = mkTargetsListOption;
|
|
};
|
|
};
|
|
|
|
config = {
|
|
|
|
profiles.clerie.monitoring-server.probeTargets.blackbox-icmp4 = targetsForProbe "icmp" (probeConfig:
|
|
(listContains "ipv4" probeConfig.protocols)
|
|
);
|
|
|
|
profiles.clerie.monitoring-server.probeTargets.blackbox-icmp6 = targetsForProbe "icmp" (probeConfig:
|
|
(listContains "ipv6" probeConfig.protocols)
|
|
);
|
|
|
|
profiles.clerie.monitoring-server.probeTargets.blackbox-local-http4 = targetsForProbe "http" (probeConfig:
|
|
(listContains "ipv4" probeConfig.protocols) && (listContains "http" probeConfig.transport)
|
|
);
|
|
|
|
profiles.clerie.monitoring-server.probeTargets.blackbox-local-http6 = targetsForProbe "http" (probeConfig:
|
|
(listContains "ipv6" probeConfig.protocols) && (listContains "http" probeConfig.transport)
|
|
);
|
|
|
|
profiles.clerie.monitoring-server.probeTargets.blackbox-local-https4 = targetsForProbe "http" (probeConfig:
|
|
(listContains "ipv4" probeConfig.protocols) && (listContains "https" probeConfig.transport)
|
|
);
|
|
|
|
profiles.clerie.monitoring-server.probeTargets.blackbox-local-https6 = targetsForProbe "http" (probeConfig:
|
|
(listContains "ipv6" probeConfig.protocols) && (listContains "https" probeConfig.transport)
|
|
);
|
|
|
|
profiles.clerie.monitoring-server.probeTargets.node-exporter-uberspace = targetsForProbe "clerie-uberspace" (_: true);
|
|
|
|
profiles.clerie.monitoring-server.probeTargets.blackbox-local-synapse = targetsForProbe "synapse" (_: true);
|
|
|
|
};
|
|
}
|