Skip to main content

Check out Port for yourselfย 

Create a PagerDuty Incident

Overviewโ€‹

This guide will help you implement a self-service action in Port that allows you to create PagerDuty incidents directly from Port. This functionality streamlines incident management by enabling users to create incidents without leaving Port.

You can implement this action in two ways:

  1. GitHub workflow: A more flexible approach that allows for complex workflows and custom logic, suitable for teams that want to maintain their automation in Git.
  2. Synced webhooks: A simpler approach that directly interacts with PagerDuty's API through Port, ideal for quick implementation and minimal setup.

Prerequisitesโ€‹

  • Complete the onboarding process.

  • Access to your PagerDuty organization with permissions to manage incidents.

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

Set up data modelโ€‹

If you haven't installed the PagerDuty integration, you'll need to create blueprints for PagerDuty incidents and PagerDuty services. However, we highly recommend you install the PagerDuty integration to have these automatically set up for you.

Create the PagerDuty service blueprintโ€‹

  1. Go to your Builder page.

  2. Click on + Blueprint.

  3. Click on the {...} button in the top right corner, and choose "Edit JSON".

  4. Add this JSON schema:

    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": {
    "description": {
    "type": "string",
    "title": "Description"
    },
    "status": {
    "type": "string",
    "title": "Status",
    "enum": ["active", "warning", "critical", "maintenance", "disabled"]
    },
    "url": {
    "type": "string",
    "format": "url",
    "title": "Service URL"
    },
    "created_at": {
    "type": "string",
    "format": "date-time",
    "title": "Created At"
    },
    "updated_at": {
    "type": "string",
    "format": "date-time",
    "title": "Updated At"
    }
    },
    "required": []
    },
    "mirrorProperties": {},
    "calculationProperties": {},
    "relations": {}
    }
  5. Click "Save" to create the blueprint.

Create the PagerDuty incident blueprintโ€‹

  1. Go to your Builder page.

  2. Click on + Blueprint.

  3. Click on the {...} button in the top right corner, and choose "Edit JSON".

  4. Add this JSON schema:

    PagerDuty Incident Blueprint (Click to expand)
    {
    "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
    }
    }
    }
  5. Click "Save" to create the blueprint.

GitHub workflow implementationโ€‹

Add GitHub secretsโ€‹

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

Add GitHub workflowโ€‹

Create the file .github/workflows/create-pagerduty-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 (Click to expand)
name: Create PagerDuty Incident

on:
workflow_dispatch:
inputs:
title:
description: The title of the incident to create
required: true
type: string
extra_details:
description: Extra details about the incident to create
required: false
urgency:
description: The urgency of the incident
required: false
from:
description: The email address of a valid user associated with the account making the request.
required: true
port_context:
required: true
description: includes blueprint, run ID, and entity identifier from Port.
jobs:
trigger:
runs-on: ubuntu-latest
steps:
- uses: port-labs/pagerduty-incident-gha@v1
with:
portClientId: ${{ secrets.PORT_CLIENT_ID }}
portClientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
token: ${{ secrets.PAGERDUTY_API_KEY }}
portRunId: ${{fromJson(inputs.port_context).run_id}}
incidentTitle: "${{ inputs.title }}"
extraDetails: "${{ inputs.extra_details }}"
urgency: "${{ inputs.urgency }}"
actorEmail: "${{ inputs.from }}"
service: "${{fromJson(inputs.port_context).entity}}"
blueprintIdentifier: 'pagerdutyIncident'

Set up self-service actionโ€‹

We will create a self-service action to handle creating PagerDuty incidents. To create a self-service action follow these steps:

  1. Head to the self-service page.

  2. Click on the + New Action button.

  3. Click on the {...} Edit JSON button.

  4. Copy and paste the following JSON configuration into the editor.

    Create PagerDuty Incident (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_incident",
    "title": "Create Incident",
    "icon": "pagerduty",
    "description": "Create a new PagerDuty incident",
    "trigger": {
    "type": "self-service",
    "operation": "DAY-2",
    "userInputs": {
    "properties": {
    "title": {
    "icon": "DefaultProperty",
    "title": "Title",
    "type": "string"
    },
    "extra_details": {
    "title": "Extra Details",
    "type": "string"
    },
    "urgency": {
    "icon": "DefaultProperty",
    "title": "Urgency",
    "type": "string",
    "default": "high",
    "enum": [
    "high",
    "low"
    ],
    "enumColors": {
    "high": "yellow",
    "low": "green"
    }
    },
    "from": {
    "title": "From",
    "icon": "User",
    "type": "string",
    "format": "user",
    "default": {
    "jqQuery": ".user.email"
    }
    }
    },
    "required": [
    "title",
    "urgency",
    "from"
    ],
    "order": [
    "title",
    "urgency",
    "from",
    "extra_details"
    ]
    },
    "blueprintIdentifier": "pagerdutyService"
    },
    "invocationMethod": {
    "type": "GITHUB",
    "org": "<GITHUB_ORG>",
    "repo": "<GITHUB_REPO>",
    "workflow": "create-pagerduty-incident.yaml",
    "workflowInputs": {
    "title": "{{.inputs.\"title\"}}",
    "extra_details": "{{.inputs.\"extra_details\"}}",
    "urgency": "{{.inputs.\"urgency\"}}",
    "from": "{{.inputs.\"from\"}}",
    "port_context": {
    "blueprint": "{{.action.blueprint}}",
    "entity": "{{.entity.identifier}}",
    "run_id": "{{.run.id}}",
    "relations": "{{.entity.relations}}"
    }
    },
    "reportWorkflowStatus": true
    },
    "requiredApproval": false
    }
  5. Click Save.

