mirror of https://github.com/grafana/grafana
Email: Allow configuration of content types for email notifications (#34530)
* Alerting: Allow configuration of content types for email notifications * Fix lint error * Improves email templates * Improve configuration documentation Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Improve code comments Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Improve configuration documentation Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Improve email template * Remove unnecessary predeclaration Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Adds handling for unrecognized content type Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Move utility function outside of util package * Fixes syntax * Remove unused package * Fix lint error * improve email templates * Fix test * Alerting: Allow configuration of content types for email notifications * Fix lint error * Improves email templates * Improve configuration documentation Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Improve code comments Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Improve configuration documentation Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Improve email template * Remove unnecessary predeclaration Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Adds handling for unrecognized content type Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Move utility function outside of util package * Fixes syntax * Remove unused package * Fix lint error * improve email templates * Fix test * Fix comment style Co-authored-by: Ganesh Vernekar <15064823+codesome@users.noreply.github.com> * Fix template formatting * Add test and improve error handling * Fix test * Fix formatting * Fix formatting * Improve documentation and regenerates txt template * Update docs/sources/administration/configuration.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: Djairho Geuens <djairho.geuens@ae.be> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> Co-authored-by: Ganesh Vernekar <15064823+codesome@users.noreply.github.com> Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>pull/37266/head
parent
cec12676e7
commit
4cadbba686
@ -0,0 +1,26 @@ |
|||||||
|
[[Subject .Subject "[[.Title]]"]] |
||||||
|
|
||||||
|
[[.Title]] |
||||||
|
---------------- |
||||||
|
|
||||||
|
[[.Message]] |
||||||
|
|
||||||
|
[[if ne .Error "" ]] |
||||||
|
Error message: |
||||||
|
[[.Error]] |
||||||
|
[[end]] |
||||||
|
|
||||||
|
[[if ne .State "ok" ]] |
||||||
|
[[range .EvalMatches]] |
||||||
|
Metric name: |
||||||
|
[[.Metric]] |
||||||
|
Value: |
||||||
|
[[.Value]] |
||||||
|
[[end]] |
||||||
|
[[end]] |
||||||
|
|
||||||
|
View your Alert rule: |
||||||
|
[[.RuleUrl]]" |
||||||
|
|
||||||
|
Go to the Alerts page: |
||||||
|
[[.AlertPageUrl]] |
@ -0,0 +1,9 @@ |
|||||||
|
[[Subject .Subject "[[.InvitedBy]] has added you to the [[.OrgName]] organization"]] |
||||||
|
|
||||||
|
You have been added to [[.OrgName]] |
||||||
|
|
||||||
|
[[.InvitedBy]] has added you to the [[.OrgName]] organization in Grafana. |
||||||
|
Once logged in, [[.OrgName]] will be available in the left side menu, in the dropdown below your username. |
||||||
|
|
||||||
|
Log in now: |
||||||
|
[[.AppUrl]] |
@ -0,0 +1,3 @@ |
|||||||
|
{{> body }} |
||||||
|
|
||||||
|
Sent by Grafana v[[.BuildVersion]] (c) 2021 Grafana Labs |
@ -0,0 +1,7 @@ |
|||||||
|
[[Subject .Subject "[[.InvitedBy]] has invited you to join Grafana"]] |
||||||
|
|
||||||
|
You're invited to join [[.OrgName]] |
||||||
|
|
||||||
|
You've been invited to join the [[.OrgName]] organization by [[.InvitedBy]]. To accept your invitation and join the team, copy and paste the link below into your browser directly: |
||||||
|
|
||||||
|
[[.LinkUrl]] |
@ -0,0 +1,38 @@ |
|||||||
|
[[Subject .Subject "[[.Title]]"]] |
||||||
|
|
||||||
|
[[.Title]] |
||||||
|
---------------- |
||||||
|
|
||||||
|
[[ .Alerts | len ]] alert[[ if gt (len .Alerts) 1 ]]s[[ end ]] for |
||||||
|
[[ range .GroupLabels.SortedPairs ]] |
||||||
|
[[ .Name ]] = [[ .Value ]] |
||||||
|
[[ end ]] |
||||||
|
[[ if gt (len .Alerts.Firing) 0 ]]([[ .Alerts.Firing | len ]]) Firing[[ end ]] |
||||||
|
[[ range .Alerts.Firing ]] |
||||||
|
Labels: |
||||||
|
[[ range .Labels.SortedPairs ]] |
||||||
|
[[ .Name ]] = [[ .Value ]] |
||||||
|
[[ end ]] |
||||||
|
[[ if gt (len .Annotations) 0 ]] |
||||||
|
Annotations: |
||||||
|
[[ end ]] |
||||||
|
[[ range .Annotations.SortedPairs ]] |
||||||
|
[[ .Name ]] = [[ .Value ]] |
||||||
|
[[ end ]] |
||||||
|
[[ end ]][[ if gt (len .Alerts.Resolved) 0 ]]([[ .Alerts.Resolved | len ]]) Resolved[[ end ]] |
||||||
|
[[ range .Alerts.Resolved ]] |
||||||
|
Labels: |
||||||
|
[[ range .Labels.SortedPairs ]] |
||||||
|
[[ .Name ]] = [[ .Value ]] |
||||||
|
[[ end ]] |
||||||
|
[[ if gt (len .Annotations) 0 ]] |
||||||
|
Annotations: |
||||||
|
[[ end ]] |
||||||
|
[[ range .Annotations.SortedPairs ]] |
||||||
|
[[ .Name ]] = [[ .Value ]] |
||||||
|
[[ end ]] |
||||||
|
[[ end ]]View your Alert rule: |
||||||
|
[[.RuleUrl]] |
||||||
|
|
||||||
|
Go to the Alerts page: |
||||||
|
[[.AlertPageUrl]] |
@ -0,0 +1,6 @@ |
|||||||
|
[[Subject .Subject "Reset your Grafana password - [[.Name]]"]] |
||||||
|
|
||||||
|
Hi [[.Name]], |
||||||
|
|
||||||
|
Copy and paste the following link directly in your browser to reset your password within [[.EmailCodeValidHours]] hours. |
||||||
|
[[.AppUrl]]user/password/reset?code=[[.Code]] |
@ -0,0 +1,9 @@ |
|||||||
|
[[Subject .Subject "Welcome to Grafana, please complete your sign up!"]] |
||||||
|
|
||||||
|
Complete the signup |
||||||
|
|
||||||
|
Copy and paste the email verification code: |
||||||
|
[[.Code]] |
||||||
|
in the sign up form or use the link below. |
||||||
|
|
||||||
|
[[.SignUpUrl]] |
@ -0,0 +1,11 @@ |
|||||||
|
[[Subject .Subject "Welcome to Grafana"]] |
||||||
|
|
||||||
|
Hi [[.Name]], |
||||||
|
|
||||||
|
Welcome! Ready to start building some beautiful metric and analytic dashboards? |
||||||
|
|
||||||
|
If you are new to Grafana, refer to the Getting started with Grafana guide on https://grafana.com/docs/grafana/latest/getting-started/getting-started/. |
||||||
|
|
||||||
|
Thank you for joining our community. |
||||||
|
|
||||||
|
The Grafana team |
@ -0,0 +1,41 @@ |
|||||||
|
package notifications |
||||||
|
|
||||||
|
import ( |
||||||
|
"bytes" |
||||||
|
"strings" |
||||||
|
"testing" |
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/setting" |
||||||
|
"github.com/stretchr/testify/assert" |
||||||
|
"github.com/stretchr/testify/require" |
||||||
|
) |
||||||
|
|
||||||
|
func TestBuildMail(t *testing.T) { |
||||||
|
ns := &NotificationService{ |
||||||
|
Cfg: setting.NewCfg(), |
||||||
|
} |
||||||
|
ns.Cfg.Smtp.ContentTypes = []string{"text/html", "text/plain"} |
||||||
|
|
||||||
|
message := &Message{ |
||||||
|
To: []string{"to@address.com"}, |
||||||
|
From: "from@address.com", |
||||||
|
Subject: "Some subject", |
||||||
|
Body: map[string]string{ |
||||||
|
"text/html": "Some HTML body", |
||||||
|
"text/plain": "Some plain text body", |
||||||
|
}, |
||||||
|
ReplyTo: []string{"from@address.com"}, |
||||||
|
} |
||||||
|
|
||||||
|
t.Run("When building email", func(t *testing.T) { |
||||||
|
email := ns.buildEmail(message) |
||||||
|
|
||||||
|
buf := new(bytes.Buffer) |
||||||
|
_, err := email.WriteTo(buf) |
||||||
|
require.NoError(t, err) |
||||||
|
|
||||||
|
assert.Contains(t, buf.String(), "Some HTML body") |
||||||
|
assert.Contains(t, buf.String(), "Some plain text body") |
||||||
|
assert.Less(t, strings.Index(buf.String(), "Some plain text body"), strings.Index(buf.String(), "Some HTML body")) |
||||||
|
}) |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
{{Subject .Subject "{{.Title}}"}} |
||||||
|
|
||||||
|
{{.Title}} |
||||||
|
---------------- |
||||||
|
|
||||||
|
{{.Message}} |
||||||
|
|
||||||
|
{{if ne .Error "" }} |
||||||
|
Error message: |
||||||
|
{{.Error}} |
||||||
|
{{end}} |
||||||
|
|
||||||
|
{{if ne .State "ok" }} |
||||||
|
{{range .EvalMatches}} |
||||||
|
Metric name: |
||||||
|
{{.Metric}} |
||||||
|
Value: |
||||||
|
{{.Value}} |
||||||
|
{{end}} |
||||||
|
{{end}} |
||||||
|
|
||||||
|
View your Alert rule: |
||||||
|
{{.RuleUrl}}" |
||||||
|
|
||||||
|
Go to the Alerts page: |
||||||
|
{{.AlertPageUrl}} |
||||||
|
|
||||||
|
Sent by Grafana v{{.BuildVersion}} (c) 2021 Grafana Labs |
@ -0,0 +1,12 @@ |
|||||||
|
{{Subject .Subject "{{.InvitedBy}} has added you to the {{.OrgName}} organization"}} |
||||||
|
|
||||||
|
You have been added to {{.OrgName}} |
||||||
|
|
||||||
|
{{.InvitedBy}} has added you to the {{.OrgName}} organization in Grafana. |
||||||
|
Once logged in, {{.OrgName}} will be available in the left side menu, in the dropdown |
||||||
|
below your username. |
||||||
|
|
||||||
|
Log in now: |
||||||
|
{{.AppUrl}} |
||||||
|
|
||||||
|
Sent by Grafana v{{.BuildVersion}} (c) 2021 Grafana Labs |
@ -0,0 +1,11 @@ |
|||||||
|
{{Subject .Subject "{{.InvitedBy}} has invited you to join Grafana"}} |
||||||
|
|
||||||
|
You're invited to join {{.OrgName}} |
||||||
|
|
||||||
|
You've been invited to join the {{.OrgName}} organization by {{.InvitedBy}}. To accept |
||||||
|
your invitation and join the team, copy and paste the link below into your browser |
||||||
|
directly: |
||||||
|
|
||||||
|
{{.LinkUrl}} |
||||||
|
|
||||||
|
Sent by Grafana v{{.BuildVersion}} (c) 2021 Grafana Labs |
@ -0,0 +1,41 @@ |
|||||||
|
{{Subject .Subject "{{.Title}}"}} |
||||||
|
|
||||||
|
{{.Title}} |
||||||
|
---------------- |
||||||
|
|
||||||
|
{{ .Alerts | len }} alert{{ if gt (len .Alerts) 1 }}s{{ end }} for |
||||||
|
{{ range .GroupLabels.SortedPairs }} |
||||||
|
{{ .Name }} = {{ .Value }} |
||||||
|
{{ end }} |
||||||
|
{{ if gt (len .Alerts.Firing) 0 }}({{ .Alerts.Firing | len }}) Firing{{ end }} |
||||||
|
{{ range .Alerts.Firing }} |
||||||
|
Labels: |
||||||
|
{{ range .Labels.SortedPairs }} |
||||||
|
{{ .Name }} = {{ .Value }} |
||||||
|
{{ end }} |
||||||
|
{{ if gt (len .Annotations) 0 }} |
||||||
|
Annotations: |
||||||
|
{{ end }} |
||||||
|
{{ range .Annotations.SortedPairs }} |
||||||
|
{{ .Name }} = {{ .Value }} |
||||||
|
{{ end }} |
||||||
|
{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}({{ .Alerts.Resolved | len }}) Resolved{{ end |
||||||
|
}} |
||||||
|
{{ range .Alerts.Resolved }} |
||||||
|
Labels: |
||||||
|
{{ range .Labels.SortedPairs }} |
||||||
|
{{ .Name }} = {{ .Value }} |
||||||
|
{{ end }} |
||||||
|
{{ if gt (len .Annotations) 0 }} |
||||||
|
Annotations: |
||||||
|
{{ end }} |
||||||
|
{{ range .Annotations.SortedPairs }} |
||||||
|
{{ .Name }} = {{ .Value }} |
||||||
|
{{ end }} |
||||||
|
{{ end }}View your Alert rule: |
||||||
|
{{.RuleUrl}} |
||||||
|
|
||||||
|
Go to the Alerts page: |
||||||
|
{{.AlertPageUrl}} |
||||||
|
|
||||||
|
Sent by Grafana v{{.BuildVersion}} (c) 2021 Grafana Labs |
@ -0,0 +1,9 @@ |
|||||||
|
{{Subject .Subject "Reset your Grafana password - {{.Name}}"}} |
||||||
|
|
||||||
|
Hi {{.Name}}, |
||||||
|
|
||||||
|
Copy and paste the following link directly in your browser to reset your password within |
||||||
|
{{.EmailCodeValidHours}} hours. |
||||||
|
{{.AppUrl}}user/password/reset?code={{.Code}} |
||||||
|
|
||||||
|
Sent by Grafana v{{.BuildVersion}} (c) 2021 Grafana Labs |
@ -0,0 +1,11 @@ |
|||||||
|
{{Subject .Subject "Welcome to Grafana, please complete your sign up!"}} |
||||||
|
|
||||||
|
Complete the signup |
||||||
|
|
||||||
|
Copy and paste the email verification code: |
||||||
|
{{.Code}} |
||||||
|
in the sign up form or use the link below. |
||||||
|
|
||||||
|
{{.SignUpUrl}} |
||||||
|
|
||||||
|
Sent by Grafana v{{.BuildVersion}} (c) 2021 Grafana Labs |
@ -0,0 +1,14 @@ |
|||||||
|
{{Subject .Subject "Welcome to Grafana"}} |
||||||
|
|
||||||
|
Hi {{.Name}}, |
||||||
|
|
||||||
|
Welcome! Ready to start building some beautiful metric and analytic dashboards? |
||||||
|
|
||||||
|
If you are new to Grafana, refer to the Getting started with Grafana guide on |
||||||
|
https://grafana.com/docs/grafana/latest/getting-started/getting-started/. |
||||||
|
|
||||||
|
Thank you for joining our community. |
||||||
|
|
||||||
|
The Grafana team |
||||||
|
|
||||||
|
Sent by Grafana v{{.BuildVersion}} (c) 2021 Grafana Labs |
Loading…
Reference in new issue