Commit 1e543d5a by Sofia Papagiannaki Committed by GitHub

Alerting: Ignore obsolete notification channels referenced by alerts (#25302)

* Ignore obsolete notification channel

* Fix tests

* Update pkg/services/alerting/rule.go
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
parent 24673dc7
......@@ -140,9 +140,10 @@ func NewRuleFromDBAlert(ruleDef *models.Alert) (*Rule, error) {
if id, err := jsonModel.Get("id").Int64(); err == nil {
uid, err := translateNotificationIDToUID(id, ruleDef.OrgId)
if err != nil {
return nil, ValidationError{Reason: "Unable to translate notification id to uid, " + err.Error(), DashboardID: model.DashboardID, AlertID: model.ID, PanelID: model.PanelID}
logger.Error("Unable to translate notification id to uid", "error", err.Error(), "dashboardId", model.DashboardID, "alertId", model.ID, "panelId", model.PanelID, "notificationId", id)
} else {
model.Notifications = append(model.Notifications, uid)
}
model.Notifications = append(model.Notifications, uid)
} else if uid, err := jsonModel.Get("uid").String(); err == nil {
model.Notifications = append(model.Notifications, uid)
} else {
......
......@@ -125,7 +125,8 @@ func TestAlertRuleModel(t *testing.T) {
"frequency": "60s",
"conditions": [{"type": "test", "prop": 123 }],
"notifications": [
{"id": 999}
{"id": 999},
{"uid": "notifier2"}
]
}
`
......@@ -142,10 +143,11 @@ func TestAlertRuleModel(t *testing.T) {
Settings: alertJSON,
}
_, err := NewRuleFromDBAlert(alert)
Convey("raises an error", func() {
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "Alert validation error: Unable to translate notification id to uid, Alert notification [ Id: 999, OrgId: 1 ] not found AlertId: 1 PanelId: 1 DashboardId: 1")
alertRule, err := NewRuleFromDBAlert(alert)
Convey("swallows the error", func() {
So(err, ShouldBeNil)
So(alertRule.Notifications, ShouldNotContain, "999")
So(alertRule.Notifications, ShouldContain, "notifier2")
})
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment