monitor hosts and dns

This commit is contained in:
Pim Kunis 2024-03-05 22:51:26 +01:00
parent d03be78a63
commit 20a394f911
2 changed files with 51 additions and 8 deletions

View file

@ -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;

View file

@ -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
{
config = lib.mkIf cfg.server.enable {
services.gatus.settings.endpoints = map
(endpoint: endpoint // {
interval = "5m";
alerts = [{ type = "email"; }];
})
endpoints
(machineEndpoints ++ otherEndpoints);
};
}