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>
This commit is contained in:
Djairho Geuens
2021-07-19 12:31:51 +02:00
committed by GitHub
parent cec12676e7
commit 4cadbba686
41 changed files with 408 additions and 58 deletions

View File

@@ -6,10 +6,9 @@
## Tasks
- npm run build (default task will build new inlines email templates)
- npm start (will build on source html or css change)
- npm start (builds on source HTML, text, or CSS change)
## Result
Assembled email templates will be in `dist/` and final
inlined templates will be in `../public/emails/`

View File

@@ -2,15 +2,25 @@ module.exports = function () {
'use strict';
return {
options: {
layout: 'templates/layouts/default.html',
partials: ['templates/partials/*.hbs'],
helpers: ['templates/helpers/**/*.js'],
data: [],
flatten: true,
},
pages: {
html: {
options: {
layout: 'templates/layouts/default.html',
},
src: ['templates/*.html'],
dest: 'dist/',
},
txt: {
options: {
layout: 'templates/layouts/default.txt',
ext: '.txt',
},
src: ['templates/*.txt'],
dest: 'dist/',
},
};
};

View File

@@ -1,5 +1,5 @@
module.exports = {
main: {
html: {
options: {
verbose: true,
removeComments: true,
@@ -13,4 +13,19 @@ module.exports = {
},
],
},
txt: {
options: {
verbose: true,
mode: 'txt',
lineLength: 90,
},
files: [
{
expand: true, // Enable dynamic expansion.
cwd: 'dist', // Src matches are relative to this path.
src: ['*.txt'], // Actual patterns to match.
dest: '../public/emails/', // Destination path prefix.
},
],
},
};

View File

@@ -1,7 +1,7 @@
module.exports = {
dist: {
overwrite: true,
src: ['dist/*.html'],
src: ['dist/*.html', 'dist/*.txt'],
replacements: [
{
from: '[[',

View File

@@ -4,6 +4,7 @@ module.exports = {
//what are the files that we want to watch
'assets/css/*.css',
'templates/**/*.html',
'templates/**/*.txt',
'grunt/*.js',
],
tasks: ['default'],

View File

@@ -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]]

View File

@@ -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]]

View File

@@ -0,0 +1,3 @@
{{> body }}
Sent by Grafana v[[.BuildVersion]] (c) 2021 Grafana Labs

View File

@@ -39,7 +39,7 @@
</tr>
<tr>
<td class="center">
<p>You can also copy/paste this link into your browser directly: <a href="[[.LinkUrl]]">[[.LinkUrl]]</a></p>
<p>You can also copy and paste this link into your browser directly: <a href="[[.LinkUrl]]">[[.LinkUrl]]</a></p>
</td>
<td class="expander"></td>
</tr>

View File

@@ -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]]

View File

@@ -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]]

View File

@@ -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]]

View File

@@ -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]]

View File

@@ -29,7 +29,7 @@
<tr>
<td class="center">
<p>
If you are new to Grafana please read the <a href="https://grafana.com/docs/grafana/latest/getting-started/getting-started/">Getting Started</a> guide.
If you are new to Grafana, refer to the <a href="https://grafana.com/docs/grafana/latest/getting-started/getting-started/">Getting started with Grafana</a> guide.
</p>
</td>
<td class="expander"></td>

View File

@@ -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