Create Opsgenie Incident
Overview
This self-service guide facilitates creating incidents in Opsgenie from Port using Port's self service actions. With this, you can manage incidents in opsgenie without leaving Port.
Prerequisites
- Port's GitHub app needs to be installed.
- 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 id
How to get the credentials.PORT_CLIENT_SECRET
- Your portclient secret
How 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.
Opsgenie Incident Blueprint
{
"identifier": "opsGenieIncident",
"description": "This blueprint represents an OpsGenie incident in our software catalog",
"title": "OpsGenie Incident",
"icon": "OpsGenie",
"schema": {
"properties": {
"description": {
"title": "Description",
"type": "string"
},
"status": {
"type": "string",
"title": "Status",
"enum": ["closed", "open", "resolved"],
"enumColors": {
"closed": "blue",
"open": "red",
"resolved": "green"
},
"description": "The status of the incident"
},
"url": {
"type": "string",
"format": "url",
"title": "URL"
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"title": "Tags"
},
"responders": {
"type": "array",
"title": "Responders",
"description": "Responders to the alert"
},
"priority": {
"type": "string",
"title": "Priority"
},
"createdAt": {
"title": "Create At",
"type": "string",
"format": "date-time"
},
"updatedAt": {
"title": "Updated At",
"type": "string",
"format": "date-time"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"services": {
"title": "Impacted Services",
"target": "opsGenieService",
"many": true,
"required": false
}
}
}
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.getport.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.getport.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.
{
"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": "trigger-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,
"publish": true
}
Let's test it!
- Head to the Self Service hub
- Click on the
Create Incident
action 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
Congrats 🎉 You've successfully created an incident in Opsgenie from Port 🔥