{ lib, config, machines, ... }: let cfg = config.lab.monitoring; status = code: "[STATUS] == ${toString code}"; bodyContains = text: "[BODY] == pat(*${text}*)"; maxResponseTime = ms: "[RESPONSE_TIME] < ${toString ms}"; machineEndpoints = lib.attrsets.mapAttrsToList (name: machine: let domain = if machine.isPhysical then "hyp" else "dmz"; in { name = "Host ${name}"; url = "icmp://${name}.${domain}"; conditions = [ "[RESPONSE_TIME] < 10" ]; }) machines; otherEndpoints = [ { name = "Forgejo"; url = "https://git.kun.is"; conditions = [ (status 200) (bodyContains "Forgejo: Beyond coding. We forge.") (maxResponseTime 750) ]; } { name = "Nextcloud"; url = "https://cloud.kun.is/status.php"; conditions = [ (status 200) "[BODY].installed == true" "[BODY].maintenance == false" "[BODY].needsDbUpgrade == false" (maxResponseTime 2000) ]; } { name = "Paperless-ngx"; url = "https://paperless.kun.is/accounts/login/"; conditions = [ (status 200) (bodyContains "Please sign in.") (maxResponseTime 750) ]; } { name = "Radicale"; url = "https://dav.kun.is/.web/"; conditions = [ (status 200) (bodyContains "Login") (maxResponseTime 750) ]; } { name = "FreshRSS"; url = "https://rss.kun.is/i/"; conditions = [ (status 200) (bodyContains "Login") (maxResponseTime 750) ]; } { name = "KitchenOwl"; url = "https://boodschappen.kun.is/signin"; conditions = [ (status 200) (bodyContains "KitchenOwl") (maxResponseTime 750) ]; } { name = "HedgeDoc"; url = "https://md.kun.is/"; conditions = [ (status 200) (bodyContains "The best platform to write and share markdown.") (maxResponseTime 750) ]; } { name = "Cyberchef"; url = "https://cyberchef.kun.is/"; conditions = [ (status 200) (bodyContains "CyberChef - The Cyber Swiss Army Knife") (maxResponseTime 750) ]; } { name = "Pi-hole"; url = "https://pihole.kun.is:444/admin/login.php"; conditions = [ (status 200) (bodyContains "Log in") (maxResponseTime 750) ]; } { name = "Inbucket"; url = "https://inbucket.kun.is:444/"; conditions = [ (status 200) (bodyContains "Inbucket") (maxResponseTime 750) ]; } { name = "kms"; url = "tcp://kms.kun.is:1688"; conditions = [ "[CONNECTED] == true" ]; } { name = "Bazarr"; url = "https://bazarr.kun.is:444/system/status"; conditions = [ (status 200) (bodyContains "Bazarr") (maxResponseTime 750) ]; } { name = "Sonarr"; url = "https://sonarr.kun.is:444/system/status"; conditions = [ (status 200) (bodyContains "Sonarr") (maxResponseTime 750) ]; } { name = "Radarr"; url = "https://radarr.kun.is:444/system/status"; conditions = [ (status 200) (bodyContains "Radarr") (maxResponseTime 750) ]; } { name = "Jellyfin"; url = "https://media.kun.is/web/index.html#!/login.html?"; conditions = [ (status 200) (bodyContains "Jellyfin") (maxResponseTime 750) ]; } { name = "Jellyseerr"; url = "https://jellyseerr.kun.is:444/login"; conditions = [ (status 200) (bodyContains "Sign in to continue") (maxResponseTime 750) ]; } { name = "Prowlarr"; url = "https://prowlarr.kun.is:444/system/status"; conditions = [ (status 200) (bodyContains "Prowlarr") (maxResponseTime 750) ]; } { name = "Transmission"; url = "https://transmission.kun.is:444/transmission/web/"; conditions = [ (status 200) (bodyContains "Transmission Web Interface") (maxResponseTime 750) ]; } { name = "Syncthing"; url = "https://sync.kun.is:444/"; conditions = [ (status 401) (maxResponseTime 750) ]; } { name = "Traefik"; url = "https://traefik.kun.is:444/dashboard/#/"; conditions = [ (status 200) (bodyContains "Traefik") (maxResponseTime 750) ]; } { name = "BIND"; url = "192.168.30.7"; dns = { query-type = "SOA"; query-name = "kun.is"; }; conditions = [ "[DNS_RCODE] == NOERROR" ]; } { name = "Pi-hole DNS"; url = "192.168.30.8"; dns = { query-type = "SOA"; query-name = "kun.is"; }; conditions = [ "[DNS_RCODE] == NOERROR" ]; } ]; in { config = lib.mkIf cfg.server.enable { services.gatus.settings.endpoints = map (endpoint: endpoint // { interval = "5m"; alerts = [{ type = "email"; }]; }) (machineEndpoints ++ otherEndpoints); }; }