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:
parent
38fa5f9f71
commit
a329d4dc52
1 changed files with 19 additions and 18 deletions
7
main.go
7
main.go
|
@ -113,8 +113,7 @@ 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
|
||||
|
@ -127,6 +126,7 @@ func (rcv *receiver) singleAlertNotifications(p *payload) []*notification {
|
|||
|
||||
n.silenceBody = base64.StdEncoding.EncodeToString(b)
|
||||
}
|
||||
}
|
||||
|
||||
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.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)
|
||||
|
@ -212,6 +212,7 @@ func (rcv *receiver) multiAlertNotification(p *payload) *notification {
|
|||
|
||||
n.silenceBody = base64.StdEncoding.EncodeToString(b)
|
||||
}
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue