Please note: I have seen issues indicating that this solution is not production ready (when on a Subscription Plan). Errors include multiple alert messages per trigger, and some few messages being lost. I suspect this to be related to cold starting.
I strongly suggest testing it for a certain period of time before going to production, and I would also suggest considering an App Service Plan for the function to run in a dedicated 24/7 VM. Read more here:
If you follow the official PagerDuty integration guide for Microsoft Teams, you are instructed to configure a generic webhook which posts to an official PagerDuty Connector in Teams. This works like a charm, and you’ll be up and running in minutes. The output, however, is not very rich, and you’ll be left with no actual information about what the alert is about:
To circumvent the limitations of the official integration, I set out to give the webhook another jump before it hits Teams, to be able to manipulate and enrich messages sent.
Here’s how to set it up:
1. Set up the Teams Connector
First go to the channel in which you want alerts to be posted. There you’ll find the “Connectors” option:
From there you’ll be able to configure a new Incoming Webhook. Give it a name and upload an icon (optional). After the creation you will be presented with the URL of the webhook. Remember to copy this URL, as you’ll need it later.
2. Create the Azure Function App
Log on to your Azure Portal and create a new Functions App. Give it a name and select a hosting location. Go with Windows OS.
Next, go to the “Integrate” menu option below your newly created function, and set the “Allowed HTTP methods” option to “Selected methods”. Make sure only “POST” is checked:
Then go to the function code view and paste the contents of this file. After pasting it, replace the teamsWebhookPath variable with the webhook URL you created in step 1. Make sure to only add the path of the URL, without the domain name (see example below):
Now click the “Get function URL” link, and you will be presented with the function URL used to post requests to your new endpoint. Copy it, you’ll need it in a minute. Next, hit save, and the function should be up and running!
3. Configure the PagerDuty extension
The only remaining step is to set up an extension in PagerDuty from which alerts will be sent when a service triggers an alert.
Log on to your company PagerDuty account, go to the Extensions menu (Configuration -> Extensions), and add a new “Generic V2 Webhook” extension, using the function URL as the webhook URL, and map it to a service:
4. Test it!
The integration should now be up an running. Test it by manually creating an incident or by triggering an actual alert from the service. As alerts are being triggered, acknowledged and resolved, messages should appear in your Teams channel:
If there’s something you want to change, simply make changes to the code in the Azure Function to better suit your needs. You should be able to add more information about who the incident is assigned to, notes and more.
These useful tools will help you get it right:
- The MessageCard Playground helps you design the layout of message cards in Teams (set in the jsonModel variables at the bottom of the function code)
- The PagerDuty webhooks documentation gives you information about the data model used by PagerDuty webhooks
If you come up with a better design layout, or have any other improvements or suggestions, let me know!