mirror of
https://github.com/grafana/grafana.git
synced 2024-12-30 10:47:30 -06:00
Alerting: Fix so that sending an alert with the Alertmanager notifier doesn't fail when one of multiple configured URL's are down (#31079)
Fixes behaviour of Notify that returns error when one of the dispatch event return error, to maintain high availability, we should return error when all dispatched events return error instead. Fixes #30509
This commit is contained in:
parent
9d36f3cc2e
commit
e21f6a29b7
@ -2,6 +2,7 @@ package notifiers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@ -170,6 +171,7 @@ func (am *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) error
|
||||
|
||||
bodyJSON := simplejson.NewFromAny(alerts)
|
||||
body, _ := bodyJSON.MarshalJSON()
|
||||
errCnt := 0
|
||||
|
||||
for _, url := range am.URL {
|
||||
cmd := &models.SendWebhookSync{
|
||||
@ -182,10 +184,15 @@ func (am *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) error
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
am.log.Error("Failed to send alertmanager", "error", err, "alertmanager", am.Name, "url", url)
|
||||
return err
|
||||
errCnt++
|
||||
}
|
||||
}
|
||||
|
||||
// This happens when every dispatch return error
|
||||
if errCnt == len(am.URL) {
|
||||
return fmt.Errorf("failed to send alert to alertmanager")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user