diff --git a/pkg/services/alerting/rule.go b/pkg/services/alerting/rule.go index 529f3b9ff95..902c1660976 100644 --- a/pkg/services/alerting/rule.go +++ b/pkg/services/alerting/rule.go @@ -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) } diff --git a/pkg/services/alerting/rule_test.go b/pkg/services/alerting/rule_test.go index 9b99278a5aa..7e8af888338 100644 --- a/pkg/services/alerting/rule_test.go +++ b/pkg/services/alerting/rule_test.go @@ -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") }) }) diff --git a/pkg/services/sqlstore/alert_notification.go b/pkg/services/sqlstore/alert_notification.go index 0b958489624..9231c896cf1 100644 --- a/pkg/services/sqlstore/alert_notification.go +++ b/pkg/services/sqlstore/alert_notification.go @@ -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,