Minor refactor

This commit is contained in:
SebastianStork 2025-06-15 22:31:29 +02:00
parent f3c3d3268c
commit 856c850c3f

View file

@ -6,8 +6,6 @@
}: }:
let let
cfg = config.custom.services.gatus; cfg = config.custom.services.gatus;
tailscaleDomain = config.custom.services.tailscale.domain;
in in
{ {
options.custom.services.gatus = { options.custom.services.gatus = {
@ -66,17 +64,15 @@ in
connectivity.checker.target = "1.1.1.1:53"; connectivity.checker.target = "1.1.1.1:53";
alerting = { alerting.ntfy = {
ntfy = { topic = "uptime";
topic = "uptime"; url = "https://alerts.${config.custom.services.tailscale.domain}";
url = "https://alerts.${tailscaleDomain}"; click = "https://${cfg.domain}";
click = "https://${cfg.domain}"; default-alert = {
default-alert = { enable = true;
enable = true; failure-threshold = 4;
failure-threshold = 4; success-threshold = 2;
success-threshold = 2; send-on-resolved = true;
send-on-resolved = true;
};
}; };
}; };
@ -87,25 +83,36 @@ in
}; };
endpoints = endpoints =
let
mkEndpoint = (
{
name,
group,
url,
extraConditions,
}:
{
inherit name group url;
interval = "30s";
alerts = [ { type = "ntfy"; } ];
ssh = lib.mkIf (lib.hasPrefix "ssh" url) {
username = "";
password = "";
};
conditions = lib.flatten [
extraConditions
(lib.optional (lib.hasPrefix "http" url) "[STATUS] == 200")
(lib.optional (lib.hasPrefix "tcp" url) "[CONNECTED] == true")
(lib.optional (lib.hasPrefix "ssh" url) "[CONNECTED] == true")
];
}
);
in
self.nixosConfigurations self.nixosConfigurations
|> lib.mapAttrsToList (_: value: value.config.custom.services.gatus.endpoints) |> lib.mapAttrsToList (_: value: value.config.custom.services.gatus.endpoints)
|> lib.map (entry: lib.mapAttrsToList (_: value: value) entry) |> lib.map (entry: lib.mapAttrsToList (_: value: value) entry)
|> lib.flatten |> lib.concatLists
|> lib.map (value: { |> lib.map (entry: mkEndpoint entry);
inherit (value) name group url;
interval = "30s";
alerts = [ { type = "ntfy"; } ];
ssh = lib.mkIf (lib.hasPrefix "ssh" value.url) {
username = "";
password = "";
};
conditions = lib.flatten [
value.extraConditions
(lib.optional (lib.hasPrefix "http" value.url) "[STATUS] == 200")
(lib.optional (lib.hasPrefix "tcp" value.url) "[CONNECTED] == true")
(lib.optional (lib.hasPrefix "ssh" value.url) "[CONNECTED] == true")
];
});
}; };
}; };
}; };