# How to get alertname in notification title

**URL:** <https://community.grafana.com/t/how-to-get-alertname-in-notification-title/56344>\
**Category:** Alerting\
**Tags:** templating, alerting\
**Created:** [November 16, 2021, 1:46pm UTC](https://community.grafana.com/t/how-to-get-alertname-in-notification-title/56344 "2021-11-16T13:46:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazzybig](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/mazzybig/32/13813_2.png) [@mazzybig](https://community.grafana.com/u/mazzybig)\
**Post date:** [November 16, 2021, 1:46pm UTC](https://community.grafana.com/t/how-to-get-alertname-in-notification-title/56344/1 "2021-11-16T13:46:14Z")

</div>

- What Grafana version and what operating system are you using?  
Grafana 8.1.2 with NGAlert enabled

- **What** are you trying to achieve?  
I want to see alert name in notifications titles using my own template

- **How** are you trying to achieve it?  
I’ve created template:

```auto
{{ define "template_title" }}
[{{.Status}}] {{ .Labels.alertname }}
{{ end }}

```

and set it as templated title of the Slack message.  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/4/9/4984e9c9632e1f8a8673ff77643551f415710add.png)

I get this code here - [Notification templating | Grafana documentation](https://grafana.com/docs/grafana/latest/alerting/unified-alerting/message-templating/#custom-template-examples)

- What happened?  
Alert message in Slack is empty with just status  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/3/8/385dbbb3fc775bec6ce20927bfe1f1478fbade31.png)

- What did you **expect** to happen?  
I expect to get normal alert message

- Can you copy/paste the configuration(s) that you are having problems with?

- Did you receive any errors in the Grafana UI or in related logs? If so, please tell us **exactly** what they were.

No

- Did you follow any online instructions? If so, what is the URL?  
[Notification templating | Grafana documentation](https://grafana.com/docs/grafana/latest/alerting/unified-alerting/message-templating/#custom-template-examples)

---

<div class="post-metadata">

**Author:** ![anon70503803](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@anon70503803](https://community.grafana.com/u/anon70503803)\
**Post date:** [November 30, 2021, 3:10am UTC](https://community.grafana.com/t/how-to-get-alertname-in-notification-title/56344/2 "2021-11-30T03:10:12Z")

</div>

Can you screenshot your full alert config? If you are using Grafana managed alerts with a classic condition, templating will not work.

You must use a multi-dimensional rule.

---

<div class="post-metadata">

**Author:** ![mazzybig](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/mazzybig/32/13813_2.png) [@mazzybig](https://community.grafana.com/u/mazzybig)\
**Post date:** [November 30, 2021, 9:44am UTC](https://community.grafana.com/t/how-to-get-alertname-in-notification-title/56344/3 "2021-11-30T09:44:02Z")

</div>

Hi Matt!  
I don’t know how it works, but now I use template based on default one and get only title.

```auto
{{ define "template_title" }}
[{{ .Status | toUpper }}: {{ if eq .Status "firing" }}{{ .Alerts.Firing | len }}{{ else if eq .Status "resolved" }}{{.Alerts.Resolved | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }}
{{ end }}

```

And yes, I use multi-dimensional rules everywhere.  
I can’t explain why `{{ .Labels.alertname }}` isn’t working

---

<div class="post-metadata">

**Author:** ![aruddick](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@aruddick](https://community.grafana.com/u/aruddick)\
**Post date:** [September 7, 2022, 11:01pm UTC](https://community.grafana.com/t/how-to-get-alertname-in-notification-title/56344/4 "2022-09-07T23:01:40Z")

</div>

I’m aware this is old, but I could find no other information on the fix. The documentation is severely lacking, but fortunately I found the answer in the [source code](https://github.com/grafana/grafana/blob/main/pkg/services/ngalert/notifier/channels/default_template.go#L68).

Use `{{ .CommonLabels.alertname }}`

Hope this helps someone.

---

<div class="post-metadata">

**Author:** ![grant2](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grant2/32/42281_2.png) [@grant2](https://community.grafana.com/u/grant2)\
**Post date:** [September 8, 2022, 12:04am UTC](https://community.grafana.com/t/how-to-get-alertname-in-notification-title/56344/5 "2022-09-08T00:04:03Z")

</div>

@arrudick This is a great find. Thank you for posting. Can you paste a screenshot of a working example of this?

---

<div class="post-metadata">

**Author:** ![jackwright](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jackwright](https://community.grafana.com/u/jackwright)\
**Post date:** [September 13, 2022, 4:34pm UTC](https://community.grafana.com/t/how-to-get-alertname-in-notification-title/56344/6 "2022-09-13T16:34:04Z")

</div>

Thank you so much for this!!! I have lost the best part of the afternoon trying to get the alertname on the title of a MS teams alert and this has done the trick. Would have saved me a lot of time if this was made clear in the documentation! Thanks again.

---

<div class="post-metadata">

**Author:** ![aruddick](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@aruddick](https://community.grafana.com/u/aruddick)\
**Post date:** [September 13, 2022, 10:21pm UTC](https://community.grafana.com/t/how-to-get-alertname-in-notification-title/56344/7 "2022-09-13T22:21:19Z")

</div>

Apologies @grant2 I did not see your reply.

 ![Screen Shot 2022-09-13 at 5.19.04 PM](https://us1.discourse-cdn.com/grafana/original/3X/6/b/6b6595ea058ee6970e0c64a1c998e65a9263e7f6.png)

---

<div class="post-metadata">

**Author:** ![adrianomatildes01](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@adrianomatildes01](https://community.grafana.com/u/adrianomatildes01)\
**Post date:** [November 18, 2022, 6:43pm UTC](https://community.grafana.com/t/how-to-get-alertname-in-notification-title/56344/8 "2022-11-18T18:43:18Z")

</div>

I did according to the example above but in my case it didn’t work. Does anyone have an idea why it didn’t work, I’m using grafana version 9.2.5

 ![grafana](https://us1.discourse-cdn.com/grafana/original/3X/3/a/3a4940444aabc6b59fa9de729ec54529f54411a3.png)
