mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): make sure dashboard id exists
This commit is contained in:
@@ -20,7 +20,6 @@ type Alert struct {
|
||||
}
|
||||
|
||||
func (cmd *SaveDashboardCommand) GetAlertModels() *[]Alert {
|
||||
dash := NewDashboardFromJson(cmd.Dashboard)
|
||||
alerts := make([]Alert, 0)
|
||||
|
||||
for _, rowObj := range cmd.Dashboard.Get("rows").MustArray() {
|
||||
@@ -31,7 +30,7 @@ func (cmd *SaveDashboardCommand) GetAlertModels() *[]Alert {
|
||||
|
||||
alerting := panel.Get("alerting")
|
||||
alert := Alert{
|
||||
DashboardId: dash.Id,
|
||||
DashboardId: cmd.Result.Id,
|
||||
PanelId: panel.Get("id").MustInt64(),
|
||||
Id: alerting.Get("id").MustInt64(),
|
||||
QueryRefId: alerting.Get("query_ref").MustString(),
|
||||
|
||||
@@ -258,6 +258,9 @@ func TestAlertModel(t *testing.T) {
|
||||
UserId: 1,
|
||||
OrgId: 1,
|
||||
Overwrite: true,
|
||||
Result: &Dashboard{
|
||||
Id: 1,
|
||||
},
|
||||
}
|
||||
|
||||
alerts := *cmd.GetAlertModels()
|
||||
@@ -267,7 +270,7 @@ func TestAlertModel(t *testing.T) {
|
||||
So(len(alerts), ShouldEqual, 1)
|
||||
|
||||
for _, v := range alerts {
|
||||
So(v.DashboardId, ShouldNotEqual, 0)
|
||||
So(v.DashboardId, ShouldEqual, 1)
|
||||
So(v.PanelId, ShouldNotEqual, 0)
|
||||
|
||||
So(v.WarnLevel, ShouldEqual, 30)
|
||||
|
||||
Reference in New Issue
Block a user