mirror of
https://github.com/grafana/grafana.git
synced 2026-07-29 15:59:50 -05:00
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>
This commit is contained in:
co-authored by
Marcus Efraimsson
parent
24673dc7d1
commit
1e543d5ac1
@@ -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")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user