From 0a3ead8b6ee88b7bc8bb88283820d5b96aef8149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sun, 12 Feb 2023 14:28:24 +0100 Subject: [PATCH] silence: Add to multi alert-mode as well --- README.md | 4 ++++ main.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index a6a5a5c..6deb0e7 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,10 @@ alertmanager { # to create a silence via the Alertmanager API. Because of limitations in ntfy, # the request will be proxied through ntfy-alertmanager. Therefore ntfy-alertmanager # needs to be exposed to external network requests and base-url has to be set. + # + # When alert-mode is set to "single" all alert labels will be used to create the silence. + # When it is "multi" common labels between all the alerts will be used. WARNING: This + # could silence unwanted alerts. silence-duration 24h # Basic authentication (https://prometheus.io/docs/alerting/latest/https/) user user diff --git a/main.go b/main.go index df75f8b..83b9660 100644 --- a/main.go +++ b/main.go @@ -199,6 +199,20 @@ func (rcv *receiver) multiAlertNotification(p *payload) *notification { n.priority = priority n.tags = tagString + if rcv.cfg.am.SilenceDuration != 0 { + if rcv.cfg.BaseURL == "" { + rcv.logger.Error("Failed to create silence action: No base-url set") + } + + s := &silenceBody{AlertManagerURL: p.ExternalURL, Labels: p.CommonLabels} + b, err := json.Marshal(s) + if err != nil { + rcv.logger.Errorf("Failed to create silence action: %v", err) + } + + n.silenceBody = base64.StdEncoding.EncodeToString(b) + } + return n } -- 2.44.0