Commit f461d520 by Pavel Bakulev

Converted notification id to uid via fmt for old alert notification settings

parent 2de32756
......@@ -9,8 +9,6 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/bus"
)
var (
......@@ -129,28 +127,10 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
for _, v := range ruleDef.Settings.Get("notifications").MustArray() {
jsonModel := simplejson.NewFromAny(v)
if id, err := jsonModel.Get("id").Int64(); err == nil {
cmd := m.GetAlertNotificationsQuery{
Id: id,
OrgId: ruleDef.OrgId,
}
if err = bus.Dispatch(&cmd); err != nil {
return nil, err
}
if cmd.Result == nil {
errString := fmt.Sprintf("Alert notification id %d doesn't exist", id)
return nil, ValidationError{Reason: errString, DashboardId: model.DashboardId, Alertid: model.Id, PanelId: model.PanelId}
}
if cmd.Result.Uid == "" {
errString := fmt.Sprintf("Alert notification id %d has empty uid", id)
return nil, ValidationError{Reason: errString, DashboardId: model.DashboardId, Alertid: model.Id, PanelId: model.PanelId}
}
model.Notifications = append(model.Notifications, cmd.Result.Uid)
model.Notifications = append(model.Notifications, fmt.Sprintf("%09d", id))
} else {
if uid, err := jsonModel.Get("uid").String(); err != nil {
return nil, ValidationError{Reason: "Neither id nor uid is specified", DashboardId: model.DashboardId, Alertid: model.Id, PanelId: model.PanelId}
return nil, ValidationError{Reason: "Neither id nor uid is specified, " + err.Error(), DashboardId: model.DashboardId, Alertid: model.Id, PanelId: model.PanelId}
} else {
model.Notifications = append(model.Notifications, uid)
}
......
......@@ -61,7 +61,7 @@ func TestAlertRuleModel(t *testing.T) {
Convey("can construct alert rule model", func() {
err := sqlstore.CreateOrg(&m.CreateOrgCommand{Name: "Main Org."})
So(err, ShouldBeNil)
firstNotification := m.CreateAlertNotificationCommand{Uid: "notifier1", OrgId: 1, Name: "1"}
firstNotification := m.CreateAlertNotificationCommand{OrgId: 1, Name: "1"}
err = sqlstore.CreateAlertNotificationCommand(&firstNotification)
So(err, ShouldBeNil)
secondNotification := m.CreateAlertNotificationCommand{Uid: "notifier2", OrgId: 1, Name: "2"}
......@@ -109,7 +109,7 @@ func TestAlertRuleModel(t *testing.T) {
Convey("Can read notifications", func() {
So(len(alertRule.Notifications), ShouldEqual, 2)
So(alertRule.Notifications, ShouldContain, "notifier1")
So(alertRule.Notifications, ShouldContain, "000000001")
So(alertRule.Notifications, ShouldContain, "notifier2")
})
})
......@@ -180,7 +180,7 @@ func TestAlertRuleModel(t *testing.T) {
_, err := NewRuleFromDBAlert(alert)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "Alert validation error: Neither id nor uid is specified AlertId: 1 PanelId: 1 DashboardId: 1")
So(err.Error(), ShouldEqual, "Alert validation error: Neither id nor uid is specified, type assertion to string failed AlertId: 1 PanelId: 1 DashboardId: 1")
})
})
......
......@@ -130,7 +130,6 @@ func getAlertNotificationInternal(query *m.GetAlertNotificationsQuery, sess *DBS
sql.WriteString(`SELECT
alert_notification.id,
alert_notification.uid,
alert_notification.org_id,
alert_notification.name,
alert_notification.type,
......
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