Browse Source

feat(alerting): add link to panel png

bergquist 9 years ago
parent
commit
adea539b8d

+ 4 - 2
emails/templates/alert_notification.html

@@ -3,14 +3,16 @@
 [[Subject .Subject "Grafana Alert: [ [[.State]] ] [[.Name]]" ]]
 
 Alertstate: [[.State]]<br />
-[[.AlertPageUrl]]"<br />
-[[.DashboardLink]]"<br />
+[[.AlertPageUrl]]<br />
+[[.DashboardLink]]<br />
 [[.Description]]<br />
 
 [[if eq .State "Ok"]]
     Everything is Ok     
 [[end]]
 
+<img src="[[.DashboardImage]]" />
+
 [[if ne .State "Ok" ]]
     <table class="row">
         <tr>

+ 1 - 0
pkg/services/alerting/notifier.go

@@ -64,6 +64,7 @@ func (this *EmailNotifier) Dispatch(alertResult *AlertResult) {
 			"TriggeredAlerts": alertResult.TriggeredAlerts,
 			"DashboardLink":   grafanaUrl + "/dashboard/db/alerting",
 			"AlertPageUrl":    grafanaUrl + "/alerting",
+			"DashboardImage":  grafanaUrl + "/render/dashboard-solo/db/alerting?from=1466169458375&to=1466171258375&panelId=1&width=1000&height=500",
 		},
 		To:       []string{this.To},
 		Template: "alert_notification.html",

+ 12 - 11
pkg/services/notifications/notifications_test.go

@@ -45,11 +45,12 @@ func TestNotifications(t *testing.T) {
 			Convey("When sending reset email password", func() {
 				cmd := &m.SendEmailCommand{
 					Data: map[string]interface{}{
-						"Name":          "Name",
-						"State":         "Critical",
-						"Description":   "Description",
-						"DashboardLink": "http://localhost:3000/dashboard/db/alerting",
-						"AlertPageUrl":  "http://localhost:3000/alerting",
+						"Name":           "Name",
+						"State":          "Critical",
+						"Description":    "Description",
+						"DashboardLink":  "http://localhost:3000/dashboard/db/alerting",
+						"AlertPageUrl":   "http://localhost:3000/alerting",
+						"DashboardImage": "http://localhost:3000/render/dashboard-solo/db/alerting?from=1466169458375&to=1466171258375&panelId=1&width=1000&height=500",
 						"TriggeredAlerts": []testTriggeredAlert{
 							{Name: "desktop", State: "Critical", ActualValue: 13},
 							{Name: "mobile", State: "Warn", ActualValue: 5},
@@ -68,18 +69,18 @@ func TestNotifications(t *testing.T) {
 				So(sentMsg.Body, ShouldContainSubstring, "Warn")
 				So(sentMsg.Body, ShouldContainSubstring, "mobile")
 				So(sentMsg.Body, ShouldContainSubstring, "desktop")
-
 				So(sentMsg.Subject, ShouldContainSubstring, "Grafana Alert: [ Critical ] ")
 			})
 
 			Convey("given critical", func() {
 				cmd := &m.SendEmailCommand{
 					Data: map[string]interface{}{
-						"Name":          "Name",
-						"State":         "Warn",
-						"Description":   "Description",
-						"DashboardLink": "http://localhost:3000/dashboard/db/alerting",
-						"AlertPageUrl":  "http://localhost:3000/alerting",
+						"Name":           "Name",
+						"State":          "Warn",
+						"Description":    "Description",
+						"DashboardLink":  "http://localhost:3000/dashboard/db/alerting",
+						"DashboardImage": "http://localhost:3000/render/dashboard-solo/db/alerting?from=1466169458375&to=1466171258375&panelId=1&width=1000&height=500",
+						"AlertPageUrl":   "http://localhost:3000/alerting",
 						"TriggeredAlerts": []testTriggeredAlert{
 							{Name: "desktop", State: "Critical", ActualValue: 13},
 							{Name: "mobile", State: "Warn", ActualValue: 5},

+ 4 - 2
public/emails/alert_notification.html

@@ -118,8 +118,8 @@ color: #FFFFFF !important;
 {{Subject .Subject "Grafana Alert: [ {{.State}} ] {{.Name}}" }}
 
 Alertstate: {{.State}}<br />
-{{.AlertPageUrl}}"<br />
-{{.DashboardLink}}"<br />
+{{.AlertPageUrl}}<br />
+{{.DashboardLink}}<br />
 {{.Description}}<br />
 
 {{if eq .State "Ok"}}
@@ -127,6 +127,8 @@ Alertstate: {{.State}}<br />
 {{end}}
 
 {{if ne .State "Ok" }}
+    <img src="{{.DashboardImage}}" style="-ms-interpolation-mode: bicubic; clear: both; display: block; float: left; max-width: 100%; outline: none; text-decoration: none; width: auto" align="left" />
+
     <table class="row" style="border-collapse: collapse; border-spacing: 0; display: block; padding: 0px; position: relative; text-align: left; vertical-align: top; width: 100%">
         <tr style="padding: 0; text-align: left; vertical-align: top" align="left">
             <td class="expander" style="-moz-hyphens: auto; -webkit-font-smoothing: antialiased; -webkit-hyphens: auto; -webkit-text-size-adjust: none; border-collapse: collapse !important; color: #222222; font-family: 'Open Sans', 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 14px; font-weight: normal; hyphens: auto; line-height: 19px; margin: 0; padding: 0; text-align: left; vertical-align: top; visibility: hidden; width: 0px; word-break: break-word" align="left" valign="top">Serie</td>