# Setting PagerDuty Severity from alert labels

**URL:** <https://community.grafana.com/t/setting-pagerduty-severity-from-alert-labels/134948>\
**Category:** Alerting\
**Tags:** pagerduty, templating\
**Created:** [October 24, 2024, 1:49am UTC](https://community.grafana.com/t/setting-pagerduty-severity-from-alert-labels/134948 "2024-10-24T01:49:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![treverw](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/treverw/32/49795_2.png) [@treverw](https://community.grafana.com/u/treverw)\
**Post date:** [October 24, 2024, 1:49am UTC](https://community.grafana.com/t/setting-pagerduty-severity-from-alert-labels/134948/1 "2024-10-24T01:49:10Z")

</div>

Using Grafana 10.4.1 (AWS Managed Grafana), I am creating an alert and setting a label called ‘severity’ that I want to use in the Contact Point, which sends it to PagerDuty. I expect it to set the ‘Severity’ field for PagerDuty to the value of the label set in the alert. Below are the steps I’ve gone through.

In the alert settings I add a label called ‘severity’ and set it to ‘critical’:

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

Then I create a Notification Template in Contact Points which should return the value of the Alert Label or ‘Info’ as a default if the Alert label is not set.

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/d/b/db660b18c7a27dad98ed4ce863effd8fd35fa546.png)

Next, in the Contact Point that is configured to send to PagerDuty, I try to use that template to set the ‘severity’ value.

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/1/0/10b2b3b3c73425d2064542026a124305660150d4.png)

When I test an alert with that label set to “info”, I expect the PagerDuty alert to be set to “Low” urgency based on the settings in PagerDuty where I set the notification policy.

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

But instead, it’s getting set to the (default?) “High” urgency.

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/e/3/e30f3bb73db6e2e7fd129e4cb2ea949e305cb9d8.png)

When I look at the details of what got sent to PagerDuty, I don’t see the top-level field for ‘severity’. It exists in the labels but I don’t think PagerDuty looks there to determine the urgency of the alert.

```auto
Received this event via the events API
{
  "client": "Grafana",
  "client_url": "https://grafana-workspace.us-east-1.amazonaws.com/",
  "contexts": [
    {
      "href": "https://grafana-workspace.us-east-1.amazonaws.com/",
      "text": "External URL",
      "type": "link"
    }
  ],
  "description": "[FIRING:1] TestAlert Grafana info ",
  "event_type": "trigger",
  "incident_key": "obfuscated",
  "service_key": "obfuscated",
  "details": {
    "firing": "
Value: [no value]
Labels:
 - alertname = TestAlert
 - instance = Grafana
 - severity = info
Annotations:
 - summary = Notification test
Silence: https://grafana-workspace.us-east-1.amazonaws.com/alerting/silence/new?alertmanager=grafana&matcher=alertname%3DTestAlert&matcher=instance%3DGrafana&matcher=severity%3Dinfo
",
    "num_firing": "1",
    "num_resolved": "0",
    "resolved": ""
  }
}

```

---

<div class="post-metadata">

**Author:** ![treverw](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/treverw/32/49795_2.png) [@treverw](https://community.grafana.com/u/treverw)\
**Post date:** [October 24, 2024, 2:24am UTC](https://community.grafana.com/t/setting-pagerduty-severity-from-alert-labels/134948/2 "2024-10-24T02:24:11Z")

</div>

I’ve modified the Notification Template a bit, as shown below, but it still doesn’t set the Severity field before sending it to PagerDuty.

```auto
{{- define "alert.severity" -}}
  {{ range .Alerts }}
    {{- with .Labels.severity }}
      {{ . }}
    {{ else }}
      Info
    {{ end -}}
  {{ end }}
{{- end -}}

```

---

<div class="post-metadata">

**Author:** ![kubsonw](https://avatars.discourse-cdn.com/v4/letter/k/59ef9b/32.png) [@kubsonw](https://community.grafana.com/u/kubsonw)\
**Post date:** [November 26, 2024, 2:45pm UTC](https://community.grafana.com/t/setting-pagerduty-severity-from-alert-labels/134948/3 "2024-11-26T14:45:30Z")

</div>

It doesn’t work due to the wrong hyphen “-” placement. Try this one:

```auto
{{ define "alert_severity" -}}
  {{ range .Alerts -}}
    {{ with .Labels.Severity -}}
      {{ . }}
    {{- else -}}
      critical
    {{- end -}}
  {{ end -}}
{{ end -}}

```

it works for me. Make sure your output in the preview looks like this:

```auto
====================================>critical<====================================

```

Without any additional lines or spaces.

---

<div class="post-metadata">

**Author:** ![fadeevabcom](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@fadeevabcom](https://community.grafana.com/u/fadeevabcom)\
**Post date:** [March 25, 2025, 4:37pm UTC](https://community.grafana.com/t/setting-pagerduty-severity-from-alert-labels/134948/4 "2025-03-25T16:37:56Z")

</div>

I made it work via using the following template line in the **Severity** field of a` Grafana -> Contact Point -> PagerDuty` settings instead of using Notification Templates.

```go
{{- range .Alerts -}}{{or .Labels.severity "critical" -}}{{- end -}}

```

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/b/0/b0e56fedfaa8ce8c6df52e280164c43d7d7698a7.png)

DON’T FORGET to change the **escalation policy** for the Grafana service on the PageDuty side.

I hope it helps someone.
