Create an GitHub workflow that’s triggered by a Pagerduty alert#
Sometimes, it’s useful to be able to run a GitHub workflow for and alert that has been triggered in Pagerduty. To do so, we can use Pagerduty’s incident workflow feature.
Steps#
On the PagerDuty side#
Go to the list of incident workflows and click the
New Workflowbutton in the right side of the screen.Give it a suggestive name and click the
CreatebuttonIn the
Buildersection, clickAdd Triggerand choose the desired oneWhen you’re happy with the trigger, click the
Add ActionbuttonFrom the list of actions, search after
Send a Webhook POST, select it once you find it and click theAdd Action buttonon the rightAfter adding the
Send a Webhook POSTaction, a menu should have been opened for you on the right side of the screenIn that menu, enter the following:
URL: https://api.github.com/repos/2i2c-org/infrastructure/dispatches
Authentication Headers: 2i2c-Bot GitHub PAT
Headers:
Content-Type: application/json Accept: application/vnd.github.v3+json
Body
{ "event_type": "some-relevant-keyword-for-matching-this-event", "client_payload": { "incident_id": "{{incident.id}}", "title": "{{incident.title}}", "service": "{{incident.service.name}}", "type": "{{incident.incident_type.display_name}}" } }
Note
Note that the event type is what’s going to be used by GitHub to trigger or not the workflow. Also, other things can be included in the payload. Experiment!
On the GitHub side#
Create a new workflow file in
.github/workflowsIn this file, the following info is important:
name: P1 outages actions on: repository_dispatch: types: [some-relevant-keyword-for-matching-this-event]
Add the jobs you want
Now, this workflow will run every time the conditions set in the incident workflow you set up, if they match the following some-relevant-keyword-for-matching-this-event type.