silence: Fix broken ntfy action

A silence action was added even when "base-url" was not set. This action
would of course fail, since there was no valid URL scheme given.
The action button is now removed in that case.
This commit is contained in:
Thorben Günther 2023-02-12 16:32:34 +01:00
parent 38fa5f9f71
commit a329d4dc52
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED

View file

@ -113,8 +113,7 @@ func (rcv *receiver) singleAlertNotifications(p *payload) []*notification {
if rcv.cfg.am.SilenceDuration != 0 && alert.Status == "firing" { if rcv.cfg.am.SilenceDuration != 0 && alert.Status == "firing" {
if rcv.cfg.BaseURL == "" { if rcv.cfg.BaseURL == "" {
rcv.logger.Error("Failed to create silence action: No base-url set") 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 // 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 // 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 // and sent to the ntfy-alertmanager silences endpoint, that operates as
@ -127,6 +126,7 @@ func (rcv *receiver) singleAlertNotifications(p *payload) []*notification {
n.silenceBody = base64.StdEncoding.EncodeToString(b) n.silenceBody = base64.StdEncoding.EncodeToString(b)
} }
}
notifications = append(notifications, n) notifications = append(notifications, n)
} }
@ -202,7 +202,7 @@ func (rcv *receiver) multiAlertNotification(p *payload) *notification {
if rcv.cfg.am.SilenceDuration != 0 && p.Status == "firing" { if rcv.cfg.am.SilenceDuration != 0 && p.Status == "firing" {
if rcv.cfg.BaseURL == "" { if rcv.cfg.BaseURL == "" {
rcv.logger.Error("Failed to create silence action: No base-url set") rcv.logger.Error("Failed to create silence action: No base-url set")
} } else {
s := &silenceBody{AlertManagerURL: p.ExternalURL, Labels: p.CommonLabels} s := &silenceBody{AlertManagerURL: p.ExternalURL, Labels: p.CommonLabels}
b, err := json.Marshal(s) b, err := json.Marshal(s)
@ -212,6 +212,7 @@ func (rcv *receiver) multiAlertNotification(p *payload) *notification {
n.silenceBody = base64.StdEncoding.EncodeToString(b) n.silenceBody = base64.StdEncoding.EncodeToString(b)
} }
}
return n return n
} }