From 4478f40ef19e3c3a067ca166ce7ab3e7218de6df Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Tue, 9 Feb 2016 16:07:57 -0500 Subject: [PATCH] notifier: fix notifier error handling and improve web hook error message --- notifier/notifier.go | 7 ++++--- notifier/notifiers/webhook.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/notifier/notifier.go b/notifier/notifier.go index 081c76e2..409104c1 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -183,13 +183,13 @@ func handleTask(notification database.VulnerabilityNotification, st *utils.Stopp for { // Max attempts exceeded. if attempts >= maxAttempts { - log.Infof("giving up on sending notification '%s' to notifier '%s': max attempts exceeded (%d)\n", notification.Name, notifierName, maxAttempts) + log.Infof("giving up on sending notification '%s' via notifier '%s': max attempts exceeded (%d)\n", notification.Name, notifierName, maxAttempts) return false, false } // Backoff. if backOff > 0 { - log.Infof("waiting %v before retrying to send notification '%s' to notifier '%s' (Attempt %d / %d)\n", backOff, notification.Name, notifierName, attempts+1, maxAttempts) + log.Infof("waiting %v before retrying to send notification '%s' via notifier '%s' (Attempt %d / %d)\n", backOff, notification.Name, notifierName, attempts+1, maxAttempts) if !st.Sleep(backOff) { return false, true } @@ -199,9 +199,10 @@ func handleTask(notification database.VulnerabilityNotification, st *utils.Stopp if err := notifier.Send(notification); err != nil { // Send failed; increase attempts/backoff and retry. promNotifierBackendErrorsTotal.WithLabelValues(notifierName).Inc() - log.Errorf("could not send notification '%s' to notifier '%s': %s", notification.Name, notifierName, err) + log.Errorf("could not send notification '%s' via notifier '%s': %v", notification.Name, notifierName, err) backOff = timeutil.ExpBackoff(backOff, maxBackOff) attempts++ + continue } // Send has been successful. Go to the next notifier. diff --git a/notifier/notifiers/webhook.go b/notifier/notifiers/webhook.go index cc7d15ef..12acd92e 100644 --- a/notifier/notifiers/webhook.go +++ b/notifier/notifiers/webhook.go @@ -104,7 +104,7 @@ func (h *WebhookNotifier) Send(notification database.VulnerabilityNotification) resp, err := h.client.Post(h.endpoint, "application/json", bytes.NewBuffer(jsonNotification)) if err != nil || resp == nil || (resp.StatusCode != 200 && resp.StatusCode != 201) { if resp != nil { - return fmt.Errorf("(%d) %s", resp.StatusCode, err) + return fmt.Errorf("got status %d, expected 200/201", resp.StatusCode) } return err }