Trigger a PagerDuty Incident
Overview
This self service guide provides a comprehensive walkthrough on how to trigger an incident in Pagerduty from Port using Port's self service actions.
Prerequisites
-
Port's GitHub app needs to be installed.
-
In your GitHub repository, go to Settings > Secrets and add the following secrets:
PAGERDUTY_API_KEY
- PagerDuty API token generated by the user.PORT_CLIENT_ID
- Your portclient id
How to get the credentials.PORT_CLIENT_SECRET
- Your portclient secret
How to get the credentials.
-
Optional - Install Port's PagerDuty integration learn more
PagerDuty IntegrationThis step is not required for this example, but it will create all the blueprint boilerplate for you, and also ingest and update the catalog in real time with your PagerDuty Incidents.
-
In Case you decided not to install the PagerDuty integration, you will need to create a blueprint for PagerDuty incidents in Port.
PagerDuty Incident Blueprint
{
"identifier": "pagerdutyIncident",
"description": "This blueprint represents a PagerDuty incident in our software catalog",
"title": "PagerDuty Incident",
"icon": "pagerduty",
"schema": {
"properties": {
"status": {
"type": "string",
"title": "Incident Status",
"enum": [
"triggered",
"annotated",
"acknowledged",
"reassigned",
"escalated",
"reopened",
"resolved"
]
},
"url": {
"type": "string",
"format": "url",
"title": "Incident URL"
},
"urgency": {
"type": "string",
"title": "Incident Urgency",
"enum": ["high", "low"]
},
"responder": {
"type": "string",
"title": "Assignee"
},
"escalation_policy": {
"type": "string",
"title": "Escalation Policy"
},
"created_at": {
"title": "Create At",
"type": "string",
"format": "date-time"
},
"updated_at": {
"title": "Updated At",
"type": "string",
"format": "date-time"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"pagerdutyService": {
"title": "PagerDuty Service",
"target": "pagerdutyService",
"required": false,
"many": true
}
}
}
GitHub Workflow
Create the file .github/workflows/trigger-incident.yaml
in the .github/workflows
folder of your repository.
We recommend creating a dedicated repository for the workflows that are used by Port actions.
GitHub Workflow
name: Trigger an Incident In PagerDuty
on:
workflow_dispatch:
inputs:
payload:
type: string
event_action:
type: string
routing_key:
type: string
summary:
type: string
source:
type: string
severity:
type: string
port_context:
required: true
description: includes blueprint, run ID, and entity identifier from Port.
jobs:
trigger-incident:
runs-on: ubuntu-latest
steps:
- name: Inform starting of PagerDuty trigger
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: |
About to trigger PagerDuty incident.. ⛴️
- name: Send Event to PagerDuty
id: trigger
uses: fjogeleit/http-request-action@v1
with:
url: 'https://events.pagerduty.com/v2/enqueue'
method: 'POST'
customHeaders: '{"Content-Type": "application/json", "Accept": "application/json"}'
data: >-
{
"payload": {
"summary": "${{ github.event.inputs.summary }}",
"source": "${{ github.event.inputs.source }}",
"severity": "${{ github.event.inputs.severity }}"
},
"event_action": "${{ github.event.inputs.event_action }}",
"routing_key": "${{ github.event.inputs.routing_key }}"
}
- name: Get PagerDuty Incident Details
id: get_incident
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.pagerduty.com/incidents/${{fromJson(inputs.port_context).entity}}'
method: 'GET'
customHeaders: '{"Content-Type": "application/json", "Accept": "application/vnd.pagerduty+json;version=2", "Authorization": "Token token=${{ secrets.PAGERDUTY_API_KEY }}"}'
- name: Log Before Upserting Entity
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: "Reporting the updated incident back to port ..."
- name: UPSERT Entity
uses: port-labs/port-github-action@v1
with:
identifier: "${{ fromJson(steps.get_incident.outputs.response).incident.id }}"
title: "${{ fromJson(steps.get_incident.outputs.response).incident.title }}"
team: "[]"
icon: "pagerduty"
blueprint: "${{fromJson(inputs.port_context).blueprint}}"
properties: |-
{
"status": "${{ fromJson(steps.get_incident.outputs.response).incident.status }}",
"url": "${{ fromJson(steps.get_incident.outputs.response).incident.self }}",
"urgency": "${{ fromJson(steps.get_incident.outputs.response).incident.urgency }}",
"responder": "${{ fromJson(steps.get_incident.outputs.response).incident.assignments[0].assignee.summary }}",
"escalation_policy": "${{ fromJson(steps.get_incident.outputs.response).incident.escalation_policy.summary }}",
"created_at": "${{ fromJson(steps.get_incident.outputs.response).incident.created_at }}",
"updated_at": "${{ fromJson(steps.get_incident.outputs.response).incident.updated_at }}"
}
relations: "${{ toJson(fromJson(inputs.port_context).relations) }}"
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: UPSERT
runId: ${{fromJson(inputs.port_context).run_id}}
- name: Inform Entity upsert failure
if: steps.upsert_entity.outcome == 'failure'
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: "Failed to report the triggered incident back to Port ..."
- name: Log After Upserting Entity
id: log-response
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: |
PagerDuty incident triggered! ✅
Port Configuration
Create a new self service action using the following JSON configuration.
Trigger Incident In PagerDuty (click to expand)
Make sure to replace <GITHUB_ORG>
and <GITHUB_REPO>
with your GitHub organization and repository names respectively.
{
"identifier": "pagerdutyIncident_trigger_incident",
"title": "Trigger Incident",
"icon": "pagerduty",
"description": "Trigger a pagerduty incident using self service",
"trigger": {
"type": "self-service",
"operation": "DAY-2",
"userInputs": {
"properties": {
"event_action": {
"icon": "pagerduty",
"title": "Event Action",
"type": "string",
"description": "The type of event. Can be trigger, acknowledge or resolve",
"default": "trigger",
"enum": [
"trigger",
"acknowledge",
"resolve"
],
"enumColors": {
"trigger": "lightGray",
"acknowledge": "lightGray",
"resolve": "lightGray"
}
},
"routing_key": {
"icon": "pagerduty",
"title": "Routing Key",
"type": "string",
"description": "This is the 32 character Integration Key for an integration on a service or on a global ruleset."
},
"summary": {
"type": "string",
"title": "Summary",
"icon": "pagerduty",
"description": "A brief text summary of the event, used to generate the summaries/titles of any associated alerts. The maximum permitted length of this property is 1024 characters.",
"maxLength": 1024
},
"source": {
"type": "string",
"title": "Source",
"description": "The unique location of the affected system, preferably a hostname or FQDN.",
"icon": "pagerduty"
},
"severity": {
"type": "string",
"title": "Severity",
"description": "The perceived severity of the status the event is describing with respect to the affected system. This can be critical, error, warning or info.",
"icon": "pagerduty",
"default": "info",
"enum": [
"critical",
"error",
"warning",
"info"
],
"enumColors": {
"critical": "red",
"error": "orange",
"warning": "yellow",
"info": "blue"
}
}
},
"required": [
"routing_key",
"event_action",
"summary",
"source",
"severity"
],
"order": [
"routing_key",
"event_action",
"summary",
"source",
"severity"
]
},
"blueprintIdentifier": "pagerdutyIncident"
},
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB_ORG>",
"repo": "<GITHUB_REPO>",
"workflow": "trigger-pagerduty-incident.yaml",
"workflowInputs": {
"summary": "{{.inputs.\"summary\"}}",
"source": "{{.inputs.\"source\"}}",
"severity": "{{.inputs.\"severity\"}}",
"event_action": "{{.inputs.\"event_action\"}}",
"routing_key": "{{.inputs.\"routing_key\"}}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}",
"relations": "{{.entity.relations}}"
}
},
"reportWorkflowStatus": true
},
"requiredApproval": false,
"publish": true
}
Now you should see the Trigger Incidents
action in the self-service page. 🎉
Let's test it!
- Head to the Self Service hub
- Click on the
Trigger Incident
action - Choose the pagerduty incident you want to trigger (In case you didn't install the PagerDuty integration, it means you don't have any PagerDuty incidents in Port yet, so you will need to create one manually in Port to test this action)
- Select the new incident
- Enter the email address of a valid user associated with the account making the request.
- Click on
Execute
- Done! wait for the incident's status to be changed in PagerDuty
Congrats 🎉 You've triggered a PagerDuty incident in Port 🔥