diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go index 4df0b6a79e3..2bf6ed9255a 100644 --- a/pkg/api/alerting.go +++ b/pkg/api/alerting.go @@ -82,7 +82,7 @@ func GetAlerts(c *middleware.Context) Response { //TODO: should be possible to speed this up with lookup table for _, alert := range alertDTOs { - for _, dash := range *dashboardsQuery.Result { + for _, dash := range dashboardsQuery.Result { if alert.DashboardId == dash.Id { alert.DashbboardUri = "db/" + dash.Slug } diff --git a/pkg/api/playlist_play.go b/pkg/api/playlist_play.go index f3bae6cbcd3..e4feb3442fb 100644 --- a/pkg/api/playlist_play.go +++ b/pkg/api/playlist_play.go @@ -18,7 +18,7 @@ func populateDashboardsById(dashboardByIds []int64) ([]m.PlaylistDashboardDto, e return result, err } - for _, item := range *dashboardQuery.Result { + for _, item := range dashboardQuery.Result { result = append(result, m.PlaylistDashboardDto{ Id: item.Id, Slug: item.Slug, diff --git a/pkg/models/dashboards.go b/pkg/models/dashboards.go index 610f29e70aa..90e1eabc707 100644 --- a/pkg/models/dashboards.go +++ b/pkg/models/dashboards.go @@ -151,7 +151,7 @@ type GetDashboardTagsQuery struct { type GetDashboardsQuery struct { DashboardIds []int64 - Result *[]Dashboard + Result []*Dashboard } type GetDashboardSlugByIdQuery struct { diff --git a/pkg/services/alerting/notifier.go b/pkg/services/alerting/notifier.go index c763e37c133..433935bbb2b 100644 --- a/pkg/services/alerting/notifier.go +++ b/pkg/services/alerting/notifier.go @@ -2,6 +2,7 @@ package alerting import ( "fmt" + "strconv" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" @@ -62,15 +63,38 @@ func (this *EmailNotifier) Dispatch(alertResult *AlertResult) { grafanaUrl += "/" + setting.AppSubUrl } + query := &m.GetDashboardsQuery{ + DashboardIds: []int64{alertResult.AlertJob.Rule.DashboardId}, + } + + if err := bus.Dispatch(query); err != nil { + this.log.Error("Failed to load dashboard", "error", err) + return + } + + if len(query.Result) != 1 { + this.log.Error("Can only support one dashboard", "result", len(query.Result)) + return + } + + dashboard := query.Result[0] + + panelId := strconv.Itoa(int(alertResult.AlertJob.Rule.PanelId)) + + //TODO: get from alertrule and transforms to seconds + from := "1466169458375" + to := "1466171258375" + + renderUrl := fmt.Sprintf("%s/render/dashboard-solo/db/%s?from=%s&to=%s&panelId=%s&width=1000&height=500", grafanaUrl, dashboard.Slug, from, to, panelId) cmd := &m.SendEmailCommand{ Data: map[string]interface{}{ "Name": "Name", "State": alertResult.State, "Description": alertResult.Description, "TriggeredAlerts": alertResult.TriggeredAlerts, - "DashboardLink": grafanaUrl + "/dashboard/db/alerting", + "DashboardLink": grafanaUrl + "/dashboard/db/" + dashboard.Slug, "AlertPageUrl": grafanaUrl + "/alerting", - "DashboardImage": grafanaUrl + "/render/dashboard-solo/db/alerting?from=1466169458375&to=1466171258375&panelId=1&width=1000&height=500", + "DashboardImage": renderUrl, }, To: []string{this.To}, Template: "alert_notification.html", diff --git a/pkg/services/sqlstore/dashboard.go b/pkg/services/sqlstore/dashboard.go index fbf245a951b..e6c5367d591 100644 --- a/pkg/services/sqlstore/dashboard.go +++ b/pkg/services/sqlstore/dashboard.go @@ -249,10 +249,10 @@ func GetDashboards(query *m.GetDashboardsQuery) error { return m.ErrCommandValidationFailed } - var dashboards = make([]m.Dashboard, 0) + var dashboards = make([]*m.Dashboard, 0) err := x.In("id", query.DashboardIds).Find(&dashboards) - query.Result = &dashboards + query.Result = dashboards if err != nil { return err