From d78e738f516c556d24fec033e4b89ebd07379766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Wed, 9 Oct 2024 00:01:39 +0200 Subject: [PATCH] alertmanager: report on matrix --- secrets | 2 +- systems/makanek/monitoring/default.nix | 65 +++++++++++++++----------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/secrets b/secrets index 3fed684..d621ecc 160000 --- a/secrets +++ b/secrets @@ -1 +1 @@ -Subproject commit 3fed684536915b6611ef24421f11c1ab488b4207 +Subproject commit d621ecc885e40ba4a7cca7ef74bb8293f021b736 diff --git a/systems/makanek/monitoring/default.nix b/systems/makanek/monitoring/default.nix index 68d8013..086ad13 100644 --- a/systems/makanek/monitoring/default.nix +++ b/systems/makanek/monitoring/default.nix @@ -181,6 +181,39 @@ in { }) ]; + + # ref https://github.com/Mic92/dotfiles/blob/f44bac5dd6970ed3fbb4feb906917331ec3c2be5/machines/eva/modules/prometheus/default.nix + systemd.services.matrix-hook = { + description = "Matrix Hook"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + environment = { + HTTP_ADDRESS = "[::1]"; + HTTP_PORT = "9088"; + MX_HOMESERVER = "https://matrix.4d2.org"; + MX_ID = "@lakai:4d2.org"; + MX_ROOMID = "!zlwCuPiCNMSxDviFzA:4d2.org"; + MX_MSG_TEMPLATE = "${pkgs.matrix-hook}/message.html.tmpl"; + }; + serviceConfig = { + EnvironmentFile = [ + # format: MX_TOKEN= + config.age.secrets.matrix-token-lakai-env.path + ]; + Type = "simple"; + ExecStart = "${pkgs.matrix-hook}/bin/matrix-hook"; + Restart = "always"; + RestartSec = "10"; + DynamicUser = true; + User = "matrix-hook"; + Group = "matrix-hook"; + }; + }; + + age.secrets = { + matrix-token-lakai-env.file = ../../../secrets/matrix-token-lakai-env.age; + }; + services.prometheus.alertmanager = { enable = true; listenAddress = "localhost"; @@ -190,39 +223,17 @@ in { route = { group_wait = "30s"; repeat_interval = "24h"; - receiver = "all"; + receiver = "matrix"; }; receivers = [ { - name = "all"; - telegram_configs = [ + name = "matrix"; + webhook_configs = [ { - bot_token = "$TELEGRAM_TOKEN"; - chat_id = 18980945; - parse_mode = ""; - api_url = "https://api.telegram.org"; - send_resolved = true; - message = '' - {{range .Alerts -}} - {{ .Status }}: {{ index .Annotations "summary" }} - {{end -}} - ''; + url = "http://localhost:9088/alert"; + max_alerts = 5; } ]; - email_configs = let - inherit (import ../../../lib) kieran; - inherit (import ../../../lib/email.nix {inherit lib;}) cock; - cockConfig = { - send_resolved = true; - to = kieran.email; - from = cock.user; - smarthost = "${cock.smtp}:587"; - auth_username = cock.user; - auth_identity = cock.user; - auth_password = "$EMAIL_PASSWORD"; - }; - in [ - ]; } ]; };