From df02ee53033d2d40c23714d03db4af487de0b39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sun, 12 Feb 2023 16:50:18 +0100 Subject: [PATCH] cache: Only cache the alert if it was published successfully --- main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 35e2102..d158722 100644 --- a/main.go +++ b/main.go @@ -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 { -- 2.44.0