Now you should see the Create Incident action in the self-service page. ๐ŸŽ‰

Synced webhook implementationโ€‹

Add Port secretsโ€‹

Add the following secrets to your Port account:

  1. In your portal, click on the ... button next to the profile icon in the top right corner.

  2. Click on Credentials.

  3. Click on the Secrets tab.

  4. Click on + Secret and add the following secrets:

    • PAGERDUTY_API_TOKEN: Your PagerDuty API token
    • PAGERDUTY_USER_EMAIL: The email of the PagerDuty user that owns the API token

Set up self-service actionโ€‹

We will create a self-service action to handle creating PagerDuty incidents using webhooks. To create a self-service action follow these steps:

  1. Head to the self-service page.

  2. Click on the + New Action button.

  3. Click on the {...} Edit JSON button.

  4. Copy and paste the following JSON configuration into the editor.

    Create PagerDuty Incident (Webhook) (Click to expand)
    {
    "identifier": "create_incident_webhook",
    "title": "Create Incident (Webhook)",
    "icon": "pagerduty",
    "description": "Create a new PagerDuty incident",
    "trigger": {
    "type": "self-service",
    "operation": "DAY-2",
    "userInputs": {
    "properties": {
    "title": {
    "icon": "DefaultProperty",
    "title": "Title",
    "type": "string"
    },
    "extra_details": {
    "title": "Extra Details",
    "type": "string"
    },
    "urgency": {
    "icon": "DefaultProperty",
    "title": "Urgency",
    "type": "string",
    "default": "high",
    "enum": [
    "high",
    "low"
    ],
    "enumColors": {
    "high": "yellow",
    "low": "green"
    }
    }
    },
    "required": [
    "title",
    "urgency"
    ],
    "order": [
    "title",
    "urgency",
    "extra_details"
    ]
    },
    "blueprintIdentifier": "pagerdutyService"
    },
    "invocationMethod": {
    "type": "WEBHOOK",
    "url": "https://api.pagerduty.com/incidents",
    "agent": false,
    "synchronized": true,
    "method": "POST",
    "headers": {
    "Authorization": "Token token={{.secrets.PAGERDUTY_API_TOKEN}}",
    "Accept": "application/vnd.pagerduty+json;version=2",
    "From": "{{.secrets.PAGERDUTY_USER_EMAIL}}",
    "Content-Type": "application/json"
    },
    "body": {
    "incident": {
    "type": "incident",
    "title": "{{.inputs.title}}",
    "service": {
    "id": "{{.entity.identifier}}",
    "type": "service_reference"
    },
    "urgency": "{{.inputs.urgency}}",
    "body": {
    "type": "incident_body",
    "details": "{{.inputs.extra_details}}"
    }
    }
    }
    },
    "requiredApproval": false
    }
  5. Click Save.

Now you should see the Create Incident (Webhook) action in the self-service page. ๐ŸŽ‰

Create an automation to upsert entity in portโ€‹

After each execution of the action, we would like to update the relevant entity in Port with the latest status.

To achieve this, we can create an automation that will be triggered when the action completes successfully.

To create the automation:

  1. Head to the automation page.

  2. Click on the + Automation button.

  3. Copy and paste the following JSON configuration into the editor.

    Update PagerDuty incident in Port automation (Click to expand)
        {
    "identifier": "pagerdutyIncident_sync_status",
    "title": "Sync PagerDuty Incident Status",
    "description": "Update PagerDuty incident data in Port after creation",
    "trigger": {
    "type": "automation",
    "event": {
    "type": "RUN_UPDATED",
    "actionIdentifier": "create_incident_webhook"
    },
    "condition": {
    "type": "JQ",
    "expressions": [
    ".diff.after.status == \"SUCCESS\""
    ],
    "combinator": "and"
    }
    },
    "invocationMethod": {
    "type": "UPSERT_ENTITY",
    "blueprintIdentifier": "pagerdutyIncident",
    "mapping": {
    "identifier": "{{.event.diff.after.response.incident.id}}",
    "title": "{{.event.diff.after.response.incident.title}}",
    "properties": {
    "status": "{{.event.diff.after.response.incident.status}}",
    "url": "{{.event.diff.after.response.incident.self}}",
    "urgency": "{{.event.diff.after.response.incident.urgency}}",
    "responder": "{{.event.diff.after.response.incident.assignments.0.assignee.summary}}",
    "escalation_policy": "{{.event.diff.after.response.incident.escalation_policy.summary}}",
    "created_at": "{{.event.diff.after.response.incident.created_at}}",
    "updated_at": "{{.event.diff.after.response.incident.updated_at}}"
    },
    "relations": {
    "pagerdutyService": ["{{.event.diff.after.response.incident.service.id}}"]
    }
    }
    },
    "publish": true
    }
  4. Click Save.

Now when you execute the webhook action, the incident data in Port will be automatically updated with the latest information from PagerDuty.

Let's test it!โ€‹

  1. Head to the self-service page of your portal

  2. Choose either the GitHub workflow or webhook implementation:

    • For GitHub workflow: Click on Create Incident
    • For webhook: Click on Create Incident (Webhook)
  3. Select the PagerDuty service where you want to create the incident

  4. Enter the required information:

    • For GitHub workflow: Enter the incident title, service, and optionally include extra details and urgency
    • For webhook: Enter the incident title and urgency, optionally include extra details
  5. Click on Execute

  6. Done! Wait for the incident to be created in PagerDuty

Congrats ๐ŸŽ‰ You've created a PagerDuty incident in Port ๐Ÿ”ฅ

More Self Service PagerDuty Actions Examplesโ€‹