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 = [ imports = [
"${nixpkgs-unstable}/nixos/modules/services/monitoring/gatus.nix" "${nixpkgs-unstable}/nixos/modules/services/monitoring/gatus.nix"
./gatus-endpoints.nix
]; ];
options = { options = {
@ -57,7 +58,6 @@ in
settings = { settings = {
web.port = 4242; web.port = 4242;
endpoints = import ./gatus-endpoints.nix;
alerting.email = { alerting.email = {
from = "gatus@kun.is"; from = "gatus@kun.is";
@ -65,6 +65,7 @@ in
port = 2525; port = 2525;
to = "pim@kunis.nl"; to = "pim@kunis.nl";
client.insecure = true; client.insecure = true;
default-alert = { default-alert = {
enabled = true; enabled = true;
failure-threshold = 2; failure-threshold = 2;

View file

@ -1,8 +1,24 @@
{ lib, config, machines, ... }:
let let
cfg = config.lab.monitoring;
status = code: "[STATUS] == ${toString code}"; status = code: "[STATUS] == ${toString code}";
bodyContains = text: "[BODY] == pat(*${text}*)"; bodyContains = text: "[BODY] == pat(*${text}*)";
maxResponseTime = ms: "[RESPONSE_TIME] < ${toString ms}"; 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"; name = "Forgejo";
url = "https://git.kun.is"; url = "https://git.kun.is";
@ -182,11 +198,37 @@ let
(maxResponseTime 750) (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 in
map {
config = lib.mkIf cfg.server.enable {
services.gatus.settings.endpoints = map
(endpoint: endpoint // { (endpoint: endpoint // {
interval = "5m"; interval = "5m";
alerts = [{ type = "email"; }]; alerts = [{ type = "email"; }];
}) })
endpoints (machineEndpoints ++ otherEndpoints);
};
}