Turn alerts into tickets automatically
In this task you'll have monitoring alerts open tracked issues by themselves.
An alert that only sends an email is easy to miss and impossible to track. Instead, have the alert call an endpoint that opens an issue (or work item) with the details, a label and an owner, so it's tracked, assigned and closed like any other work.
In GitHub, an external system starts a workflow with a repository_dispatch event and a JSON client_payload. In Azure, an action group can call a webhook or a Logic App, which can send that event. Use a token or app scoped to just that repository.
Example. When SS Kaiser's checkout error rate passes 2%, Azure Monitor's action group calls a Logic App, which sends repository_dispatch to the shop repository. A workflow opens an issue titled 'Alert: checkout error rate', labelled alert and assigned to on-call.
Before you start
You need: A GitHub repository. Time: 25 minutes.
Where to look
- Monitor
- Alerts
- Action groups
Steps
- Write a workflow on
repository_dispatchwithtypes: alertandpermissions: issues: write. - In the workflow, read
github.event.client_payloadand create an issue withgh issue createand a label. - Test it by sending the event yourself:
gh api repos/OWNER/REPO/dispatches -f event_type=alert. - Point the real alert at it (action group to Logic App or webhook).
Commands
gh api repos/OWNER/REPO/dispatches -f event_type=alert -F 'client_payload[service]=checkout' -F 'client_payload[value]=3.1'
Watch out for
- Cost
- Free on GitHub; Logic Apps and alerts cost a little.
- Security
- The sender needs a token that can only send events to this repository: a fine-grained token or GitHub App.
- Common mistakes
- One issue per alert firing (storms of duplicates): check for an open issue first.
Clean up
Delete the workflow and the action group's webhook.
Words to know
- repository_dispatch
- A GitHub event that an external system sends to start workflows, with a JSON payload.
- client_payload
- The data sent with a repository_dispatch event, such as the alert name and value.
- Action group
- Azure Monitor's list of what to do when an alert fires: email, webhook, Logic App and more.
Tick off each step and track your progress in the guide.
Open this task in DevOps, Hands On