diff --git a/emails/templates/layouts/default.html b/emails/templates/layouts/default.html index 80d24d53082..80708eaa835 100644 --- a/emails/templates/layouts/default.html +++ b/emails/templates/layouts/default.html @@ -143,7 +143,7 @@ td[class="stack-column-center"] {

Sent by Grafana v[[.BuildVersion]] -
© 2019 Grafana Labs +
© 2021 Grafana Labs

diff --git a/emails/templates/ng_alert_notification.html b/emails/templates/ng_alert_notification.html index 71d0542640a..2efb616852b 100644 --- a/emails/templates/ng_alert_notification.html +++ b/emails/templates/ng_alert_notification.html @@ -15,7 +15,11 @@
-

[[.Title]]

+ [[ if gt (len .Alerts.Firing) 0 ]] +

[[.Title]]

+ [[ else ]] +

[[.Title]]

+ [[ end ]]
diff --git a/pkg/services/ngalert/notifier/channels/email.go b/pkg/services/ngalert/notifier/channels/email.go index e0487aee99e..157d6533990 100644 --- a/pkg/services/ngalert/notifier/channels/email.go +++ b/pkg/services/ngalert/notifier/channels/email.go @@ -2,7 +2,9 @@ package channels import ( "context" + "fmt" "net/url" + "strings" gokit_log "github.com/go-kit/kit/log" "github.com/grafana/grafana/pkg/infra/log" @@ -66,12 +68,13 @@ func (en *EmailNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool, // We only need ExternalURL from this template object. This hack should go away with https://github.com/prometheus/alertmanager/pull/2508. data := notify.GetTemplateData(ctx, &template.Template{ExternalURL: en.externalUrl}, as, gokit_log.NewNopLogger()) + title := getTitleFromTemplateData(data) + cmd := &models.SendEmailCommandSync{ SendEmailCommand: models.SendEmailCommand{ - Subject: "TODO", + Subject: title, Data: map[string]interface{}{ - "Title": "TODO", - "Subject": "TODO", + "Title": title, "Receiver": data.Receiver, "Status": data.Status, "Alerts": data.Alerts, @@ -95,6 +98,18 @@ func (en *EmailNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool, return true, nil } +func getTitleFromTemplateData(data *template.Data) string { + title := "[" + data.Status + if data.Status == string(model.AlertFiring) { + title += fmt.Sprintf(":%d", len(data.Alerts.Firing())) + } + title += "]" + strings.Join(data.GroupLabels.SortedPairs().Values(), " ") + " " + if len(data.CommonLabels) > len(data.GroupLabels) { + title += "(" + strings.Join(data.CommonLabels.Remove(data.GroupLabels.Names()).Values(), " ") + ")" + } + return title +} + func (en *EmailNotifier) SendResolved() bool { // TODO: implement this. return true diff --git a/public/emails/alert_notification.html b/public/emails/alert_notification.html index 0921c033954..1ffbd182400 100644 --- a/public/emails/alert_notification.html +++ b/public/emails/alert_notification.html @@ -183,7 +183,7 @@ text-decoration: underline; diff --git a/public/emails/invited_to_org.html b/public/emails/invited_to_org.html index d2e7fa78e7a..25b4ef8b034 100644 --- a/public/emails/invited_to_org.html +++ b/public/emails/invited_to_org.html @@ -183,7 +183,7 @@ text-decoration: underline;
- +
diff --git a/public/emails/new_user_invite.html b/public/emails/new_user_invite.html index 4bbb35c97ee..9679738e6fa 100644 --- a/public/emails/new_user_invite.html +++ b/public/emails/new_user_invite.html @@ -183,7 +183,7 @@ text-decoration: underline;
- +
diff --git a/public/emails/ng_alert_notification.html b/public/emails/ng_alert_notification.html new file mode 100644 index 00000000000..afdd0ed042b --- /dev/null +++ b/public/emails/ng_alert_notification.html @@ -0,0 +1,364 @@ + + + + + + + + + +
- +
+ + + +
+
+ + + + +
+
+ + + + + +
+ + + + + + +
+ +
+ +
+ +
+
+ + + + + + + + +
+ {{Subject .Subject "{{.Title}}"}} + + + + + + + +
+ + + + +
+ {{ if gt (len .Alerts.Firing) 0 }} +

{{.Title}}

+ {{ else }} +

{{.Title}}

+ {{ end }} +
+
+ + + + + +
+ + + {{ if gt (len .Alerts.Firing) 0 }} + + + + + +
+ {{ else }} + + {{ end }}. + {{ .Alerts | len }} alert{{ if gt (len .Alerts) 1 }}s{{ end }} for + {{ range .GroupLabels.SortedPairs }} + {{ .Name }}={{ .Value }} + {{ end }} +
+ + {{ if gt (len .Alerts.Firing) 0 }} + + + + {{ end }} + {{ range .Alerts.Firing }} + + + + {{ end }} + + {{ if gt (len .Alerts.Resolved) 0 }} + {{ if gt (len .Alerts.Firing) 0 }} + + + + {{ end }} + + + + {{ end }} + {{ range .Alerts.Resolved }} + + + + {{ end }} +
+ ({{ .Alerts.Firing | len }}) Firing +
+ Labels
+ {{ range .Labels.SortedPairs }}{{ .Name }} = {{ .Value }}
{{ end }} + {{ if gt (len .Annotations) 0 }}Annotations
{{ end }} + {{ range .Annotations.SortedPairs }}{{ .Name }} = {{ .Value }}
{{ end }} + Source
+
+
+
+
+
+ ({{ .Alerts.Resolved | len }}) Resolved +
+ Labels
+ {{ range .Labels.SortedPairs }}{{ .Name }} = {{ .Value }}
{{ end }} + {{ if gt (len .Annotations) 0 }}Annotations
{{ end }} + {{ range .Annotations.SortedPairs }}{{ .Name }} = {{ .Value }}
{{ end }} + Source
+
+
+
+ + + + + + + +
+ + + + + +
+ + + + +
+ View your Alert rule +
+
+ + + + +
+ Go to the Alerts page +
+
+
+ + + + +
+ + + + + + +
+
+ + diff --git a/public/emails/reset_password.html b/public/emails/reset_password.html index 58f92a246a7..697928655ed 100644 --- a/public/emails/reset_password.html +++ b/public/emails/reset_password.html @@ -183,7 +183,7 @@ text-decoration: underline; diff --git a/public/emails/signup_started.html b/public/emails/signup_started.html index 394e10df9ba..dab02e572e6 100644 --- a/public/emails/signup_started.html +++ b/public/emails/signup_started.html @@ -183,7 +183,7 @@ text-decoration: underline;
- +
diff --git a/public/emails/welcome_on_signup.html b/public/emails/welcome_on_signup.html index e9e63b6fd82..e874cc8dd30 100644 --- a/public/emails/welcome_on_signup.html +++ b/public/emails/welcome_on_signup.html @@ -183,7 +183,7 @@ text-decoration: underline;
- +
@@ -235,7 +235,7 @@ text-decoration: underline; @@ -253,7 +253,6 @@ text-decoration: underline;
- +

- If you are new to Grafana please read the Getting Started guide. + If you are new to Grafana please read the Getting Started guide.

-