<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Configure notification messages on Grafana Labs</title><link>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/</link><description>Recent content in Configure notification messages on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/index.xml" rel="self" type="application/rss+xml"/><item><title>Using Go's templating language</title><link>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/using-go-templating-language/</link><pubDate>Tue, 21 May 2024 15:18:36 +0000</pubDate><guid>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/using-go-templating-language/</guid><content><![CDATA[&lt;h1 id=&#34;using-gos-templating-language&#34;&gt;Using Go&amp;rsquo;s templating language&lt;/h1&gt;
&lt;p&gt;You write notification templates in Go&amp;rsquo;s templating language, &lt;a href=&#34;https://pkg.go.dev/text/template&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;text/template&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Before you start creating your own notification templates, we recommend that you read through this topic, which provides you with an overview of Go&amp;rsquo;s templating language and writing templates in text/template.&lt;/p&gt;
&lt;h2 id=&#34;dot&#34;&gt;Dot&lt;/h2&gt;
&lt;p&gt;In text/template there is a special cursor called dot, and is written as &lt;code&gt;.&lt;/code&gt;. You can think of this cursor as a variable whose value changes depending where in the template it is used. For example, at the start of a notification template &lt;code&gt;.&lt;/code&gt; refers to something called 
    &lt;a href=&#34;/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/reference/#extendeddata&#34;&gt;&lt;code&gt;ExtendedData&lt;/code&gt;&lt;/a&gt; which contains a number of fields including &lt;code&gt;Alerts&lt;/code&gt;, &lt;code&gt;Status&lt;/code&gt;, &lt;code&gt;GroupLabels&lt;/code&gt;, &lt;code&gt;CommonLabels&lt;/code&gt;, &lt;code&gt;CommonAnnotations&lt;/code&gt; and &lt;code&gt;ExternalURL&lt;/code&gt;. However, dot might refer to something else when used in a range over a list, when used inside a &lt;code&gt;with&lt;/code&gt;, or when writing feature templates to be used in other templates. You can see examples of this in 
    &lt;a href=&#34;/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/create-notification-templates/&#34;&gt;Create notification templates&lt;/a&gt;, and all data and functions in the 
    &lt;a href=&#34;/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/reference/&#34;&gt;Reference&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;opening-and-closing-tags&#34;&gt;Opening and closing tags&lt;/h2&gt;
