Skip to main content

Create PagerDuty Service Action

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

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

tip

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

GitHub Workflow
create-service.yaml
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 }}",
"escalation_policy": ${{ github.event.inputs.escalation_policy }}
}
}

- name: Create a log message
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 oncalls

- 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[]=${{ fromJson(github.event.inputs.escalation_policy).id }}'
method: 'GET'
customHeaders: '{"Content-Type": "application/json", "Accept": "application/json", "Authorization": "Token token=${{ secrets.PAGERDUTY_API_KEY }}"}'

- name: Create a log message
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 }}"
team: "[]"
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": "${{ fromJson(steps.fetch_oncalls).oncalls }}"
}
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: Create a log message
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: |
Upsert was successful ✅

Port Configuration

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

Create Service 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": "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": {
"{{if (.inputs | has(\"ref\")) then \"ref\" else null end}}": "{{.inputs.\"ref\"}}",
"{{if (.inputs | has(\"name\")) then \"name\" else null end}}": "{{.inputs.\"name\"}}",
"{{if (.inputs | has(\"description\")) then \"description\" else null end}}": "{{.inputs.\"description\"}}",
"{{if (.inputs | has(\"escalation_policy\")) then \"escalation_policy\" else null end}}": "{{.inputs.\"escalation_policy\"}}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity}}",
"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!

  1. Head to the Self Service hub
  2. Click on the Create Service action.
  3. Enter the required data for Name, Description (optional), and Escalation Policy.
  4. Click on Execute.
  5. Done! wait for the incident's status to be changed in PagerDuty.

Congrats 🎉 You've created your first service in PagerDuty from Port! 🔥

More Self Service PagerDuty Actions Examples