From 20a394f9118439305cdcde7bf99f6cadfdb4a868 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Tue, 5 Mar 2024 22:51:26 +0100 Subject: [PATCH] monitor hosts and dns --- nix/modules/monitoring/default.nix | 3 +- nix/modules/monitoring/gatus-endpoints.nix | 56 +++++++++++++++++++--- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/nix/modules/monitoring/default.nix b/nix/modules/monitoring/default.nix index bc9099b..8384b1d 100644 --- a/nix/modules/monitoring/default.nix +++ b/nix/modules/monitoring/default.nix @@ -5,6 +5,7 @@ in { imports = [ "${nixpkgs-unstable}/nixos/modules/services/monitoring/gatus.nix" + ./gatus-endpoints.nix ]; options = { @@ -57,7 +58,6 @@ in settings = { web.port = 4242; - endpoints = import ./gatus-endpoints.nix; alerting.email = { from = "gatus@kun.is"; @@ -65,6 +65,7 @@ in port = 2525; to = "pim@kunis.nl"; client.insecure = true; + default-alert = { enabled = true; failure-threshold = 2; diff --git a/nix/modules/monitoring/gatus-endpoints.nix b/nix/modules/monitoring/gatus-endpoints.nix index 92a7f66..8680367 100644 --- a/nix/modules/monitoring/gatus-endpoints.nix +++ b/nix/modules/monitoring/gatus-endpoints.nix @@ -1,8 +1,24 @@ +{ lib, config, machines, ... }: let + cfg = config.lab.monitoring; + status = code: "[STATUS] == ${toString code}"; bodyContains = text: "[BODY] == pat(*${text}*)"; maxResponseTime = ms: "[RESPONSE_TIME] < ${toString ms}"; - endpoints = [ + + 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"; @@ -182,11 +198,37 @@ let (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 -map - (endpoint: endpoint // { - interval = "5m"; - alerts = [{ type = "email"; }]; - }) - endpoints +{ + config = lib.mkIf cfg.server.enable { + services.gatus.settings.endpoints = map + (endpoint: endpoint // { + interval = "5m"; + alerts = [{ type = "email"; }]; + }) + (machineEndpoints ++ otherEndpoints); + }; +}