gatus: Refactor again

This commit is contained in:
SebastianStork 2025-09-21 01:00:18 +02:00
parent c55be783b1
commit 5a960a1074
2 changed files with 32 additions and 26 deletions

View file

@ -31,17 +31,14 @@
gatus = { gatus = {
enable = true; enable = true;
domain = "status.${tailscaleDomain}"; domain = "status.${tailscaleDomain}";
domainsToMonitor = config.meta.domains.globalList; generateDefaultEndpoints = true;
endpoints = { endpoints = {
"alerts" = { "alerts" = {
group = "Monitoring";
path = "/v1/health"; path = "/v1/health";
extraConditions = [ "[BODY].healthy == true" ]; extraConditions = [ "[BODY].healthy == true" ];
}; };
"grafana".group = "Monitoring";
"metrics".group = "Monitoring";
"logs".group = "Monitoring";
"git ssh" = { "git ssh" = {
group = "srv-public";
protocol = "ssh"; protocol = "ssh";
domain = "git.sstork.dev"; domain = "git.sstork.dev";
}; };

View file

@ -1,13 +1,12 @@
{ {
config, config,
self,
pkgs-unstable, pkgs-unstable,
lib, lib,
... ...
}: }:
let let
cfg = config.custom.services.gatus; cfg = config.custom.services.gatus;
tailscaleDomain = config.custom.services.tailscale.domain;
dataDir = "/var/lib/gatus"; dataDir = "/var/lib/gatus";
in in
{ {
@ -21,14 +20,11 @@ in
type = lib.types.port; type = lib.types.port;
default = 8080; default = 8080;
}; };
domainsToMonitor = lib.mkOption { generateDefaultEndpoints = lib.mkEnableOption "";
type = lib.types.listOf lib.types.nonEmptyStr;
default = [ ];
};
endpoints = lib.mkOption { endpoints = lib.mkOption {
type = lib.types.attrsOf ( type = lib.types.attrsOf (
lib.types.submodule ( lib.types.submodule (
{ name, config, ... }: { name, ... }:
{ {
options = { options = {
name = lib.mkOption { name = lib.mkOption {
@ -37,7 +33,7 @@ in
}; };
group = lib.mkOption { group = lib.mkOption {
type = lib.types.nonEmptyStr; type = lib.types.nonEmptyStr;
default = if config.domain |> lib.hasSuffix tailscaleDomain then "Private" else "Public"; default = "";
}; };
protocol = lib.mkOption { protocol = lib.mkOption {
type = lib.types.nonEmptyStr; type = lib.types.nonEmptyStr;
@ -106,20 +102,33 @@ in
getSubdomain = domain: domain |> lib.splitString "." |> lib.head; getSubdomain = domain: domain |> lib.splitString "." |> lib.head;
defaultEndpoints = defaultEndpoints =
cfg.domainsToMonitor self.nixosConfigurations
|> lib.filter (domain: domain != cfg.domain) |> lib.mapAttrs (_: value: value.config.meta.domains.list)
|> lib.map (domain: lib.nameValuePair (getSubdomain domain) { inherit domain; }) |> lib.concatMapAttrs (
|> lib.listToAttrs; hostName: domains:
domains
|> lib.filter (domain: domain != cfg.domain)
|> lib.map (
domain:
lib.nameValuePair (getSubdomain domain) {
inherit domain;
group = hostName;
}
)
|> lib.listToAttrs
);
in in
{ lib.mkIf cfg.generateDefaultEndpoints (
"healthchecks.io" = { defaultEndpoints
group = "Monitoring"; // {
domain = "hc-ping.com"; "healthchecks.io" = {
path = "/\${HEALTHCHECKS_PING_KEY}/${config.networking.hostName}-gatus-uptime?create=1"; group = "external";
interval = "2h"; domain = "hc-ping.com";
}; path = "/\${HEALTHCHECKS_PING_KEY}/${config.networking.hostName}-gatus-uptime?create=1";
} interval = "2h";
// defaultEndpoints; };
}
);
services.gatus = { services.gatus = {
enable = true; enable = true;