PagerDuty + Slack + Azure Integration

An illustrated walk through of how to correctly set up the integration between these three services.

Danielle Fenske
PayScale Tech
4 min readFeb 18, 2020

--

Photo Credit: unsplash.com

Our tech ecosystem involves PagerDuty for alerting, Slack for communicating, and Azure for logs. We wanted to integrate all of these so we could have clear, transparent alerting for our various apps that we host in Azure.

We thought we had this integration all set up, but we were observing a strange anomaly. Slack would not notify us if the Azure alert had been triggered. It would only notify us when the alert had been acknowledged, resolved, etc. Furthermore when we tried to view the specific alert in PagerDuty, the whole site would freeze or crash.

We finally figured out the cause of these issues: the large JSON payload associated with the alert from Azure.

note: this occurs only with Azure Alerts that are configured using the “Log Search” Signal Type.

To restate the problems we were seeing:

  • Slack would not notify us of Triggered alerts
Problem 1: Slack didn’t notify us of a Triggered PagerDuty alert
  • The PagerDuty app would crash regularly while trying to view the alerts
Problem 2: The PagerDuty site would crash when viewing the specific alert, due to the large JSON payload

To resolve these issues, I found that we needed to configure a Custom JSON payload for our Azure Webhooks, which are used by PagerDuty. To do that, I went into the configuration for our Azure alerts.

Azure Configuration

As you can see below, our PagerDuty Webhook was already set up, and the condition is a Custom Log Search. This following steps are only required if the alert is a Custom Log Search type.

Step 1: Configuring the Azure Log Search Alert to use a custom JSON Payload for the Webhook

Then to actually customize the JSON payload, I checked the box labeled “Include custom JSON payload for webhook”. To specify the JSON output, I referred to the Azure documentation on how to use predefined variables in the text of the JSON. You can use variables such as #searchresultcount to include details in the text about this specific alert.

To ensure that my custom JSON looked correct, I clicked the “View Sample Webhook Payload” button.

You can use predefined variables from Azure to configure the custom JSON payload (documentation)

After configuring my alert in Azure, I tested my alert in Slack:

Problem 3: My Slack notification was missing a description, because it couldn’t be parsed from the JSON

But wait… there’s a new problem ! The summary is missing from the Slack alert.

PagerDuty Configuration

To configure the summary of an alert in Slack, I had to go into PagerDuty to configure my service to read from the correct JSON fields. So I went to the Event Rules tab of my service:

The Event Rules tab is where you can configure the correct fields to use in the Slack alert

Inside the Event Rules, I configured a new rule with the following criteria:

You need to configure an Event Rule to extract the right details from the custom JSON payload

In the following screenshots, I show more detail on what values need to be configured to populate the Slack alert’s summary. I needed to create a rule that fired only if the text field of Custom Details existed. (text should be replaced with whatever field in the JSON object you want to extract Summary from).

Step 1 for configuring the Event Rule

Then I clicked “Do these things” and went to the Advanced tab. I checked the box “Add or replace the summary field” and filled it in as shown below. This specifies that the alert should replace the Summary field with the custom field named text.

Step 2 for configuring the Event Rule

I then tested my alert one more time — success! The alert shows up as Triggered in Slack, with the summary that I configured in Azure:

The Triggered alert showed up in Slack, with a detailed error message from the Custom JSON payload.

One last thing: if you don’t see the Event Rules tab in your PagerDuty Service configuration, you may need to edit the service so that it can create alerts AND incidents. The Event Rule tab will not show up if the service is configured differently.

Note: If you don’t have your service configured this way, the Event Rules tab won’t show up

Hopefully this can help anyone facing a similar issue to correctly configure their alerts. Happy configuring!

--

--

Danielle Fenske
PayScale Tech

I am a Software Engineer at PayScale, a crowd-sourced compensation software company. I focus on creating attractive and reliable front-end web apps.