Create a PagerDuty Service
Overview
This self service guide provides a comprehensive walkthrough on how to create a service 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 service in Port.
PagerDuty Service Blueprint (Click to expand)
{
"identifier": "pagerdutyService",
"description": "This blueprint represents a PagerDuty service in our software catalog",
"title": "PagerDuty Service",
"icon": "pagerduty",
"schema": {
"properties": {
"status": {
"title": "Status",
"type": "string",
"enum": [
"active",
"warning",
"critical",
"maintenance",
"disabled"
],
"enumColors": {
"active": "green",
"warning": "yellow",
"critical": "red",
"maintenance": "lightGray",
"disabled": "darkGray"
}
},
"url": {
"title": "URL",
"type": "string",
"format": "url"
},
"oncall": {
"title": "On Call",
"type": "string",
"format": "user"
},
"meanSecondsToResolve": {
"title": "Mean Seconds to Resolve",
"type": "number"
},
"meanSecondsToFirstAck": {
"title": "Mean Seconds to First Acknowledge",
"type": "number"
},
"meanSecondsToEngage": {
"title": "Mean Seconds to Engage",
"type": "number"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}
GitHub Workflow
Create the file .github/workflows/acknowledge-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: Create PagerDuty Service
on:
workflow_dispatch:
inputs:
name:
description: 'Name of the PagerDuty Service'
required: true
type: string
description:
description: 'Description of the PagerDuty Service'
required: false
type: string
escalation_policy:
description: 'Escalation Policy for the service'
required: true
type: string
port_context:
required: true
description: includes blueprint, run ID, and entity identifier from Port.
jobs:
create-pagerduty-service:
runs-on: ubuntu-latest
steps:
- name: Create Service in PagerDuty
id : create_service_request
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.pagerduty.com/services'
method: 'POST'
customHeaders: '{"Content-Type": "application/json", "Accept": "application/vnd.pagerduty+json;version=2", "Authorization": "Token token=${{ secrets.PAGERDUTY_API_KEY }}"}'
data: >-
{
"service": {
"name": "${{ github.event.inputs.name }}",
"description": "${{ github.event.inputs.description }}",
"status": "active",
"escalation_policy": {
"id": "${{ github.event.inputs.escalation_policy }}",
"type": "escalation_policy_reference"
}
}
}
- name: Log Create Service Request Failure
if: 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: "Request to create service failed ..."
- name: Log Request Success
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 service created! ✅
Requesting for on-calls
- name: Request for oncalls for Escalation Policy
id: fetch_oncalls
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.pagerduty.com/oncalls?include[]=users&escalation_policy_ids[]=${{ inputs.escalation_policy }}'
method: 'GET'
customHeaders: '{"Content-Type": "application/json", "Accept": "application/json", "Authorization": "Token token=${{ secrets.PAGERDUTY_API_KEY }}"}'
- name: Extract User Emails
if: steps.fetch_oncalls.outcome == 'success'
id: extract_user_emails
run: |
echo "Extracting user emails..."
EMAILS=$(echo '${{ steps.fetch_oncalls.outputs.response }}' | jq -c '[.oncalls[].user.email]')
echo "Extracted emails: $EMAILS"
echo "user_emails=${EMAILS}" >> $GITHUB_ENV
- name: Log Fetch Oncalls Request Failure
if: steps.fetch_oncalls.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 fetch on-calls ❌
- 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: |
Upserting Created PagerDuty Entity
- name: UPSERT PagerDuty Entity
uses: port-labs/port-github-action@v1
with:
identifier: "${{ fromJson(steps.create_service_request.outputs.response).service.id }}"
title: "${{ fromJson(steps.create_service_request.outputs.response).service.summary }}"
icon: pagerduty
blueprint: "${{fromJson(inputs.port_context).blueprint}}"
properties: |-
{
"status": "${{ fromJson(steps.create_service_request.outputs.response).service.status }}",
"url": "${{ fromJson(steps.create_service_request.outputs.response).service.html_url }}",
"oncall": ${{ env.user_emails }}
}
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: Log After 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: |
Upserting was successful ✅
Port Configuration
Create a new self service action using the following JSON configuration.
Create Service In PagerDuty (click to expand)
Make sure to replace <GITHUB_ORG>
and <GITHUB_REPO>
with your GitHub organization and repository names respectively.
{
"identifier": "pagerdutyService_create_service",
"title": "Create Service",
"icon": "pagerduty",
"description": "Create PagerDuty Service",
"trigger": {
"type": "self-service",
"operation": "CREATE",
"userInputs": {
"properties": {
"name": {
"title": "Name",
"description": "Name of the PagerDuty Service",
"icon": "pagerduty",
"type": "string"
},
"description": {
"title": "Description",
"description": "Description of the PagerDuty Service",
"icon": "pagerduty",
"type": "string"
},
"escalation_policy": {
"title": "Escalation Policy",
"description": "PagerDuty Escalation Policy ID to apply",
"icon": "pagerduty",
"type": "string"
}
},
"required": [
"name",
"escalation_policy"
],
"order": [
"name",
"description",
"escalation_policy"
]
},
"blueprintIdentifier": "pagerdutyService"
},
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB_ORG>",
"repo": "<GITHUB_REPO>",
"workflow": "create-a-service.yaml",
"workflowInputs": {
"name": "{{.inputs.\"name\"}}",
"description": "{{.inputs.\"description\"}}",
"escalation_policy": "{{.inputs.\"escalation_policy\"}}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}"
}
},
"reportWorkflowStatus": true
},
"requiredApproval": false,
"publish": true
}
Now you should see the Create Service
action in the self-service page. 🎉
Let's test it!
- Head to the Self Service hub
- Click on the
Create Service
action. - Enter the required data for
Name
,Description
(optional), andEscalation Policy
. - Click on
Execute
. - Done! wait for the incident's status to be changed in PagerDuty.
Congrats 🎉 You've created your first service
in PagerDuty from Port! 🔥