From f6e36a699ae2d073e340e0a5844b8e111ed3de37 Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Thu, 23 Mar 2023 16:59:15 +0300 Subject: 2023-03-23 --- modules/nixos/alertmanager.nix | 79 ++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 26 deletions(-) (limited to 'modules/nixos/alertmanager.nix') diff --git a/modules/nixos/alertmanager.nix b/modules/nixos/alertmanager.nix index 871b0c4..8f5b34b 100644 --- a/modules/nixos/alertmanager.nix +++ b/modules/nixos/alertmanager.nix @@ -1,11 +1,14 @@ { config, + inputs, lib, ... }: with lib; let cfg = config.nixfiles.modules.alertmanager; in { + imports = [inputs.alertmanager-ntfy.nixosModules.default]; + options.nixfiles.modules.alertmanager = { enable = mkEnableOption "Alertmanager"; @@ -23,41 +26,65 @@ in { }; config = mkIf cfg.enable { - nixfiles.modules.nginx = with cfg; { - enable = true; - upstreams.alertmanager.servers."127.0.0.1:${toString cfg.port}" = {}; - virtualHosts.${cfg.domain} = { - locations."/".proxyPass = "http://alertmanager"; - extraConfig = nginxInternalOnly; + nixfiles.modules = { + ntfy.enable = true; + nginx = with cfg; { + enable = true; + upstreams.alertmanager.servers."127.0.0.1:${toString cfg.port}" = {}; + virtualHosts.${cfg.domain} = { + locations."/".proxyPass = "http://alertmanager"; + extraConfig = nginxInternalOnly; + }; }; }; - services.prometheus.alertmanager = { - enable = true; + services = { + prometheus.alertmanager = { + enable = true; - listenAddress = "127.0.0.1"; - inherit (cfg) port; + listenAddress = "127.0.0.1"; + inherit (cfg) port; - extraFlags = ["--web.external-url=https://${cfg.domain}"]; + extraFlags = ["--web.external-url=https://${cfg.domain}"]; - configuration = { - global = { - smtp_from = "alertmanager@${my.domain.shire}"; - smtp_smarthost = "${my.domain.shire}:584"; - }; + configuration = { + global = { + smtp_from = "alertmanager@${my.domain.shire}"; + smtp_smarthost = "${my.domain.shire}:584"; + }; - route = { - receiver = my.username; - group_by = ["alertname"]; - }; + route = { + receiver = my.username; + group_by = ["alertname"]; + }; - receivers = [ - { - name = my.username; - email_configs = [{to = "${my.username}+alert@${my.domain.shire}";}]; - } - ]; + receivers = [ + { + name = my.username; + # TODO + # email_configs = [ + # { + # to = "${my.username}+alert@${my.domain.shire}"; + # } + # ]; + webhook_configs = [ + { + url = with config.pinpox.services.alertmanager-ntfy; "http://${httpAddress}:${httpPort}"; + } + ]; + } + ]; + }; }; }; + + pinpox.services.alertmanager-ntfy = { + enable = true; + httpAddress = "127.0.0.1"; + httpPort = toString (config.nixfiles.modules.ntfy.port + 1); + ntfyTopic = "${config.services.ntfy-sh.settings.base-url}/alertmanager"; + ntfyPriority = "high"; + envFile = "/dev/null"; + }; }; } -- cgit v1.2.3