&lt;p&gt;In text/template, templates start with &lt;code&gt;{{&lt;/code&gt; and end with &lt;code&gt;}}&lt;/code&gt; irrespective of whether the template prints a variable or executes control structures such as if statements. This is different from other templating languages such as Jinja where printing a variable uses &lt;code&gt;{{&lt;/code&gt; and &lt;code&gt;}}&lt;/code&gt; and control structures use &lt;code&gt;{%&lt;/code&gt; and &lt;code&gt;%}&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;print&#34;&gt;Print&lt;/h2&gt;
&lt;p&gt;To print the value of something use &lt;code&gt;{{&lt;/code&gt; and &lt;code&gt;}}&lt;/code&gt;. You can print the value of dot, a field of dot, the result of a function, and the value of a &lt;a href=&#34;#variables&#34;&gt;variable&lt;/a&gt;. For example, to print the &lt;code&gt;Alerts&lt;/code&gt; field where dot refers to &lt;code&gt;ExtendedData&lt;/code&gt; you would write the following:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ .Alerts }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;iterate-over-alerts&#34;&gt;Iterate over alerts&lt;/h2&gt;
&lt;p&gt;To print just the labels of each alert, rather than all information about the alert, you can use a &lt;code&gt;range&lt;/code&gt; to iterate the alerts in &lt;code&gt;ExtendedData&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ range .Alerts }}
{{ .Labels }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Inside the range dot no longer refers to &lt;code&gt;ExtendedData&lt;/code&gt;, but to an &lt;code&gt;Alert&lt;/code&gt;. You can use &lt;code&gt;{{ .Labels }}&lt;/code&gt; to print the labels of each alert. This works because &lt;code&gt;{{ range .Alerts }}&lt;/code&gt; changes dot to refer to the current alert in the list of alerts. When the range is finished dot is reset to the value it had before the start of the range, which in this example is &lt;code&gt;ExtendedData&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ range .Alerts }}
{{ .Labels }}
{{ end }}
{{/* does not work, .Labels does not exist here */}}
{{ .Labels }}
{{/* works, cursor was reset */}}
{{ .Status }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;iterate-over-annotations-and-labels&#34;&gt;Iterate over annotations and labels&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s write a template to print the labels of each alert in the format &lt;code&gt;The name of the label is $name, and the value is $value&lt;/code&gt;, where &lt;code&gt;$name&lt;/code&gt; and &lt;code&gt;$value&lt;/code&gt; contain the name and value of each label.&lt;/p&gt;
&lt;p&gt;Like in the previous example, use a range to iterate over the alerts in &lt;code&gt;.Alerts&lt;/code&gt; such that dot refers to the current alert in the list of alerts, and then use a second range on the sorted labels so dot is updated a second time to refer to the current label. Inside the second range use &lt;code&gt;.Name&lt;/code&gt; and &lt;code&gt;.Value&lt;/code&gt; to print the name and value of each label:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ range .Alerts }}
{{ range .Labels.SortedPairs }}
The name of the label is {{ .Name }}, and the value is {{ .Value }}
{{ end }}
{{ range .Annotations.SortedPairs }}
The name of the annotation is {{ .Name }}, and the value is {{ .Value }}
{{ end }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;the-index-function&#34;&gt;The index function&lt;/h2&gt;
&lt;p&gt;To print a specific annotation or label use the &lt;code&gt;index&lt;/code&gt; function.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ range .Alerts }}
The name of the alert is {{ index .Labels &amp;#34;alertname&amp;#34; }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;if-statements&#34;&gt;If statements&lt;/h2&gt;
&lt;p&gt;You can use if statements in templates. For example, to print &lt;code&gt;There are no alerts&lt;/code&gt; if there are no alerts in &lt;code&gt;.Alerts&lt;/code&gt; you would write the following:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ if .Alerts }}
There are alerts
{{ else }}
There are no alerts
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;with&#34;&gt;With&lt;/h2&gt;
&lt;p&gt;With is similar to if statements, however unlike if statements, &lt;code&gt;with&lt;/code&gt; updates dot to refer to the value of the with:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ with .Alerts }}
There are {{ len . }} alert(s)
{{ else }}
There are no alerts
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;variables&#34;&gt;Variables&lt;/h2&gt;
&lt;p&gt;Variables in text/template must be created within the template. For example, to create a variable called &lt;code&gt;$variable&lt;/code&gt; with the current value of dot you would write the following:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ $variable := . }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can use &lt;code&gt;$variable&lt;/code&gt; inside a range or &lt;code&gt;with&lt;/code&gt; and it will refer to the value of dot at the time the variable was defined, not the current value of dot.&lt;/p&gt;
&lt;p&gt;For example, you cannot write a template that use &lt;code&gt;{{ .Labels }}&lt;/code&gt; in the second range because here dot refers to the current label, not the current alert:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ range .Alerts }}
{{ range .Labels.SortedPairs }}
{{ .Name }} = {{ .Value }}
{{/* does not work because in the second range . is a label not an alert */}}
There are {{ len .Labels }}
{{ end }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can fix this by defining a variable called &lt;code&gt;$alert&lt;/code&gt; in the first range and before the second range:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ range .Alerts }}
{{ $alert := . }}
{{ range .Labels.SortedPairs }}
{{ .Name }} = {{ .Value }}
{{/* works because $alert refers to the value of dot inside the first range */}}
There are {{ len $alert.Labels }}
{{ end }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;range-with-index&#34;&gt;Range with index&lt;/h2&gt;
&lt;p&gt;You can get the index of each alert within a range by defining index and value variables at the start of the range:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ $num_alerts := len .Alerts }}
{{ range $index, $alert := .Alerts }}
This is alert {{ $index }} out of {{ $num_alerts }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;define-templates&#34;&gt;Define templates&lt;/h2&gt;
&lt;p&gt;You can define templates using &lt;code&gt;define&lt;/code&gt; and the name of the template in double quotes. You should not define templates with the same name as other templates, including default templates such as &lt;code&gt;__subject&lt;/code&gt;, &lt;code&gt;__text_values_list&lt;/code&gt;, &lt;code&gt;__text_alert_list&lt;/code&gt;, &lt;code&gt;default.title&lt;/code&gt; and &lt;code&gt;default.message&lt;/code&gt;. Where a template has been created with the same name as a default template, or a template in another notification template, Grafana might use either template. Grafana does not prevent, or show an error message, when there are two or more templates with the same name.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ define &amp;#34;print_labels&amp;#34; }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;execute-templates&#34;&gt;Execute templates&lt;/h2&gt;
&lt;p&gt;You can execute defined templates using &lt;code&gt;template&lt;/code&gt;, the name of the template in double quotes, and the cursor that should be passed to the template:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;print_labels&amp;#34; . }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;pass-data-to-templates&#34;&gt;Pass data to templates&lt;/h2&gt;
&lt;p&gt;Within a template dot refers to the value that is passed to the template.&lt;/p&gt;
&lt;p&gt;For example, if a template is passed a list of firing alerts then dot refers to that list of firing alerts:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;print_alerts&amp;#34; .Alerts }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If the template is passed the sorted labels for an alert then dot refers to the list of sorted labels:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;print_labels&amp;#34; .SortedLabels }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This is useful when writing reusable templates. For example, to print all alerts you might write the following:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;print_alerts&amp;#34; .Alerts }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then to print just the firing alerts you could write this:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;print_alerts&amp;#34; .Alerts.Firing }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This works because both &lt;code&gt;.Alerts&lt;/code&gt; and &lt;code&gt;.Alerts.Firing&lt;/code&gt; is a list of alerts.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ define &amp;#34;print_alerts&amp;#34; }}
{{ range . }}
{{ template &amp;#34;print_labels&amp;#34; .SortedLabels }}
{{ end }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;p&gt;You can add comments with &lt;code&gt;{{/*&lt;/code&gt; and &lt;code&gt;*/}}&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{/* This is a comment */}}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To prevent comments from adding line breaks use:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{- /* This is a comment with no leading or trailing line breaks */ -}}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;indentation&#34;&gt;Indentation&lt;/h2&gt;
&lt;p&gt;You can use indentation, both tabs and spaces, and line breaks, to make templates more readable:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ range .Alerts }}
  {{ range .Labels.SortedPairs }}
    {{ .Name }} = {{ .Value }}
  {{ end }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;However, indentation in the template will also be present in the text. Next we will see how to remove it.&lt;/p&gt;
&lt;h2 id=&#34;remove-spaces-and-line-breaks&#34;&gt;Remove spaces and line breaks&lt;/h2&gt;
&lt;p&gt;In text/template use &lt;code&gt;{{-&lt;/code&gt; and &lt;code&gt;-}}&lt;/code&gt; to remove leading and trailing spaces and line breaks.&lt;/p&gt;
&lt;p&gt;For example, when using indentation and line breaks to make a template more readable:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ range .Alerts }}
  {{ range .Labels.SortedPairs }}
    {{ .Name }} = {{ .Value }}
  {{ end }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The indentation and line breaks will also be present in the text:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;    alertname = &amp;#34;Test&amp;#34;

    grafana_folder = &amp;#34;Test alerts&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can remove the indentation and line breaks from the text changing &lt;code&gt;}}&lt;/code&gt; to &lt;code&gt;-}}&lt;/code&gt; at the start of each range:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ range .Alerts -}}
  {{ range .Labels.SortedPairs -}}
    {{ .Name }} = {{ .Value }}
  {{ end }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The indentation and line breaks in the template are now absent from the text:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;alertname = &amp;#34;Test&amp;#34;
grafana_folder = &amp;#34;Test alerts&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="using-gos-templating-language">Using Go&amp;rsquo;s templating language&lt;/h1>
&lt;p>You write notification templates in Go&amp;rsquo;s templating language, &lt;a href="https://pkg.go.dev/text/template" target="_blank" rel="noopener noreferrer">text/template&lt;/a>.&lt;/p>
&lt;p>Before you start creating your own notification templates, we recommend that you read through this topic, which provides you with an overview of Go&amp;rsquo;s templating language and writing templates in text/template.&lt;/p></description></item><item><title>Create notification templates</title><link>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/create-notification-templates/</link><pubDate>Tue, 24 Sep 2024 07:09:39 +0000</pubDate><guid>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/create-notification-templates/</guid><content><![CDATA[&lt;h1 id=&#34;create-notification-templates&#34;&gt;Create notification templates&lt;/h1&gt;
&lt;p&gt;Create reusable notification templates to send to your contact points.&lt;/p&gt;
&lt;p&gt;You can add one or more templates to your notification template.&lt;/p&gt;
&lt;p&gt;Your notification template name must be unique. You cannot have two templates with the same name in the same notification template or in different notification templates. Avoid defining templates with the same name as default templates, such as: &lt;code&gt;__subject&lt;/code&gt;, &lt;code&gt;__text_values_list&lt;/code&gt;, &lt;code&gt;__text_alert_list&lt;/code&gt;, &lt;code&gt;default.title&lt;/code&gt; and &lt;code&gt;default.message&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To create a notification template, complete the following steps.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;Alerts &amp;amp; IRM&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Contact points&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click the &lt;strong&gt;Notification Templates&lt;/strong&gt; tab and then &lt;strong&gt;&#43; Add notification template&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter a name for the notification template.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Write the content of the template in the content field.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save your changes.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;code&gt;{{ define &amp;quot;email.subject&amp;quot; }}&lt;/code&gt; and &lt;code&gt;{{ end }}&lt;/code&gt; is automatically added to the start and end of the content:&lt;/p&gt;
&lt;p&gt;To create a notification template that contains more than one template:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;&#43; Add notification template&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter a name for the notification template.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Write each template in the Content field, including &lt;code&gt;{{ define &amp;quot;name-of-template&amp;quot; }}&lt;/code&gt; and &lt;code&gt;{{ end }}&lt;/code&gt; at the start and end of each template.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save your changes.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;preview-notification-templates&#34;&gt;Preview notification templates&lt;/h2&gt;
&lt;p&gt;Preview how your notification templates should look before using them in your contact points, helping you understand the result of the template you are creating as well as enabling you to fix any errors before saving it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This feature is only for Grafana Alertmanager.&lt;/p&gt;
&lt;p&gt;To preview your notification templates:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Navigate to &lt;strong&gt;Alerts&amp;amp;IRM&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Alerting&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Contact points&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Notification Templates&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;&#43; Add notification template&lt;/strong&gt; or edit an existing template.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add or update your template content.&lt;/p&gt;
&lt;p&gt;Default data is provided and you can add or edit alert data to it as well as alert instances. You can add alert data directly in the Payload data window itself or click &lt;strong&gt;Select alert instances&lt;/strong&gt; or &lt;strong&gt;Add custom alerts&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Optional: To add alert data from existing alert instances:&lt;/p&gt;
&lt;p&gt;a. Click &lt;strong&gt;Select alert instances&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;b. Hover over the alert instances to view more information on each alert instance.&lt;/p&gt;
&lt;p&gt;c. Click &lt;strong&gt;Confirm&lt;/strong&gt; to add the alert instance(s) to the payload.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Optional: To add alert data using the Alert data editor, click &lt;strong&gt;Add custom data:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;a. Add annotations, custom labels and/or set a dashboard or a panel.&lt;/p&gt;
&lt;p&gt;b. Toggle Firing/resolved depending on whether you want to add firing or resolved alerts to your notification.&lt;/p&gt;
&lt;p&gt;c. Click &lt;strong&gt;Add alert data&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;d. Click &lt;strong&gt;Refresh preview&lt;/strong&gt; to see what your template content should look like and the corresponding payload data.&lt;/p&gt;
&lt;p&gt;If there are any errors in your template, they are displayed in the Preview and you can correct them before saving.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save your changes.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;template-the-subject-of-an-email&#34;&gt;Template the subject of an email&lt;/h2&gt;
&lt;p&gt;Template the subject of an email to contain the number of firing and resolved alerts:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;1 firing alert(s), 0 resolved alerts(s)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a template called &lt;code&gt;email.subject&lt;/code&gt; with the following content:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ define &amp;#34;email.subject&amp;#34; }}
{{ len .Alerts.Firing }} firing alert(s), {{ len .Alerts.Resolved }} resolved alert(s)
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute the template from the subject field in your contact point integration:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;email.subject&amp;#34; . }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;template-the-message-of-an-email&#34;&gt;Template the message of an email&lt;/h2&gt;
&lt;p&gt;Template the message of an email to contain a summary of all firing and resolved alerts:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;There are 2 firing alert(s), and 1 resolved alert(s)

Firing alerts:

- alertname=Test 1 grafana_folder=GrafanaCloud has value(s) B=1
- alertname=Test 2 grafana_folder=GrafanaCloud has value(s) B=2

Resolved alerts:

- alertname=Test 3 grafana_folder=GrafanaCloud has value(s) B=0&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a notification template called &lt;code&gt;email&lt;/code&gt; with two templates in the content: &lt;code&gt;email.message_alert&lt;/code&gt; and &lt;code&gt;email.message&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;email.message_alert&lt;/code&gt; template is used to print the labels and values for each firing and resolved alert while the &lt;code&gt;email.message&lt;/code&gt; template contains the structure of the email.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{- define &amp;#34;email.message_alert&amp;#34; -}}
{{- range .Labels.SortedPairs }}{{ .Name }}={{ .Value }} {{ end }} has value(s)
{{- range $k, $v := .Values }} {{ $k }}={{ $v }}{{ end }}
{{- end -}}

{{ define &amp;#34;email.message&amp;#34; }}
There are {{ len .Alerts.Firing }} firing alert(s), and {{ len .Alerts.Resolved }} resolved alert(s)

{{ if .Alerts.Firing -}}
Firing alerts:
{{- range .Alerts.Firing }}
- {{ template &amp;#34;email.message_alert&amp;#34; . }}
{{- end }}
{{- end }}

{{ if .Alerts.Resolved -}}
Resolved alerts:
{{- range .Alerts.Resolved }}
- {{ template &amp;#34;email.message_alert&amp;#34; . }}
{{- end }}
{{- end }}

{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute the template from the message field in your contact point integration:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;email.message&amp;#34; . }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;group-multiple-alert-instances-into-one-email-notification&#34;&gt;Group multiple alert instances into one email notification&lt;/h2&gt;
&lt;p&gt;To make alerts more concise, you can group multiple instances of a firing alert into a single email notification in a table format. This way, you avoid long, repetitive emails and make alerts easier to digest.&lt;/p&gt;
&lt;p&gt;Follow these steps to create a custom notification template that consolidates alert instances into a table.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Modify the alert rule to include an annotation that is referenced in the notification template later on.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter a name for the &lt;strong&gt;custom annotation&lt;/strong&gt;: In this example, &lt;em&gt;ServerInfo&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter the following code as the value for the annotation. It retrieves the server&amp;rsquo;s instance name and a corresponding metric value, formatted as a table row:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ index $labels &amp;#34;instance&amp;#34; }}{{- &amp;#34;\t&amp;#34; -}}{{ index $values &amp;#34;A&amp;#34;}}{{- &amp;#34;\n&amp;#34; -}}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This line of code returns the labels and their values in the form of a table. Assuming $labels has &lt;code&gt;{&amp;quot;instance&amp;quot;: &amp;quot;node1&amp;quot;}&lt;/code&gt; and $values has &lt;code&gt;{&amp;quot;A&amp;quot;: &amp;quot;123&amp;quot;}&lt;/code&gt;, the output would be:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;node1    123&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a notification template that references the &lt;em&gt;ServerInfo&lt;/em&gt; annotation.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Go&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-go&#34;&gt;{{ define &amp;#34;Table&amp;#34; }}
{{- &amp;#34;\nHost\t\tValue\n&amp;#34; -}}
{{ range .Alerts -}}
{{ range .Annotations.SortedPairs -}}
{{ if (eq .Name  &amp;#34;ServerInfo&amp;#34;) -}}
{{ .Value -}}
{{- end }}
{{- end }}
{{- end }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The notification template outputs a list of server information from the &amp;ldquo;ServerInfo&amp;rdquo; annotation for each alert instance.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Navigate to your contact point in Grafana&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;strong&gt;Message&lt;/strong&gt; field, reference the template by name (see &lt;strong&gt;Optional Email settings&lt;/strong&gt; section):&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;Table&amp;#34; . }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This generates a neatly formatted table in the email, grouping information for all affected servers into a single notification.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;conditional-notification-template&#34;&gt;Conditional notification template&lt;/h2&gt;
&lt;p&gt;Template alert notifications based on a label. In this example the label represents a namespace.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Use the following code in your notification template to display different messages based on the namespace:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Go&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-go&#34;&gt;{{ define &amp;#34;my_conditional_notification&amp;#34; }}
{{ if eq .CommonLabels.namespace &amp;#34;namespace-a&amp;#34; }}
Alert: CPU limits have reached 80% in namespace-a.
{{ else if eq .CommonLabels.namespace &amp;#34;namespace-b&amp;#34; }}
Alert: CPU limits have reached 80% in namespace-b.
{{ else if eq .CommonLabels.namespace &amp;#34;namespace-c&amp;#34; }}
Alert: CPU limits have reached 80% in namespace-c.
{{ else }}
Alert: CPU limits have reached 80% for {{ .CommonLabels.namespace }} namespace.
{{ end }}
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;.CommonLabels&lt;/code&gt; is a map containing the labels that are common to all the alerts firing.&lt;/p&gt;
&lt;p&gt;Make sure to replace the &lt;code&gt;.namespace&lt;/code&gt; label with a label that exists in your alert rule.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Replace &lt;code&gt;namespace-a&lt;/code&gt;, &lt;code&gt;namespace-b&lt;/code&gt;, and &lt;code&gt;namespace-c&lt;/code&gt; with your specific namespace values.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Navigate to your contact point in Grafana&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;strong&gt;Message&lt;/strong&gt; field, reference the template by name (see &lt;strong&gt;Optional settings&lt;/strong&gt; section):&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;my_conditional_notification&amp;#34; . }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This template alters the content of alert notifications depending on the namespace value.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;template-the-title-of-a-slack-message&#34;&gt;Template the title of a Slack message&lt;/h2&gt;
&lt;p&gt;Template the title of a Slack message to contain the number of firing and resolved alerts:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;1 firing alert(s), 0 resolved alerts(s)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a template called &lt;code&gt;slack.title&lt;/code&gt; with the following content:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ define &amp;#34;slack.title&amp;#34; }}
{{ len .Alerts.Firing }} firing alert(s), {{ len .Alerts.Resolved }} resolved alert(s)
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute the template from the title field in your contact point integration:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;slack.title&amp;#34; . }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;template-the-content-of-a-slack-message&#34;&gt;Template the content of a Slack message&lt;/h2&gt;
&lt;p&gt;Template the content of a Slack message to contain a description of all firing and resolved alerts, including their labels, annotations, Silence URL and Dashboard URL.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This template is for Grafana-managed alerts only.
To use the template for Grafana Mimir/Loki-managed alerts, delete the references to DashboardURL and SilenceURL.
For more information, see the &lt;a href=&#34;https://prometheus.io/docs/alerting/latest/notifications/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Prometheus documentation on notifications&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;1 firing alert(s):

[firing] Test1
Labels:
- alertname: Test1
- grafana_folder: GrafanaCloud
Annotations:
- description: This is a test alert
Silence: https://example.com/alerting/silence/new?alertmanager=grafana&amp;amp;matcher=alertname%3DTest1&amp;amp;matcher=grafana_folder%3DGrafanaCloud
Go to dashboard: https://example.com/d/dlhdLqF4z?orgId=1

1 resolved alert(s):

[firing] Test2
Labels:
- alertname: Test2
- grafana_folder: GrafanaCloud
Annotations:
- description: This is another test alert
Silence: https://example.com/alerting/silence/new?alertmanager=grafana&amp;amp;matcher=alertname%3DTest2&amp;amp;matcher=grafana_folder%3DGrafanaCloud
Go to dashboard: https://example.com/d/dlhdLqF4z?orgId=1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a template called &lt;code&gt;slack&lt;/code&gt; with two templates in the content: &lt;code&gt;slack.print_alert&lt;/code&gt; and &lt;code&gt;slack.message&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;slack.print_alert&lt;/code&gt; template is used to print the labels, annotations, SilenceURL and DashboardURL while the &lt;code&gt;slack.message&lt;/code&gt; template contains the structure of the notification.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ define &amp;#34;slack.print_alert&amp;#34; -}}
[{{.Status}}] {{ .Labels.alertname }}
Labels:
{{ range .Labels.SortedPairs -}}
- {{ .Name }}: {{ .Value }}
{{ end -}}
{{ if .Annotations -}}
Annotations:
{{ range .Annotations.SortedPairs -}}
- {{ .Name }}: {{ .Value }}
{{ end -}}
{{ end -}}
{{ if .SilenceURL -}}
  Silence: {{ .SilenceURL }}
{{ end -}}
{{ if .DashboardURL -}}
  Go to dashboard: {{ .DashboardURL }}
{{- end }}
{{- end }}

{{ define &amp;#34;slack.message&amp;#34; -}}
{{ if .Alerts.Firing -}}
{{ len .Alerts.Firing }} firing alert(s):
{{ range .Alerts.Firing }}
{{ template &amp;#34;slack.print_alert&amp;#34; . }}
{{ end -}}
{{ end }}
{{ if .Alerts.Resolved -}}
{{ len .Alerts.Resolved }} resolved alert(s):
{{ range .Alerts.Resolved }}
{{ template &amp;#34;slack.print_alert&amp;#34; .}}
{{ end -}}
{{ end }}
{{- end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute the template from the text body field in your contact point integration:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;slack.message&amp;#34; . }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;template-both-email-and-slack-with-shared-templates&#34;&gt;Template both email and Slack with shared templates&lt;/h2&gt;
&lt;p&gt;Instead of creating separate notification templates for email and Slack, you can share the same template.&lt;/p&gt;
&lt;p&gt;For example, if you want to send an email with this subject and Slack message with this title:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;1 firing alert(s), 0 resolved alerts(s)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a template called &lt;code&gt;common.subject_title&lt;/code&gt; with the following content:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ define &amp;#34;common.subject_title&amp;#34; }}
{{ len .Alerts.Firing }} firing alert(s), {{ len .Alerts.Resolved }} resolved alert(s)
{{ end }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For email, execute the template from the subject field in your email contact point integration:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;common.subject_title&amp;#34; . }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For Slack, execute the template from the title field in your Slack contact point integration:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ template &amp;#34;common.subject_title&amp;#34; . }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
]]></content><description>&lt;h1 id="create-notification-templates">Create notification templates&lt;/h1>
&lt;p>Create reusable notification templates to send to your contact points.&lt;/p>
&lt;p>You can add one or more templates to your notification template.&lt;/p>
&lt;p>Your notification template name must be unique. You cannot have two templates with the same name in the same notification template or in different notification templates. Avoid defining templates with the same name as default templates, such as: &lt;code>__subject&lt;/code>, &lt;code>__text_values_list&lt;/code>, &lt;code>__text_alert_list&lt;/code>, &lt;code>default.title&lt;/code> and &lt;code>default.message&lt;/code>.&lt;/p></description></item><item><title>Use notification templates</title><link>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/use-notification-templates/</link><pubDate>Tue, 21 May 2024 15:18:36 +0000</pubDate><guid>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/use-notification-templates/</guid><content><![CDATA[&lt;h1 id=&#34;use-notification-templates&#34;&gt;Use notification templates&lt;/h1&gt;
&lt;p&gt;Use templates in contact points to customize your notifications.&lt;/p&gt;
&lt;p&gt;In the Contact points tab, you can see a list of your contact points.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;To create a new contact point, click New.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can edit an existing contact by clicking the Edit icon.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute a template from one or more fields such as Message and Subject:&lt;/p&gt;
&lt;figure
       class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
       style=&#34;max-width: 940px;&#34;
       itemprop=&#34;associatedMedia&#34;
       itemscope=&#34;&#34;
       itemtype=&#34;http://schema.org/ImageObject&#34;
     &gt;&lt;a
           class=&#34;lightbox-link captioned&#34;
           href=&#34;/static/img/docs/alerting/unified/use-notification-template-9-4.png&#34;
           itemprop=&#34;contentUrl&#34;
         &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
             class=&#34;lazyload mb-0&#34;
             data-src=&#34;/static/img/docs/alerting/unified/use-notification-template-9-4.png&#34;data-srcset=&#34;/static/img/docs/alerting/unified/use-notification-template-9-4.png?w=320 320w, /static/img/docs/alerting/unified/use-notification-template-9-4.png?w=550 550w, /static/img/docs/alerting/unified/use-notification-template-9-4.png?w=750 750w, /static/img/docs/alerting/unified/use-notification-template-9-4.png?w=900 900w, /static/img/docs/alerting/unified/use-notification-template-9-4.png?w=1040 1040w, /static/img/docs/alerting/unified/use-notification-template-9-4.png?w=1240 1240w, /static/img/docs/alerting/unified/use-notification-template-9-4.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Use notification template&#34;width=&#34;2360&#34;height=&#34;1236&#34;title=&#34;Use notification template&#34;/&gt;
           &lt;noscript&gt;
             &lt;img
               src=&#34;/static/img/docs/alerting/unified/use-notification-template-9-4.png&#34;
               alt=&#34;Use notification template&#34;width=&#34;2360&#34;height=&#34;1236&#34;title=&#34;Use notification template&#34;/&gt;
           &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;Use notification template&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;For more information on how to write and execute templates, refer to 
    &lt;a href=&#34;/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/using-go-templating-language/&#34;&gt;Using Go&amp;rsquo;s templating language&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/create-notification-templates/&#34;&gt;Create notification templates&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;Save contact point&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
]]></content><description>&lt;h1 id="use-notification-templates">Use notification templates&lt;/h1>
&lt;p>Use templates in contact points to customize your notifications.&lt;/p>
&lt;p>In the Contact points tab, you can see a list of your contact points.&lt;/p></description></item><item><title>Reference</title><link>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/reference/</link><pubDate>Tue, 26 Mar 2024 12:30:09 +0000</pubDate><guid>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/reference/</guid><content><![CDATA[&lt;h1 id=&#34;reference&#34;&gt;Reference&lt;/h1&gt;
&lt;h2 id=&#34;data&#34;&gt;Data&lt;/h2&gt;
&lt;h3 id=&#34;alert&#34;&gt;Alert&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Kind&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Example&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Status&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Firing or resolved&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Status }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Labels&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;KV&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The labels for this alert&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Labels }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Annotations&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;KV&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The annotations for this alert&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Annotations }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Values&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;KV&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The values of all expressions, including Classic Conditions&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Values }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;StartsAt&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;Time&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The time the alert fired&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .StartsAt }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;EndsAt&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;Time&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .EndsAt }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;GeneratorURL&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A link to Grafana, or the Alertmanager if using an external Alertmanager&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .GeneratorURL }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;SilenceURL&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A link to silence the alert&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .SilenceURL }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;DashboardURL&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A link to the Grafana Dashboard if the alert has a Dashboard UID annotation&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .DashboardURL }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;PanelURL&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A link to the panel if the alert has a Panel ID annotation&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .PanelURL }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Fingerprint&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A unique string that identifies the alert&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Fingerprint }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;ValueString&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A string that contains the labels and value of each reduced expression in the alert.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .ValueString }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;extendeddata&#34;&gt;ExtendedData&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Kind&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Example&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Receiver&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The name of the contact point sending the notification&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Receiver }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Status&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The status is &lt;code&gt;firing&lt;/code&gt; if at least one alert is firing, otherwise &lt;code&gt;resolved&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Status }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Alerts&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;[]Alert&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;List of all firing and resolved alerts in this notification&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;There are {{ len .Alerts }} alerts&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Firing alerts&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;[]Alert&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;List of all firing alerts in this notification&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;There are {{ len .Alerts.Firing }} firing alerts&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Resolved alerts&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;[]Alert&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;List of all resolved alerts in this notification&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;There are {{ len .Alerts.Resolved }} resolved alerts&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;GroupLabels&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;KV&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The labels that group these alerts in this&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .GroupLabels }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;CommonLabels&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;KV&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The labels common to all alerts in this notification&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .CommonLabels }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;CommonAnnotations&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;KV&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The annotations common to all alerts in this notification&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .CommonAnnotations }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;ExternalURL&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A link to Grafana, or the Alertmanager that sent this notification if using an external Alertmanager&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .ExternalURL }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;kv&#34;&gt;KV&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;KV&lt;/code&gt; is a set of key value pairs, where each key and value is a string. If a KV happens to contain numbers or bools then these are string representations of the numeric or boolean value.&lt;/p&gt;
&lt;p&gt;Here is an example of a KV, the annotations of an alert:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;summary: &amp;#39;A summary of the alert&amp;#39;
description: &amp;#39;A description of the alert&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In addition to iterating over each key value pair, you can sort the pairs, remove keys, and iterate over just the keys or the values.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Arguments&lt;/th&gt;
              &lt;th&gt;Returns&lt;/th&gt;
              &lt;th&gt;Example&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;SortedPairs&lt;/td&gt;
              &lt;td&gt;Sorts&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Annotations.SortedPairs }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Remove&lt;/td&gt;
              &lt;td&gt;Returns a copy of the KV with the keys removed&lt;/td&gt;
              &lt;td&gt;[]string&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Annotations.Remove &amp;quot;summary&amp;quot; }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Names&lt;/td&gt;
              &lt;td&gt;A list of the names&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Names }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Values&lt;/td&gt;
              &lt;td&gt;A list of the values&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{ .Values }}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;time&#34;&gt;Time&lt;/h3&gt;
&lt;p&gt;Time is from the Go &lt;a href=&#34;https://pkg.go.dev/time#Time&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&lt;code&gt;time&lt;/code&gt;&lt;/a&gt; package. You can print a time in a number of different formats. For example, to print the time that an alert fired in the format &lt;code&gt;Monday, 1st January 2022 at 10:00AM&lt;/code&gt; you would write the following template:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{{ .StartsAt.Format &amp;#34;Monday, 2 January 2006 at 3:04PM&amp;#34; }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can find a reference for Go&amp;rsquo;s time format &lt;a href=&#34;https://pkg.go.dev/time#pkg-constants&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="reference">Reference&lt;/h1>
&lt;h2 id="data">Data&lt;/h2>
&lt;h3 id="alert">Alert&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Name&lt;/th>
&lt;th>Kind&lt;/th>
&lt;th>Description&lt;/th>
&lt;th>Example&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Status&lt;/td>
&lt;td>&lt;code>string&lt;/code>&lt;/td>
&lt;td>Firing or resolved&lt;/td>
&lt;td>&lt;code>{{ .Status }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Labels&lt;/td>
&lt;td>&lt;code>KV&lt;/code>&lt;/td>
&lt;td>The labels for this alert&lt;/td>
&lt;td>&lt;code>{{ .Labels }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Annotations&lt;/td>
&lt;td>&lt;code>KV&lt;/code>&lt;/td>
&lt;td>The annotations for this alert&lt;/td>
&lt;td>&lt;code>{{ .Annotations }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Values&lt;/td>
&lt;td>&lt;code>KV&lt;/code>&lt;/td>
&lt;td>The values of all expressions, including Classic Conditions&lt;/td>
&lt;td>&lt;code>{{ .Values }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>StartsAt&lt;/td>
&lt;td>&lt;code>Time&lt;/code>&lt;/td>
&lt;td>The time the alert fired&lt;/td>
&lt;td>&lt;code>{{ .StartsAt }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>EndsAt&lt;/td>
&lt;td>&lt;code>Time&lt;/code>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;code>{{ .EndsAt }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>GeneratorURL&lt;/td>
&lt;td>&lt;code>string&lt;/code>&lt;/td>
&lt;td>A link to Grafana, or the Alertmanager if using an external Alertmanager&lt;/td>
&lt;td>&lt;code>{{ .GeneratorURL }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>SilenceURL&lt;/td>
&lt;td>&lt;code>string&lt;/code>&lt;/td>
&lt;td>A link to silence the alert&lt;/td>
&lt;td>&lt;code>{{ .SilenceURL }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>DashboardURL&lt;/td>
&lt;td>&lt;code>string&lt;/code>&lt;/td>
&lt;td>A link to the Grafana Dashboard if the alert has a Dashboard UID annotation&lt;/td>
&lt;td>&lt;code>{{ .DashboardURL }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>PanelURL&lt;/td>
&lt;td>&lt;code>string&lt;/code>&lt;/td>
&lt;td>A link to the panel if the alert has a Panel ID annotation&lt;/td>
&lt;td>&lt;code>{{ .PanelURL }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Fingerprint&lt;/td>
&lt;td>&lt;code>string&lt;/code>&lt;/td>
&lt;td>A unique string that identifies the alert&lt;/td>
&lt;td>&lt;code>{{ .Fingerprint }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ValueString&lt;/td>
&lt;td>&lt;code>string&lt;/code>&lt;/td>
&lt;td>A string that contains the labels and value of each reduced expression in the alert.&lt;/td>
&lt;td>&lt;code>{{ .ValueString }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="extendeddata">ExtendedData&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Name&lt;/th>
&lt;th>Kind&lt;/th>
&lt;th>Description&lt;/th>
&lt;th>Example&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Receiver&lt;/td>
&lt;td>&lt;code>string&lt;/code>&lt;/td>
&lt;td>The name of the contact point sending the notification&lt;/td>
&lt;td>&lt;code>{{ .Receiver }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Status&lt;/td>
&lt;td>&lt;code>string&lt;/code>&lt;/td>
&lt;td>The status is &lt;code>firing&lt;/code> if at least one alert is firing, otherwise &lt;code>resolved&lt;/code>&lt;/td>
&lt;td>&lt;code>{{ .Status }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Alerts&lt;/td>
&lt;td>&lt;code>[]Alert&lt;/code>&lt;/td>
&lt;td>List of all firing and resolved alerts in this notification&lt;/td>
&lt;td>&lt;code>There are {{ len .Alerts }} alerts&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Firing alerts&lt;/td>
&lt;td>&lt;code>[]Alert&lt;/code>&lt;/td>
&lt;td>List of all firing alerts in this notification&lt;/td>
&lt;td>&lt;code>There are {{ len .Alerts.Firing }} firing alerts&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Resolved alerts&lt;/td>
&lt;td>&lt;code>[]Alert&lt;/code>&lt;/td>
&lt;td>List of all resolved alerts in this notification&lt;/td>
&lt;td>&lt;code>There are {{ len .Alerts.Resolved }} resolved alerts&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>GroupLabels&lt;/td>
&lt;td>&lt;code>KV&lt;/code>&lt;/td>
&lt;td>The labels that group these alerts in this&lt;/td>
&lt;td>&lt;code>{{ .GroupLabels }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>CommonLabels&lt;/td>
&lt;td>&lt;code>KV&lt;/code>&lt;/td>
&lt;td>The labels common to all alerts in this notification&lt;/td>
&lt;td>&lt;code>{{ .CommonLabels }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>CommonAnnotations&lt;/td>
&lt;td>&lt;code>KV&lt;/code>&lt;/td>
&lt;td>The annotations common to all alerts in this notification&lt;/td>
&lt;td>&lt;code>{{ .CommonAnnotations }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ExternalURL&lt;/td>
&lt;td>&lt;code>string&lt;/code>&lt;/td>
&lt;td>A link to Grafana, or the Alertmanager that sent this notification if using an external Alertmanager&lt;/td>
&lt;td>&lt;code>{{ .ExternalURL }}&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="kv">KV&lt;/h3>
&lt;p>&lt;code>KV&lt;/code> is a set of key value pairs, where each key and value is a string. If a KV happens to contain numbers or bools then these are string representations of the numeric or boolean value.&lt;/p></description></item><item><title>Use images in notifications</title><link>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/images-in-notifications/</link><pubDate>Tue, 26 Mar 2024 12:30:09 +0000</pubDate><guid>https://grafana.com/docs/grafana/v11.0/alerting/configure-notifications/template-notifications/images-in-notifications/</guid><content><![CDATA[&lt;h1 id=&#34;use-images-in-notifications&#34;&gt;Use images in notifications&lt;/h1&gt;
&lt;p&gt;Images in notifications helps recipients of alert notifications better understand why an alert has fired or resolved by including a screenshot of the panel associated with the alert.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This feature is not supported in Mimir or Loki, or when Grafana is configured to send alerts to other Alertmanagers such as the Prometheus Alertmanager&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;When an alert is fired or resolved Grafana takes a screenshot of the panel associated with the alert. This is determined via the Dashboard UID and Panel ID annotations of the rule. Grafana cannot take a screenshot for alerts that are not associated with a panel.&lt;/p&gt;
&lt;p&gt;Grafana takes at most two screenshots for each alert: once when the alert fires and again when the alert is resolved. Screenshots are not re-taken over the lifetime of the alert, instead you should open the panel in Grafana to follow the data in real time. In addition, depending on how alerts are grouped in your notification policies, Grafana might send a notification with many screenshots of the same panel. This happens because Grafana does not know how your alerts are grouped at the time a screenshot is taken, and so acts conservatively by taking a screenshot for every alert.&lt;/p&gt;
&lt;p&gt;Once a screenshot has been taken Grafana can either upload it to a cloud storage service such as Amazon S3, Azure Blob Storage or Google Cloud Storage; upload the screenshot to it&amp;rsquo;s internal web server; or upload it to the service that is receiving the notification, such as Slack. Which option you should choose depends on how your Grafana is managed and which integrations you use. More information on this can be found in Requirements.&lt;/p&gt;
&lt;p&gt;Refer to the table at the end of this page for a list of contact points and their support for images in notifications.&lt;/p&gt;
&lt;h2 id=&#34;requirements&#34;&gt;Requirements&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;To use images in notifications, Grafana must be set up to use image rendering. You can either install the image rendering plugin or run it as a remote rendering service.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When a screenshot is taken it is saved to the [data][paths] folder, even if Grafana is configured to upload screenshots to a cloud storage service. Grafana must have write-access to this folder otherwise screenshots cannot be saved to disk and an error will be logged for each failed screenshot attempt.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You should use a cloud storage service unless sending alerts to Discord, Email, Pushover, Slack or Telegram. These integrations support either embedding screenshots in the email or attaching screenshots to the notification, while other integrations must link screenshots uploaded to a cloud storage bucket. If a cloud storage service has been configured then integrations that support both will link screenshots from the cloud storage bucket instead of embedding or attaching screenshots to the notification.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If uploading screenshots to a cloud storage service such as Amazon S3, Azure Blob Storage or Google Cloud Storage; and accessing screenshots in the bucket requires authentication, logging into a VPN or corporate network; then image previews might not work in all instant messaging and communication platforms as some services rewrite URLs to use their CDN. If this happens we recommend using &lt;a href=&#34;#supported-contact-points&#34;&gt;integrations which support uploading images&lt;/a&gt; or &lt;a href=&#34;#configuration&#34;&gt;disabling images in notifications&lt;/a&gt; altogether.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When uploading screenshots to a cloud storage service Grafana uses a random 20 character (30 characters for Azure Blob Storage) filename for each image. This makes URLs hard to guess but not impossible.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grafana does not delete screenshots from cloud storage. We recommend configuring a retention policy with your cloud storage service to delete screenshots older than 1 month.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If Grafana is configured to upload screenshots to its internal web server, and accessing Grafana requires logging into a VPN or corporate network; image previews might not work in all instant messaging and communication platforms as some services rewrite URLs to use their CDN. If this happens we recommend using &lt;a href=&#34;#supported-contact-points&#34;&gt;integrations which support uploading images&lt;/a&gt; or &lt;a href=&#34;#configuration&#34;&gt;disabling images in notifications&lt;/a&gt; altogether.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grafana does not delete screenshots uploaded to its internal web server. To delete screenshots from &lt;code&gt;static_root_path/images/attachments&lt;/code&gt; after a certain amount of time we recommend setting up a CRON job.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;configuration&#34;&gt;Configuration&lt;/h2&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Grafana Cloud users can request this feature by &lt;a href=&#34;/profile/org#support&#34;&gt;opening a support ticket in the Cloud Portal&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Having installed either the image rendering plugin, or set up Grafana to use a remote rendering service, set &lt;code&gt;capture&lt;/code&gt; in &lt;code&gt;[unified_alerting.screenshots]&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Enable screenshots in notifications. You must have either installed the Grafana image rendering
# plugin, or set up Grafana to use a remote rendering service.
# For more information on configuration options, refer to [rendering].
capture = false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If screenshots should be uploaded to cloud storage then &lt;code&gt;upload_external_image_storage&lt;/code&gt; should also be set to &lt;code&gt;true&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Uploads screenshots to the local Grafana server or remote storage such as Azure, S3 and GCS. Please
# see [external_image_storage] for further configuration options. If this option is false, screenshots
# will be persisted to disk for up to temp_data_lifetime.
upload_external_image_storage = false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Restart Grafana for the changes to take effect.&lt;/p&gt;
&lt;h2 id=&#34;advanced-configuration&#34;&gt;Advanced configuration&lt;/h2&gt;
&lt;p&gt;We recommended that &lt;code&gt;max_concurrent_screenshots&lt;/code&gt; is less than or equal to &lt;code&gt;concurrent_render_request_limit&lt;/code&gt;. The default value for both &lt;code&gt;max_concurrent_screenshots&lt;/code&gt; and &lt;code&gt;concurrent_render_request_limit&lt;/code&gt; is &lt;code&gt;5&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# The maximum number of screenshots that can be taken at the same time. This option is different from
# concurrent_render_request_limit as max_concurrent_screenshots sets the number of concurrent screenshots
# that can be taken at the same time for all firing alerts where as concurrent_render_request_limit sets
# the total number of concurrent screenshots across all Grafana services.
max_concurrent_screenshots = 5
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&#34;supported-contact-points&#34;&gt;Supported contact points&lt;/h2&gt;
&lt;p&gt;Grafana supports a wide range of contact points with varied support for images in notifications. The table below shows the list of all contact points supported in Grafana and their support for uploading screenshots to the receiving service and referencing screenshots that have been uploaded to a cloud storage service.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Upload from disk&lt;/th&gt;
              &lt;th&gt;Reference from cloud storage&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;DingDing&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Discord&lt;/td&gt;
              &lt;td&gt;Yes (Maximum of 10 per notification)&lt;/td&gt;
              &lt;td&gt;Yes (Maximum of 10 per notification)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Email&lt;/td&gt;
              &lt;td&gt;Yes (Embedded in the email)&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Google Chat&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Kafka&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Line&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Microsoft Teams&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Opsgenie&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Pagerduty&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Prometheus Alertmanager&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Pushover&lt;/td&gt;
              &lt;td&gt;Yes (Maximum of 1 per notification)&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Sensu Go&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Slack&lt;/td&gt;
              &lt;td&gt;Yes (when using Bot tokens, maximum of 5 per notification)&lt;/td&gt;
              &lt;td&gt;Yes (when using webhooks, maximum of 1 per notification)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Telegram&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Threema&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;VictorOps&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Webhook&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;limitations&#34;&gt;Limitations&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;This feature is not supported in Mimir or Loki, or when Grafana is configured to send alerts to other Alertmanagers such as the Prometheus Alertmanager.&lt;/li&gt;
&lt;li&gt;A number of contact points support at most one image per notification. In this case, just the first image is either uploaded to the receiving service or referenced from cloud storage per notification.&lt;/li&gt;
&lt;li&gt;When multiple alerts are sent in a single notification a screenshot might be included for each alert. The order the images are shown is random.&lt;/li&gt;
&lt;li&gt;If uploading screenshots to a cloud storage service such as Amazon S3, Azure Blob Storage or Google Cloud Storage; and accessing screenshots in the bucket requires authentication, logging into a VPN or corporate network; image previews might not work in all instant messaging and communication platforms as some services rewrite URLs to use their CDN.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;troubleshooting&#34;&gt;Troubleshooting&lt;/h2&gt;
&lt;p&gt;If Grafana has been set up to send images in notifications, however notifications are still being received without them, follow the troubleshooting steps below:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check that images in notifications has been set up as per the instructions.&lt;/li&gt;
&lt;li&gt;Enable debug logging in Grafana and look for logs with the logger &lt;code&gt;ngalert.image&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If the alert is not associated with a dashboard there will be logs for &lt;code&gt;Cannot take screenshot for alert rule as it is not associated with a dashboard&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If the alert is associated with a dashboard, but no panel in the dashboard, there will be logs for &lt;code&gt;Cannot take screenshot for alert rule as it is not associated with a panel&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If images cannot be taken because of mis-configuration or an issue with image rendering there will be logs for &lt;code&gt;Failed to take an image&lt;/code&gt; including the Dashboard UID, Panel ID, and the error message.&lt;/li&gt;
&lt;li&gt;Check that the contact point supports images in notifications and whether it supports uploading images to the receiving service or referencing images that have been uploaded to a cloud storage service.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;metrics&#34;&gt;Metrics&lt;/h2&gt;
&lt;p&gt;Grafana provides the following metrics to observe the performance and failure rate of images in notifications.
For example, if a screenshot could not be taken within the expected time (10 seconds) then the counter &lt;code&gt;grafana_screenshot_failures_total&lt;/code&gt; is updated.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;grafana_alerting_image_cache_hits_total&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grafana_alerting_image_cache_misses_total&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grafana_screenshot_duration_seconds&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grafana_screenshot_failures_total&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grafana_screenshot_successes_total&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grafana_screenshot_upload_failures_total&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grafana_screenshot_upload_successes_total&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="use-images-in-notifications">Use images in notifications&lt;/h1>
&lt;p>Images in notifications helps recipients of alert notifications better understand why an alert has fired or resolved by including a screenshot of the panel associated with the alert.&lt;/p></description></item></channel></rss>