Change Incident Owner In Pagerduty
Overview
This self service guide provides a comprehensive walkthrough on how to change an incident owner 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/change-incident-owner.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: Change PagerDuty Incident Owner
on:
workflow_dispatch:
inputs:
new_owner:
description: Email User of the new incident owner
required: true
type: string
from:
description: The email address of a valid pagerduty user associated with the account making the request.
required: true
type: string
port_context:
required: true
description: includes blueprint, run ID, and entity identifier from Port.
jobs:
change-incident-owner:
runs-on: ubuntu-latest
steps:
- name: Inform searching of user in user list
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: "Searching for user in organization user list... ⛴️"
- name: Search for user id among user list
id: search_for_user_id
uses: fjogeleit/http-request-action@v1
with:
url: "https://api.pagerduty.com/users?query=${{ github.event.inputs.new_owner }}"
method: "GET"
customHeaders: '{"Content-Type": "application/json", "Authorization": "Token token=${{ secrets.PAGERDUTY_API_KEY }}"}'
- name: Retrieve user list from search
id: user_id_from_search
if: steps.search_for_user_id.outcome == 'success'
run: |
user_id=$(echo '${{ steps.search_for_user_id.outputs.response }}' | jq -r '.users | if length > 0 then .[0].id else "empty" end')
echo "user_id=${user_id}" >> $GITHUB_OUTPUT
- name: Inform user existence
if: steps.user_id_from_search.outputs.user_id != 'empty'
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: |
User found 🥹, Changing incident owner to ${{ inputs.new_owner }}... ⛴️
- name: Inform user inexistence
if: steps.user_list_from_search.outputs.selected_user_id == 'empty'
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: |
User not found 😭 Skipping assignment... ⛴️
- name: Change Incident Owner in PagerDuty
id: change_owner
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.pagerduty.com/incidents/${{fromJson(inputs.port_context).entity}}'
method: 'PUT'
customHeaders: '{"Content-Type": "application/json", "Accept": "application/vnd.pagerduty+json;version=2", "Authorization": "Token token=${{ secrets.PAGERDUTY_API_KEY }}", "From": "${{ github.event.inputs.from }}"}'
data: >-
{
"incident": {
"type": "incident_reference",
"assignments": [
{
"assignee": {
"id": "${{ steps.user_id_from_search.outputs.user_id }}",
"type": "user_reference"
}
}
]
}
}
- name: Inform ingestion of pagerduty incident to Port
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 pagerduty entity to Port
uses: port-labs/port-github-action@v1
with:
identifier: "${{ fromJson(steps.change_owner.outputs.response).incident.id }}"
title: "${{ fromJson(steps.change_owner.outputs.response).incident.title }}"
blueprint: ${{fromJson(inputs.port_context).blueprint}}
properties: |-
{
"status": "${{ fromJson(steps.change_owner.outputs.response).incident.status }}",
"url": "${{ fromJson(steps.change_owner.outputs.response).incident.self }}",
"urgency": "${{ fromJson(steps.change_owner.outputs.response).incident.urgency }}",
"responder": "${{ fromJson(steps.change_owner.outputs.response).incident.assignments[0].assignee.summary}}",
"escalation_policy": "${{ fromJson(steps.change_owner.outputs.response).incident.escalation_policy.summary }}",
"created_at": "${{ fromJson(steps.change_owner.outputs.response).incident.created_at }}",
"updated_at": "${{ fromJson(steps.change_owner.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 completion of pagerduty incident upsertion
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: "Entity upserting was successful ✅"
Port Configuration
Create a new self service action using the following JSON configuration.
Change Incident Owner In PagerDuty (click to expand)
Make sure to replace <GITHUB_ORG>
and <GITHUB_REPO>
with your GitHub organization and repository names respectively.
{
"identifier": "pagerdutyIncident_change_incident_owner",
"title": "Change Incident Owner",
"icon": "pagerduty",
"description": "Change Incident Owner in pagerduty",
"trigger": {
"type": "self-service",
"operation": "DAY-2",
"userInputs": {
"properties": {
"from": {
"icon": "User",
"title": "From",
"description": "The email address of a valid user associated with the account making the request.",
"type": "string",
"format": "user"
},
"new_owner": {
"icon": "pagerduty",
"title": "New Owner",
"description": "Email User of the new incident owner",
"type": "string",
"format": "user"
}
},
"required": [
"new_owner",
"from"
],
"order": [
"new_owner",
"from"
]
},
"blueprintIdentifier": "pagerdutyIncident"
},
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB_ORG>",
"repo": "<GITHUB_REPO>",
"workflow": "change-incident-owner.yaml",
"workflowInputs": {
"new_owner": "{{.inputs.\"new_owner\"}}",
"from": "{{.inputs.\"from\"}}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}"
}
},
"reportWorkflowStatus": true
},
"requiredApproval": false,
"publish": true
}
Now you should see the Change Incident Owner
action in the self-service page. 🎉
Let's test it!
- Head to the Self Service hub
- Click on the
Change Incident Owner
action - Choose the jira ticket you want to change the status and assignee for (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
- Click on
Execute
- Done! wait for the incident's status to be changed in PagerDuty
Congrats 🎉 You've successfully changed a pagerduty incident owner in Port 🔥