# Documentation of Alert Templating in Serious Need of Improvement!

**URL:** <https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083>\
**Category:** Alerting\
**Tags:** templating, format, alerting\
**Created:** [November 15, 2022, 4:34pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083 "2022-11-15T16:34:44Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [November 29, 2022, 6:14pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/22 "2022-11-29T18:14:26Z")

</div>

Hey

could you please show us the actual emoji you used in your alert code?

---

<div class="post-metadata">

**Author:** ![naresh9999](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@naresh9999](https://community.grafana.com/u/naresh9999)\
**Post date:** [November 29, 2022, 6:19pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/23 "2022-11-29T18:19:25Z")

</div>

Hi @yosiasz

I used like below.

{{ range .Alerts }} ⚠PMM | {{ .Labels.severity}} | {{ .Labels.node\_name}} | {{ .Annotations.summary }}

---

<div class="post-metadata">

**Author:** ![naresh9999](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@naresh9999](https://community.grafana.com/u/naresh9999)\
**Post date:** [November 30, 2022, 7:28am UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/24 "2022-11-30T07:28:24Z")

</div>

Hi @yosiasz

Is it correct way I am using the emoji or any changes needed to get actual emoji color in the mail subject?

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [November 30, 2022, 8:25am UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/25 "2022-11-30T08:25:30Z")

</div>

Honestly I am not sure. one way it to try things by process of elimination. try to send alerts to something else like slack or teams or telegram

If it does not function well in these then it could be grafana alerts itself.

---

<div class="post-metadata">

**Author:** ![naresh9999](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@naresh9999](https://community.grafana.com/u/naresh9999)\
**Post date:** [November 30, 2022, 2:26pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/26 "2022-11-30T14:26:01Z")

</div>

Sure @yosiasz

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![gregbeyer](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/gregbeyer/32/15514_2.png) [@gregbeyer](https://community.grafana.com/u/gregbeyer)\
**Post date:** [November 30, 2022, 8:52pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/27 "2022-11-30T20:52:50Z")

</div>

Hello @simpres99, and thank you for hearing us. Regarding collecting feedback on the documentation, that sounds like a great idea – instead of you having to hunt through dozens of posts. Please let us know how you would like us to provide what you need. Perhaps a dedicated forum under Alerting? However we can help, we will.

---

<div class="post-metadata">

**Author:** ![gregbeyer](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/gregbeyer/32/15514_2.png) [@gregbeyer](https://community.grafana.com/u/gregbeyer)\
**Post date:** [November 30, 2022, 8:54pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/28 "2022-11-30T20:54:23Z")

</div>

Oops, DM’d the wrong person. @georgerobinson, pls see above.

---

<div class="post-metadata">

**Author:** ![naresh9999](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@naresh9999](https://community.grafana.com/u/naresh9999)\
**Post date:** [December 4, 2022, 5:17pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/29 "2022-12-04T17:17:20Z")

</div>

Hi @georgerobinson

How can I get Label values in the new line?

{{ define “email.body” }}

{{- range .Alerts -}}

{{ if gt (len .Annotations) 0 }}

_Summary_: {{ .Annotations.summary }}

_Description_: {{ .Annotations.description }}

Labels:

{{ range .Labels.SortedPairs }} {{ if or (eq .Name “ENV”) (eq .Name “APP\_TYPE”) }} • _{{ .Name }}_: {{ .Value }}

{{ end }}{{ end }}

{{ end }}

{{ end }}

{{ end }}

I am using the above code but I am getting the output like this.

_Summary_: MariaDB Repl Lag is 4104 Secs Behind for C-DEV4-RO _Description_: MariaDB Slave is Lagging Behind Of 4104 Seconds From [http://test402.test.com](http://test402.test.com) to test404: C-DEV4-RO Labels: • _APP\_TYPE_: DEV\_ALL\_TRACKS • _ENV_: C-STACK-DEV

But I want output like below.

_Summary_: MariaDB Repl Lag is 4104 Secs Behind for C-DEV4-RO  
_Description_: MariaDB Slave is Lagging Behind Of 4104 Seconds From [http://test402.test.com](http://test402.test.com) to test404: C-DEV4-RO  
Labels:  
•_APP\_TYPE_: DEV\_ALL\_TRACKS  
• _ENV_: C-STACK-DEV

---

<div class="post-metadata">

**Author:** ![naresh9999](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@naresh9999](https://community.grafana.com/u/naresh9999)\
**Post date:** [December 9, 2022, 4:09pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/30 "2022-12-09T16:09:06Z")

</div>

@georgerobinson Can you please help me on the above?

---

<div class="post-metadata">

**Author:** ![georgerobinson](https://avatars.discourse-cdn.com/v4/letter/g/ad7895/32.png) [@georgerobinson](https://community.grafana.com/u/georgerobinson)\
**Post date:** [December 9, 2022, 4:26pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/31 "2022-12-09T16:26:00Z")

</div>

Hi! What about the something like this?

```auto
Labels:
{{ range .Labels.SortedPairs }}{{ if or (eq .Name "foo") (eq .Name "bar") -}}
- {{ .Name }}: {{ .Value }}
{{ end }}{{ end }}

```

![Screenshot 2022-12-09 at 16.25.42](https://us1.discourse-cdn.com/grafana/original/3X/2/d/2d071fcb1b9060690108e28c9bb2c0c57844512f.png)

---

<div class="post-metadata">

**Author:** ![naresh9999](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@naresh9999](https://community.grafana.com/u/naresh9999)\
**Post date:** [December 9, 2022, 4:27pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/32 "2022-12-09T16:27:54Z")

</div>

@georgerobinson Yeah this looks good, let me try and update you on the same.

---

<div class="post-metadata">

**Author:** ![naresh9999](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@naresh9999](https://community.grafana.com/u/naresh9999)\
**Post date:** [December 9, 2022, 5:03pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/33 "2022-12-09T17:03:34Z")

</div>

@georgerobinson Still I am not getting the same issue?

{{ define “email.body” }}

{{- range .Alerts -}}

{{ if gt (len .Annotations) 0 }}

Summary: {{ .Annotations.summary }}

Description: {{ .Annotations.description }}

Labels:

{{ range .Labels.SortedPairs }} {{ if or (eq .Name “ENV”) (eq .Name “APP\_TYPE”) -}} - {{ .Name }}: {{ .Value }}

{{ end }}{{ end }}

{{ end }}

{{ end }}

{{ end }}

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/1/4/1493bb49940e931654bd282baf58289c70b8932f.png)

---

<div class="post-metadata">

**Author:** ![georgerobinson](https://avatars.discourse-cdn.com/v4/letter/g/ad7895/32.png) [@georgerobinson](https://community.grafana.com/u/georgerobinson)\
**Post date:** [December 9, 2022, 5:09pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/34 "2022-12-09T17:09:06Z")

</div>

Hi! What email client is this?

---

<div class="post-metadata">

**Author:** ![thopewell](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@thopewell](https://community.grafana.com/u/thopewell)\
**Post date:** [December 9, 2022, 9:59pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/35 "2022-12-09T21:59:35Z")

</div>

@georgerobinson  
Apologies for jumping in here, I have alerts + image rendering to S3 + notifications to teams with images all working (and deployed via helm). Its taken a week and 100’s of searches but I got there…

The final hurdle is making the messages pretty and as noted in this thread, the template documentation is not very clear… I’m copy/pasting/editing bits of the the default template:

> <https://github.com/grafana/grafana/blob/main/pkg/services/ngalert/notifier/channels/default_template.go>

into my own template but can’t figure out what part is responsible for the image?  
Can you help?

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![naresh9999](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@naresh9999](https://community.grafana.com/u/naresh9999)\
**Post date:** [December 12, 2022, 3:28am UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/36 "2022-12-12T03:28:09Z")

</div>

Hi @georgerobinson

Its a Microsoft Office Outlook.

---

<div class="post-metadata">

**Author:** ![georgerobinson](https://avatars.discourse-cdn.com/v4/letter/g/ad7895/32.png) [@georgerobinson](https://community.grafana.com/u/georgerobinson)\
**Post date:** [December 12, 2022, 9:49am UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/37 "2022-12-12T09:49:24Z")

</div>

Hi Tom! Images are added to notifications after templating as its difficult to provide a consistent templating experience for images given the varied contact points supported in Grafana. This is something we could reconsider, but it would be good to know what kind of problem you’re looking to solve and whether it would be possible with templates.

---

<div class="post-metadata">

**Author:** ![naresh9999](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@naresh9999](https://community.grafana.com/u/naresh9999)\
**Post date:** [December 12, 2022, 12:37pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/38 "2022-12-12T12:37:10Z")

</div>

Hi @georgerobinson

Its a Microsoft Office Outlook.

---

<div class="post-metadata">

**Author:** ![thopewell](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@thopewell](https://community.grafana.com/u/thopewell)\
**Post date:** [December 12, 2022, 11:52pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/39 "2022-12-12T23:52:03Z")

</div>

Hi @georgerobinson ,

Thanks for the reply.  
Thats useful info - I think the template I was playing with sometimes contained errors which caused screenshots to go missing, leading me to think it was a function of the template. I was trying to have some text below the image, but its entirely cosmetic.

Back to the main topic of this thread, I think we need more documentaion around converting json from the alert-api into a configmap or equivalent that can be used to provision alerts.  
For example, if I create an alert-rule in the UI (v9.3.1), and then get it via the api:

```auto
curl -XGET http://some:password@somegrafana/api/v1/provisioning/alert-rules/1jIgdlKVk | jq . > alert-rule.json

```

delete the original in the UI and then post back the json, I always get this error:

```auto
curl -XPOST http://some:password@somegrafana//api/v1/provisioning/alert-rules -d @alert-rule.json      
{"message":"bad request data","traceID":""} 

```

My thinking is that if I can’t get the json to work via the api, it won’t work as a configmap with sidecar.  
The example yaml given here is too simple:

> **[Create and manage alerting resources using file provisioning | Grafana...](https://grafana.com/docs/grafana/latest/alerting/set-up/provision-alerting-resources/file-provisioning/)**
>
> Create and manage resources using file provisioning

and not all the json is adequately described by the api documentation,

> **[Alerting Provisioning HTTP API | Grafana documentation](https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/#alert-query)**
>
> Grafana Alerts HTTP API

for example, its not clear from “AlertQuery” if this is required or not:

```auto
        "datasource": {
          "name": "Expression",
          "type": " __expr__",
          "uid": " __expr__"
        },

```

As others have asked for, it would be nice if we could have an export function in the UI for alerts where similar to dashboards, you can put the json in the required directory/create a config map out of it for a sidecar, and it “just works”!

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![naresh9999](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@naresh9999](https://community.grafana.com/u/naresh9999)\
**Post date:** [December 13, 2022, 11:23am UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/40 "2022-12-13T11:23:29Z")

</div>

Hi @georgerobinson

Its a Microsoft Office Outlook.

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/1/4/1493bb49940e931654bd282baf58289c70b8932f.png)

Can you please help me on this issue?

---

<div class="post-metadata">

**Author:** ![georgerobinson](https://avatars.discourse-cdn.com/v4/letter/g/ad7895/32.png) [@georgerobinson](https://community.grafana.com/u/georgerobinson)\
**Post date:** [December 13, 2022, 12:33pm UTC](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083/41 "2022-12-13T12:33:05Z")

</div>

Hi! Would it be possible to update Grafana to 9.3 as I recall there being a similar issue for line breaks in some email clients [Newlines not being preserved in certain email clients · Issue #53879 · grafana/grafana · GitHub](https://github.com/grafana/grafana/issues/53879).

[Previous page](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083.md?page=1)

[Next page](https://community.grafana.com/t/documentation-of-alert-templating-in-serious-need-of-improvement/76083.md?page=3)
