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,10 +64,9 @@ 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.${tailscaleDomain}"; url = "https://alerts.${config.custom.services.tailscale.domain}";
click = "https://${cfg.domain}"; click = "https://${cfg.domain}";
default-alert = { default-alert = {
enable = true; enable = true;
@ -78,7 +75,6 @@ in
send-on-resolved = true; send-on-resolved = true;
}; };
}; };
};
maintenance = { maintenance = {
start = "03:00"; start = "03:00";
@ -87,25 +83,36 @@ in
}; };
endpoints = endpoints =
self.nixosConfigurations let
|> lib.mapAttrsToList (_: value: value.config.custom.services.gatus.endpoints) mkEndpoint = (
|> lib.map (entry: lib.mapAttrsToList (_: value: value) entry) {
|> lib.flatten name,
|> lib.map (value: { group,
inherit (value) name group url; url,
extraConditions,
}:
{
inherit name group url;
interval = "30s"; interval = "30s";
alerts = [ { type = "ntfy"; } ]; alerts = [ { type = "ntfy"; } ];
ssh = lib.mkIf (lib.hasPrefix "ssh" value.url) { ssh = lib.mkIf (lib.hasPrefix "ssh" url) {
username = ""; username = "";
password = ""; password = "";
}; };
conditions = lib.flatten [ conditions = lib.flatten [
value.extraConditions extraConditions
(lib.optional (lib.hasPrefix "http" value.url) "[STATUS] == 200") (lib.optional (lib.hasPrefix "http" url) "[STATUS] == 200")
(lib.optional (lib.hasPrefix "tcp" value.url) "[CONNECTED] == true") (lib.optional (lib.hasPrefix "tcp" url) "[CONNECTED] == true")
(lib.optional (lib.hasPrefix "ssh" value.url) "[CONNECTED] == true") (lib.optional (lib.hasPrefix "ssh" url) "[CONNECTED] == true")
]; ];
}); }
);
in
self.nixosConfigurations
|> lib.mapAttrsToList (_: value: value.config.custom.services.gatus.endpoints)
|> lib.map (entry: lib.mapAttrsToList (_: value: value) entry)
|> lib.concatLists
|> lib.map (entry: mkEndpoint entry);
}; };
}; };
}; };