Skip to content

Commit 48e1a17

Browse files
committed
feat(alerting): remove dummie values from email notifier
1 parent 6121d15 commit 48e1a17

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

pkg/api/alerting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func GetAlerts(c *middleware.Context) Response {
8282

8383
//TODO: should be possible to speed this up with lookup table
8484
for _, alert := range alertDTOs {
85-
for _, dash := range *dashboardsQuery.Result {
85+
for _, dash := range dashboardsQuery.Result {
8686
if alert.DashboardId == dash.Id {
8787
alert.DashbboardUri = "db/" + dash.Slug
8888
}

pkg/api/playlist_play.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func populateDashboardsById(dashboardByIds []int64) ([]m.PlaylistDashboardDto, e
1818
return result, err
1919
}
2020

21-
for _, item := range *dashboardQuery.Result {
21+
for _, item := range dashboardQuery.Result {
2222
result = append(result, m.PlaylistDashboardDto{
2323
Id: item.Id,
2424
Slug: item.Slug,

pkg/models/dashboards.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ type GetDashboardTagsQuery struct {
151151

152152
type GetDashboardsQuery struct {
153153
DashboardIds []int64
154-
Result *[]Dashboard
154+
Result []*Dashboard
155155
}
156156

157157
type GetDashboardSlugByIdQuery struct {

pkg/services/alerting/notifier.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package alerting
22

33
import (
44
"fmt"
5+
"strconv"
56

67
"github.com/grafana/grafana/pkg/bus"
78
"github.com/grafana/grafana/pkg/components/simplejson"
@@ -62,15 +63,38 @@ func (this *EmailNotifier) Dispatch(alertResult *AlertResult) {
6263
grafanaUrl += "/" + setting.AppSubUrl
6364
}
6465

66+
query := &m.GetDashboardsQuery{
67+
DashboardIds: []int64{alertResult.AlertJob.Rule.DashboardId},
68+
}
69+
70+
if err := bus.Dispatch(query); err != nil {
71+
this.log.Error("Failed to load dashboard", "error", err)
72+
return
73+
}
74+
75+
if len(query.Result) != 1 {
76+
this.log.Error("Can only support one dashboard", "result", len(query.Result))
77+
return
78+
}
79+
80+
dashboard := query.Result[0]
81+
82+
panelId := strconv.Itoa(int(alertResult.AlertJob.Rule.PanelId))
83+
84+
//TODO: get from alertrule and transforms to seconds
85+
from := "1466169458375"
86+
to := "1466171258375"
87+
88+
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)
6589
cmd := &m.SendEmailCommand{
6690
Data: map[string]interface{}{
6791
"Name": "Name",
6892
"State": alertResult.State,
6993
"Description": alertResult.Description,
7094
"TriggeredAlerts": alertResult.TriggeredAlerts,
71-
"DashboardLink": grafanaUrl + "/dashboard/db/alerting",
95+
"DashboardLink": grafanaUrl + "/dashboard/db/" + dashboard.Slug,
7296
"AlertPageUrl": grafanaUrl + "/alerting",
73-
"DashboardImage": grafanaUrl + "/render/dashboard-solo/db/alerting?from=1466169458375&to=1466171258375&panelId=1&width=1000&height=500",
97+
"DashboardImage": renderUrl,
7498
},
7599
To: []string{this.To},
76100
Template: "alert_notification.html",

pkg/services/sqlstore/dashboard.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ func GetDashboards(query *m.GetDashboardsQuery) error {
249249
return m.ErrCommandValidationFailed
250250
}
251251

252-
var dashboards = make([]m.Dashboard, 0)
252+
var dashboards = make([]*m.Dashboard, 0)
253253

254254
err := x.In("id", query.DashboardIds).Find(&dashboards)
255-
query.Result = &dashboards
255+
query.Result = dashboards
256256

257257
if err != nil {
258258
return err

0 commit comments

Comments
 (0)