From 23c2eb44eb7bc0dddfa003925a5dcc4c6e3c28eb Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Mon, 17 Jun 2019 15:33:50 +0200 Subject: [PATCH] Update prometheus/main.go --- prometheus/main.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/prometheus/main.go b/prometheus/main.go index 95440b3..2552cf9 100644 --- a/prometheus/main.go +++ b/prometheus/main.go @@ -24,22 +24,21 @@ func init() { logger := log.WithField("type", hookType) var request notify.WebhookMessage - if err := libHTTP.Read(r, &request); err != nil { - logger.Errorf("no readable payload: %s", err) - http.Error(w, fmt.Sprintf("no readable payload"), http.StatusInternalServerError) - return - } + if err := libHTTP.Read(r, &request); err != nil { + logger.Errorf("no readable payload: %s", err) + http.Error(w, fmt.Sprintf("no readable payload"), http.StatusInternalServerError) + return + } - content := "" - firingAlerts := len(request.Alerts.Firing()) - if firingAlerts > 0 { - content = fmt.Sprintf("[%s:%d] %s", request.Status, firingAlerts, strings.Join(request.CommonAnnotations.Values()," ")) - } else { - content = fmt.Sprintf("[%s] %s", request.Status, strings.Join(request.CommonAnnotations.Values()," ")) - } + content := "" + firingAlerts := len(request.Alerts.Firing()) + if firingAlerts > 0 { + content = fmt.Sprintf("[%s:%d] %s", request.Status, firingAlerts, strings.Join(request.CommonAnnotations.Values()," ")) + } else { + content = fmt.Sprintf("[%s] %s", request.Status, strings.Join(request.CommonAnnotations.Values()," ")) + } - - logger = logger.WithField("body", content) + logger = logger.WithField("body", content) ok := false for _, hook := range hooks {