cache: Only cache the alert if it was published successfully

This commit is contained in:
Thorben Günther 2023-02-12 16:50:18 +01:00
parent 4b5c309a3c
commit df02ee5303
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED

View file

@ -51,6 +51,8 @@ type notification struct {
priority string
tags string
silenceBody string
fingerprint fingerprint
status string
}
func (rcv *receiver) singleAlertNotifications(p *payload) []*notification {
@ -60,9 +62,10 @@ func (rcv *receiver) singleAlertNotifications(p *payload) []*notification {
rcv.logger.Debugf("Alert %s skipped: Still in cache", alert.Fingerprint)
continue
}
rcv.cache.set(alert.Fingerprint, status(alert.Status))
n := new(notification)
n.fingerprint = alert.Fingerprint
n.status = alert.Status
// create title
n.title = fmt.Sprintf("[%s]", strings.ToUpper(alert.Status))
@ -297,6 +300,8 @@ func (rcv *receiver) handleWebhooks(w http.ResponseWriter, r *http.Request) {
err := rcv.publish(n)
if err != nil {
rcv.logger.Errorf("Failed to publish notification: %v", err)
} else {
rcv.cache.set(n.fingerprint, status(n.status))
}
}
} else {