diff --git a/main.go b/main.go index ea9396c..35e2102 100644 --- a/main.go +++ b/main.go @@ -113,19 +113,19 @@ func (rcv *receiver) singleAlertNotifications(p *payload) []*notification { if rcv.cfg.am.SilenceDuration != 0 && alert.Status == "firing" { if rcv.cfg.BaseURL == "" { rcv.logger.Error("Failed to create silence action: No base-url set") - } + } else { + // I could not convince ntfy to accept an Action with a body which contains + // a json with more than one key. Instead the json will be base64 encoded + // and sent to the ntfy-alertmanager silences endpoint, that operates as + // a proxy and will do the Alertmanager API request. + s := &silenceBody{AlertManagerURL: p.ExternalURL, Labels: alert.Labels} + b, err := json.Marshal(s) + if err != nil { + rcv.logger.Errorf("Failed to create silence action: %v", err) + } - // I could not convince ntfy to accept an Action with a body which contains - // a json with more than one key. Instead the json will be base64 encoded - // and sent to the ntfy-alertmanager silences endpoint, that operates as - // a proxy and will do the Alertmanager API request. - s := &silenceBody{AlertManagerURL: p.ExternalURL, Labels: alert.Labels} - b, err := json.Marshal(s) - if err != nil { - rcv.logger.Errorf("Failed to create silence action: %v", err) + n.silenceBody = base64.StdEncoding.EncodeToString(b) } - - n.silenceBody = base64.StdEncoding.EncodeToString(b) } notifications = append(notifications, n) @@ -202,15 +202,16 @@ func (rcv *receiver) multiAlertNotification(p *payload) *notification { if rcv.cfg.am.SilenceDuration != 0 && p.Status == "firing" { if rcv.cfg.BaseURL == "" { rcv.logger.Error("Failed to create silence action: No base-url set") - } + } else { - 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) - } + 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) + n.silenceBody = base64.StdEncoding.EncodeToString(b) + } } return n