~xenrox/ntfy-alertmanager

df02ee53033d2d40c23714d03db4af487de0b39e — Thorben Günther 1 year, 2 months ago 4b5c309
cache: Only cache the alert if it was published successfully
1 files changed, 6 insertions(+), 1 deletions(-)

M main.go
M main.go => main.go +6 -1
@@ 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 {