Skip to main content

Check out Port for yourselfย 

Resolve an Incident in PagerDuty

Overviewโ€‹

This guide will help you implement a self-service action in Port that allows you to resolve PagerDuty incidents directly from Port. This functionality streamlines incident management by enabling users to resolve 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 incident blueprint

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

Implementationโ€‹

You can resolve PagerDuty incidents by leveraging Port's synced webhooks and secrets to directly interact with the PagerDuty's API. This method simplifies the setup by handling everything within Port.

Add Port secrets

Existing secrets

If you have already installed Port's PagerDuty integration, these secrets should already exist in your portal.
To view your existing secrets:

  1. Click on the ... button in the top right corner of your Port application.
  2. Choose Credentials, then click on the Secrets tab.

To add these secrets to your portal:

  1. Click on the ... button in the top right corner of your Port application.

  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

Follow these steps to create the self-service action:

  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.

    Resolve PagerDuty Incident (Webhook) (Click to expand)
    {
    "identifier": "resolve_incident_webhook",
    "title": "Resolve Incident (Webhook)",
    "icon": "pagerduty",
    "description": "Resolve a PagerDuty incident",
    "trigger": {
    "type": "self-service",
    "operation": "DAY-2",
    "userInputs": {
    "properties": {
    "from": {
    "icon": "User",
    "title": "From",
    "description": "The email address of a valid PagerDuty user associated with the account making the request.",
    "type": "string",
    "format": "user",
    "default": {
    "jqQuery": ".user.email"
    }
    }
    },
    "required": [
    "from"
    ],
    "order": [
    "from"
    ]
    },
    "blueprintIdentifier": "pagerdutyIncident"
    },
    "invocationMethod": {
    "type": "WEBHOOK",
    "url": "https://api.pagerduty.com/incidents",
    "agent": false,
    "synchronized": true,
    "method": "PUT",
    "headers": {
    "Authorization": "Token token={{.secrets.PAGERDUTY_API_TOKEN}}",
    "Accept": "application/vnd.pagerduty+json;version=2",
    "From": "{{.inputs.from}}",
    "Content-Type": "application/json"
    },
    "body": {
    "incidents": [
    {
    "id": "{{.entity.identifier}}",
    "type": "incident_reference",
    "status": "resolved"
    }
    ]
    }
    },
    "requiredApproval": false
    }
  5. Click Save.

Now you should see the Resolve 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 resolution",
    "trigger": {
    "type": "automation",
    "event": {
    "type": "RUN_UPDATED",
    "actionIdentifier": "resolve_incident_webhook"
    },
    "condition": {
    "type": "JQ",
    "expressions": [
    ".diff.after.status == \"SUCCESS\""
    ],
    "combinator": "and"
    }
    },
    "invocationMethod": {
    "type": "UPSERT_ENTITY",
    "blueprintIdentifier": "pagerdutyIncident",
    "mapping": {
    "identifier": "{{.event.diff.after.entity.identifier}}",
    "title": "{{.event.diff.after.entity.title}}",
    "properties": {
    "status": "resolved",
    "updated_at": "{{.event.diff.after.endedAt}}"
    }
    }
    },
    "publish": true
    }
  4. Click Save.

Now when you execute the webhook action, the incident data in Port will be automatically updated to show it as resolved.

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 Resolve Incident
    • For webhook: Click on Resolve Incident (Webhook)
  3. Select the PagerDuty incident you want to resolve

  4. Enter the required information:

    • From (email address of a valid PagerDuty user)
  5. Click on Execute

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

More Self Service PagerDuty Actions Examplesโ€‹