Create Opsgenie Incident
This guide demonstrates how to create a self-service action in Port that executes a GitHub workflow to create an Opsgenie incident. With this, you can manage incidents in Opsgenie without leaving Port.
- For GitHub (Legacy), see the GitHub workflow documentation.
- For GitHub (Ocean), see the GitHub Ocean workflow documentation.
Prerequisites
-
Install the Ports GitHub app or Port's GitHub ocean.
-
In your GitHub repository, go to Settings > Secrets and add the following secrets:
OPSGENIE_API_KEY- OPSGENIE API KEY generated by the user.PORT_CLIENT_ID- Your portclient idHow to get the credentials.PORT_CLIENT_SECRET- Your portclient secretHow to get the credentials.
-
Optional - Install Port's Opsgenie integration learn more
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 opsgenie incidents.
- In Case you decided not to install the Opsgenie integration, you will need to create a blueprint for the Opsgenie incident in Port.
Set up data model
We need to create a blueprint in Port for the Opsgenie incident. Follow the steps below to create the blueprint:
-
Go to the Builder page of your portal.
-
Click on
+ Blueprint. -
Click on the
{...}button in the top right corner, and chooseEdit JSON. -
Copy and paste the following JSON schema:
Opsgenie Incident Blueprint (click to expand)
{
"identifier": "opsGenieIncident",
"title": "Opsgenie Incident",
"description": "This blueprint represents an incident in Opsgenie, capturing all relevant fields for incident management and response.",
"icon": "OpsGenie",
"schema": {
"properties": {
"description": {
"title": "Description",
"description": "Detailed information about the incident.",
"type": "string",
"icon": "OpsGenie",
"maxLength": 15000
},
"url": {
"type": "string",
"format": "url",
"title": "Incident URL",
"description": "Direct link to the incident in Opsgenie."
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"title": "Tags",
"description": "Labels or tags related to the incident."
},
"responders": {
"type": "array",
"title": "Responders",
"description": "Entities responsible for handling the incident."
},
"priority": {
"type": "string",
"title": "Priority",
"description": "Incident priority as defined in Opsgenie.",
"enum": ["P1", "P2", "P3", "P4", "P5"],
"enumColors": {
"P1": "red",
"P2": "orange",
"P3": "yellow",
"P4": "blue",
"P5": "gray"
}
},
"createdAt": {
"title": "Created At",
"type": "string",
"format": "date-time",
"description": "Timestamp when the incident was created."
},
"updatedAt": {
"title": "Updated At",
"type": "string",
"format": "date-time",
"description": "Timestamp for the last update to the incident."
}
},
"required": ["description", "priority", "createdAt"]
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"services": {
"title": "Impacted Services",
"target": "opsGenieService",
"many": true,
"required": false,
"description": "Services that are impacted by this incident."
}
}
}
GitHub Workflow
Create the file .github/workflows/create-opsgenie-incident.yml 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 Opsgenie Incident
on:
workflow_dispatch:
inputs:
message:
type: string
required: true
description:
type: string
required: false
responders:
type: string
required: false
tags:
type: string
required: false
details:
type: string
required: false
priority:
required: false
type: string
note:
required: false
type: string
impactedServices:
required: false
type: string
notifyStakeholders:
required: false
type: boolean
port_context:
required: true
description: includes blueprint, run ID, and entity identifier from Port.
jobs:
create-entity-in-port-and-update-run:
runs-on: ubuntu-latest
steps:
- name: Inform start of Opsgenie incident creation
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.port.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: Starting request to create Opsgenie incident
- name: Create a Opsgenie incident
uses: fjogeleit/http-request-action@v1
with:
url: "https://api.opsgenie.com/v1/incidents/create"
method: "POST"
customHeaders: '{"Content-Type": "application/json", "Authorization": "GenieKey ${{ secrets.OPSGENIE_API_KEY }}"}'
data: '{"message": "${{ inputs.message }}", "description": "${{ inputs.description }}", "responders": ${{ inputs.responders }}, "tags": ${{ inputs.tags }}, "details": ${{ inputs.details }}, "priority": "${{ inputs.priority }}", "note": "${{ inputs.note }}", "impactedServices": ${{ inputs.impactedServices }}, "notifyStakeholders": ${{ inputs.notifyStakeholders }}}'
- name: Inform completion of Opsgenie incident creation
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.port.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: Finished request to create Opsgenie incident
Port Configuration
Create a new self service action using the following JSON configuration.
Create an Opsgenie Incident (Click to expand)
Make sure to replace <GITHUB_ORG> and <GITHUB_REPO> with your GitHub organization and repository names respectively.
- GitHub (Legacy)
- GitHub (Ocean)
{
"identifier": "opsGenieIncident_create_incident",
"title": "Create Incident",
"icon": "OpsGenie",
"description": "Triggers Opsgenie incident",
"trigger": {
"type": "self-service",
"operation": "CREATE",
"userInputs": {
"properties": {
"message": {
"icon": "OpsGenie",
"title": "Message",
"description": "Message of the incident",
"type": "string",
"maxLength": 130
},
"description": {
"title": "Description",
"description": "Description field of the incident that is generally used to provide a detailed information about the incident.",
"type": "string",
"icon": "OpsGenie",
"maxLength": 15000
},
"responders": {
"items": {
"type": "object"
},
"title": "Responders",
"description": "Teams/users that the incident is routed to via notifications. type field is mandatory for each item, where possible values are team, user.",
"type": "array",
"icon": "OpsGenie"
},
"tags": {
"items": {
"type": "string",
"maxLength": 50
},
"title": "Tags",
"description": "Tags of the incident.",
"type": "array",
"icon": "OpsGenie"
},
"details": {
"title": "Details",
"description": "Map of key-value pairs to use as custom properties of the incident.",
"type": "object",
"icon": "OpsGenie"
},
"priority": {
"title": "Priority",
"icon": "OpsGenie",
"description": "Priority level of the incident. Possible values are P1, P2, P3, P4 and P5. Default value is P3.",
"type": "string",
"default": "P3",
"enum": [
"P1",
"P2",
"P3",
"P4",
"P5"
],
"enumColors": {
"P1": "lightGray",
"P2": "lightGray",
"P3": "lightGray",
"P4": "lightGray",
"P5": "lightGray"
}
},
"note": {
"icon": "OpsGenie",
"title": "Note",
"description": "Additional note that is added while creating the incident.",
"type": "string",
"maxLength": 25000
},
"impactedServices": {
"title": "Impacted Services",
"description": "Services on which incident will be created.",
"icon": "OpsGenie",
"type": "array",
"items": {
"type": "string",
"format": "entity",
"blueprint": "opsGenieService"
}
},
"notifyStakeholders": {
"icon": "OpsGenie",
"title": "Notify Stakeholders",
"description": "Indicate whether stakeholders are notified or not. Default value is false.",
"type": "boolean",
"default": false
}
},
"required": [
"message"
],
"order": [
"message",
"description",
"responders",
"tags",
"details",
"priority",
"note",
"impactedServices",
"notifyStakeholders"
]
},
"blueprintIdentifier": "opsGenieIncident"
},
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB_ORG>",
"repo": "<GITHUB_REPO>",
"workflow": "create-opsgenie-incident.yml",
"workflowInputs": {
"message": "{{.inputs.\"message\"}}",
"description": "{{.inputs.\"description\"}}",
"responders": "{{.inputs.\"responders\"}}",
"tags": "{{.inputs.\"tags\"}}",
"details": "{{.inputs.\"details\"}}",
"priority": "{{.inputs.\"priority\"}}",
"note": "{{.inputs.\"note\"}}",
"impactedServices": "{{.inputs.\"impactedServices\"}}",
"notifyStakeholders": "{{.inputs.\"notifyStakeholders\"}}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}"
}
},
"reportWorkflowStatus": true
},
"requiredApproval": false
}
{
"identifier": "opsGenieIncident_create_incident",
"title": "Create Incident",
"icon": "OpsGenie",
"description": "Triggers Opsgenie incident",
"trigger": {
"type": "self-service",
"operation": "CREATE",
"userInputs": {
"properties": {
"message": {
"icon": "OpsGenie",
"title": "Message",
"description": "Message of the incident",
"type": "string",
"maxLength": 130
},
"description": {
"title": "Description",
"description": "Description field of the incident that is generally used to provide a detailed information about the incident.",
"type": "string",
"icon": "OpsGenie",
"maxLength": 15000
},
"responders": {
"items": {
"type": "object"
},
"title": "Responders",
"description": "Teams/users that the incident is routed to via notifications. type field is mandatory for each item, where possible values are team, user.",
"type": "array",
"icon": "OpsGenie"
},
"tags": {
"items": {
"type": "string",
"maxLength": 50
},
"title": "Tags",
"description": "Tags of the incident.",
"type": "array",
"icon": "OpsGenie"
},
"details": {
"title": "Details",
"description": "Map of key-value pairs to use as custom properties of the incident.",
"type": "object",
"icon": "OpsGenie"
},
"priority": {
"title": "Priority",
"icon": "OpsGenie",
"description": "Priority level of the incident. Possible values are P1, P2, P3, P4 and P5. Default value is P3.",
"type": "string",
"default": "P3",
"enum": [
"P1",
"P2",
"P3",
"P4",
"P5"
],
"enumColors": {
"P1": "lightGray",
"P2": "lightGray",
"P3": "lightGray",
"P4": "lightGray",
"P5": "lightGray"
}
},
"note": {
"icon": "OpsGenie",
"title": "Note",
"description": "Additional note that is added while creating the incident.",
"type": "string",
"maxLength": 25000
},
"impactedServices": {
"title": "Impacted Services",
"description": "Services on which incident will be created.",
"icon": "OpsGenie",
"type": "array",
"items": {
"type": "string",
"format": "entity",
"blueprint": "opsGenieService"
}
},
"notifyStakeholders": {
"icon": "OpsGenie",
"title": "Notify Stakeholders",
"description": "Indicate whether stakeholders are notified or not. Default value is false.",
"type": "boolean",
"default": false
}
},
"required": [
"message"
],
"order": [
"message",
"description",
"responders",
"tags",
"details",
"priority",
"note",
"impactedServices",
"notifyStakeholders"
]
},
"blueprintIdentifier": "opsGenieIncident"
},
"invocationMethod": {
"type": "INTEGRATION_ACTION",
"installationId": "<YOUR_GITHUB_OCEAN_INTEGRATION_ID>",
"integrationActionType": "dispatch_workflow",
"integrationActionExecutionProperties": {
"org": "<GITHUB-ORG>",
"repo": "<GITHUB-REPO-NAME>",
"workflow": "create-opsgenie-incident.yml",
"workflowInputs": {
"message": "{{.inputs.\"message\"}}",
"description": "{{.inputs.\"description\"}}",
"responders": "{{.inputs.\"responders\"}}",
"tags": "{{.inputs.\"tags\"}}",
"details": "{{.inputs.\"details\"}}",
"priority": "{{.inputs.\"priority\"}}",
"note": "{{.inputs.\"note\"}}",
"impactedServices": "{{.inputs.\"impactedServices\"}}",
"notifyStakeholders": "{{.inputs.\"notifyStakeholders\"}}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}"
}
},
"reportWorkflowStatus": true
}
},
"requiredApproval": false
}
Let's test it!
- Head to the Self Service hub.
- Click on the
Create Incidentaction for opsgenie. - Enter the required details in the input fields.
- Click on
Execute. - Done! wait for the ticket's status and assignee to be changed in Jira.