cache: Only cache the alert if it was published successfully
This commit is contained in:
parent
4b5c309a3c
commit
df02ee5303
1 changed files with 6 additions and 1 deletions
7
main.go
7
main.go
|
@ -51,6 +51,8 @@ type notification struct {
|
||||||
priority string
|
priority string
|
||||||
tags string
|
tags string
|
||||||
silenceBody string
|
silenceBody string
|
||||||
|
fingerprint fingerprint
|
||||||
|
status string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rcv *receiver) singleAlertNotifications(p *payload) []*notification {
|
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)
|
rcv.logger.Debugf("Alert %s skipped: Still in cache", alert.Fingerprint)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rcv.cache.set(alert.Fingerprint, status(alert.Status))
|
|
||||||
|
|
||||||
n := new(notification)
|
n := new(notification)
|
||||||
|
n.fingerprint = alert.Fingerprint
|
||||||
|
n.status = alert.Status
|
||||||
|
|
||||||
// create title
|
// create title
|
||||||
n.title = fmt.Sprintf("[%s]", strings.ToUpper(alert.Status))
|
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)
|
err := rcv.publish(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rcv.logger.Errorf("Failed to publish notification: %v", err)
|
rcv.logger.Errorf("Failed to publish notification: %v", err)
|
||||||
|
} else {
|
||||||
|
rcv.cache.set(n.fingerprint, status(n.status))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue