Simplify config for gatus endpoints

This commit is contained in:
SebastianStork 2025-06-22 20:44:04 +02:00
parent f65bf51905
commit 6c0ff3393b
9 changed files with 29 additions and 61 deletions

View file

@ -18,6 +18,15 @@
gatus = { gatus = {
enable = true; enable = true;
domain = "status.${config.custom.services.tailscale.domain}"; domain = "status.${config.custom.services.tailscale.domain}";
endpoints = {
"status".group = "Monitoring";
"alerts" = {
group = "Monitoring";
appendPath = "/v1/health";
extraConditions = [ "[BODY].healthy == true" ];
};
"git ssh".url = "ssh://git.sstork.dev";
};
}; };
ntfy = { ntfy = {
enable = true; enable = true;

View file

@ -25,7 +25,5 @@ in
inherit (cfg) port; inherit (cfg) port;
}; };
}; };
custom.services.gatus.endpoints."Actual Budget".url = "https://${cfg.domain}/";
}; };
} }

View file

@ -93,13 +93,5 @@ in
"d ${config.services.forgejo.customDir}/public 750 ${user} ${group} - -" "d ${config.services.forgejo.customDir}/public 750 ${user} ${group} - -"
"L+ ${config.services.forgejo.customDir}/public/robots.txt 750 - - - ${disallow-all-robots}" "L+ ${config.services.forgejo.customDir}/public/robots.txt 750 - - - ${disallow-all-robots}"
]; ];
custom.services.gatus.endpoints = {
"Forgejo" = {
url = "https://${cfg.domain}/api/healthz";
extraConditions = [ "[BODY].status == pass" ];
};
"Forgejo SSH".url = "ssh://${cfg.domain}";
};
}; };
} }

View file

@ -1,9 +1,4 @@
{ { config, lib, ... }:
config,
self,
lib,
...
}:
let let
cfg = config.custom.services.gatus; cfg = config.custom.services.gatus;
in in
@ -36,6 +31,10 @@ in
type = lib.types.nonEmptyStr; type = lib.types.nonEmptyStr;
default = ""; default = "";
}; };
appendPath = lib.mkOption {
type = lib.types.str;
default = "";
};
extraConditions = lib.mkOption { extraConditions = lib.mkOption {
type = lib.types.listOf lib.types.nonEmptyStr; type = lib.types.listOf lib.types.nonEmptyStr;
default = [ ]; default = [ ];
@ -58,6 +57,14 @@ in
''; '';
}; };
custom.services.gatus.endpoints =
let
getSubdomain = domain: domain |> lib.splitString "." |> lib.head;
in
config.meta.domains.globalList
|> lib.map (domain: lib.nameValuePair (getSubdomain domain) { url = "https://${domain}"; })
|> lib.listToAttrs;
services.gatus = { services.gatus = {
enable = true; enable = true;
environmentFile = config.sops.templates."gatus.env".path; environmentFile = config.sops.templates."gatus.env".path;
@ -99,6 +106,7 @@ in
name, name,
group, group,
url, url,
appendPath,
extraConditions, extraConditions,
}: }:
let let
@ -106,9 +114,9 @@ in
deducedGroup = if isPrivate then "Private" else "Public"; deducedGroup = if isPrivate then "Private" else "Public";
in in
{ {
inherit name url; inherit name;
group = if group == null then deducedGroup else group; group = if group != null then group else deducedGroup;
interval = "30s"; url = url + appendPath;
alerts = [ { type = "ntfy"; } ]; alerts = [ { type = "ntfy"; } ];
ssh = lib.mkIf (lib.hasPrefix "ssh" url) { ssh = lib.mkIf (lib.hasPrefix "ssh" url) {
username = ""; username = "";
@ -125,20 +133,14 @@ in
in in
[ [
{ {
name = "Healthchecks.io"; name = "healthchecks.io";
group = "Monitoring"; group = "Monitoring";
url = "https://hc-ping.com/\${HEALTHCHECKS_PING_KEY}/gatus-uptime?create=1"; url = "https://hc-ping.com/\${HEALTHCHECKS_PING_KEY}/${config.networking.hostName}-gatus-uptime?create=1";
interval = "2h"; interval = "2h";
conditions = [ "[STATUS] == 200" ]; conditions = [ "[STATUS] == 200" ];
} }
] ]
++ ( ++ (cfg.endpoints |> lib.mapAttrsToList (_: value: value) |> lib.map (entry: mkEndpoint entry));
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)
);
}; };
}; };
}; };

View file

@ -79,10 +79,5 @@ in
}; };
environment.shellAliases.hedgedoc-manage-users = "sudo --user=${user} ${manage_users}"; environment.shellAliases.hedgedoc-manage-users = "sudo --user=${user} ${manage_users}";
custom.services.gatus.endpoints."Hedgedoc" = {
url = "https://${cfg.domain}/_health";
extraConditions = [ "[BODY].ready == true" ];
};
}; };
} }

View file

@ -29,10 +29,5 @@ in
root = "${pkgs.it-tools}/lib"; root = "${pkgs.it-tools}/lib";
configuration.general.health = true; configuration.general.health = true;
}; };
custom.services.gatus.endpoints."IT Tools" = {
url = "https://${cfg.domain}/health";
extraConditions = [ "[BODY] == OK" ];
};
}; };
} }

View file

@ -72,14 +72,5 @@ in
}; };
}; };
}; };
custom.services.gatus.endpoints."Nextcloud" = {
url = "https://${cfg.domain}/status.php";
extraConditions = [
"[BODY].installed == true"
"[BODY].maintenance == false"
"[BODY].needsDbUpgrade == false"
];
};
}; };
} }

View file

@ -27,11 +27,5 @@ in
web-root = "disable"; web-root = "disable";
}; };
}; };
custom.services.gatus.endpoints."Ntfy" = {
group = "Monitoring";
url = "https://${cfg.domain}/v1/health";
extraConditions = [ "[BODY].healthy == true" ];
};
}; };
} }

View file

@ -97,13 +97,5 @@ in
}; };
}; };
}; };
custom.services.gatus.endpoints = lib.mkIf cfg.isServer {
"Syncthing".url = "tcp://${config.networking.hostName}.${tailscaleCfg.domain}:22000";
"Syncthing GUI" = {
url = "https://${cfg.gui.domain}/rest/noauth/health";
extraConditions = [ "[BODY].status == OK" ];
};
};
}; };
} }