Skip to content

Commit

Permalink
notifier: fix notifier error handling and improve web hook error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-M authored and jzelinskie committed Feb 24, 2016
1 parent 2126259 commit 4478f40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion notifier/notifiers/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 4478f40

Please sign in to comment.