Skip to main content

Trigger A PagerDuty Incident Action

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

  1. Port's GitHub app needs to be installed.

  2. In your GitHub repository, go to Settings > Secrets and add the following secrets:

  3. Optional - Install Port's PagerDuty integration learn more

    PagerDuty Integration

    This 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.

  4. 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.

tip

We recommend creating a dedicated repository for the workflows that are used by Port actions.

GitHub Workflow
trigger-incident.yaml
name: Trigger an Incident In PagerDuty
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_payload:
required: true
description: Port's payload, including details for who triggered the action and
general context (blueprint, run id, etc...)
type: string
jobs:
create-entity-in-port-and-update-run:
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_payload).context.runId }}
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: Create a log message
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_payload).context.runId}}
logMessage: |
PagerDuty incident triggered! ✅
"The incident id is: ${{ steps.trigger.outputs}}"

Port Configuration

Create a new self service action using the following JSON configuration.

Trigger Incident In PagerDuty (click to expand)
Modification Required

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.",
"minLength": 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": {
"{{if (.inputs | has(\"ref\")) then \"ref\" else null end}}": "{{.inputs.\"ref\"}}",
"{{if (.inputs | has(\"summary\")) then \"summary\" else null end}}": "{{.inputs.\"summary\"}}",
"{{if (.inputs | has(\"source\")) then \"source\" else null end}}": "{{.inputs.\"source\"}}",
"{{if (.inputs | has(\"severity\")) then \"severity\" else null end}}": "{{.inputs.\"severity\"}}",
"{{if (.inputs | has(\"event_action\")) then \"event_action\" else null end}}": "{{.inputs.\"event_action\"}}",
"{{if (.inputs | has(\"routing_key\")) then \"routing_key\" else null end}}": "{{.inputs.\"routing_key\"}}",
"port_payload": {
"action": "{{ .action.identifier[(\"pagerdutyIncident_\" | length):] }}",
"resourceType": "run",
"status": "TRIGGERED",
"trigger": "{{ .trigger | {by, origin, at} }}",
"context": {
"entity": "{{.entity.identifier}}",
"blueprint": "{{.action.blueprint}}",
"runId": "{{.run.id}}"
},
"payload": {
"entity": "{{ (if .entity == {} then null else .entity end) }}",
"action": {
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB_ORG>",
"repo": "<GITHUB_REPO>",
"workflow": "trigger-pagerduty-incident.yaml",
"omitUserInputs": false,
"omitPayload": false,
"reportWorkflowStatus": true
},
"trigger": "{{.trigger.operation}}"
},
"properties": {
"{{if (.inputs | has(\"summary\")) then \"summary\" else null end}}": "{{.inputs.\"summary\"}}",
"{{if (.inputs | has(\"source\")) then \"source\" else null end}}": "{{.inputs.\"source\"}}",
"{{if (.inputs | has(\"severity\")) then \"severity\" else null end}}": "{{.inputs.\"severity\"}}",
"{{if (.inputs | has(\"event_action\")) then \"event_action\" else null end}}": "{{.inputs.\"event_action\"}}",
"{{if (.inputs | has(\"routing_key\")) then \"routing_key\" else null end}}": "{{.inputs.\"routing_key\"}}"
},
"censoredProperties": "{{.action.encryptedProperties}}"
}
}
},
"reportWorkflowStatus": true
},
"requiredApproval": false,
"publish": true
}

Now you should see the Trigger Incidents action in the self-service page. 🎉

Let's test it!

  1. Head to the Self Service hub
  2. Click on the Trigger Incident action
  3. 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)
  4. Select the new incident
  5. Enter the email address of a valid user associated with the account making the request.
  6. Click on Execute
  7. Done! wait for the incident's status to be changed in PagerDuty

Congrats 🎉 You've triggered a PagerDuty incident in Port 🔥

More Self Service PagerDuty Actions Examples