Skip to main content

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​

  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 Opsgenie integration learn more
Opsgenie 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 opsgenie incidents.

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

tip

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

GitHub Workflow
create-opsgenie-incident.yml
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_payload:
required: true
description: Port's payload, including details for who triggered the action and
general context (blueprint, run id, etc...)
type: string
secrets:
OPSGENIE_API_KEY:
required: true
PORT_CLIENT_ID:
required: true
PORT_CLIENT_SECRET:
required: true
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_payload).context.runId}}
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_payload).context.runId}}
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)
Modification Required

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": {
"{{if (.inputs | has(\"ref\")) then \"ref\" else null end}}": "{{.inputs.\"ref\"}}",
"{{if (.inputs | has(\"message\")) then \"message\" else null end}}": "{{.inputs.\"message\"}}",
"{{if (.inputs | has(\"description\")) then \"description\" else null end}}": "{{.inputs.\"description\"}}",
"{{if (.inputs | has(\"responders\")) then \"responders\" else null end}}": "{{.inputs.\"responders\"}}",
"{{if (.inputs | has(\"tags\")) then \"tags\" else null end}}": "{{.inputs.\"tags\"}}",
"{{if (.inputs | has(\"details\")) then \"details\" else null end}}": "{{.inputs.\"details\"}}",
"{{if (.inputs | has(\"priority\")) then \"priority\" else null end}}": "{{.inputs.\"priority\"}}",
"{{if (.inputs | has(\"note\")) then \"note\" else null end}}": "{{.inputs.\"note\"}}",
"{{if (.inputs | has(\"impactedServices\")) then \"impactedServices\" else null end}}": "{{.inputs.\"impactedServices\"}}",
"{{if (.inputs | has(\"notifyStakeholders\")) then \"notifyStakeholders\" else null end}}": "{{.inputs.\"notifyStakeholders\"}}",
"port_payload": {
"action": "{{ .action.identifier[(\"opsGenieIncident_\" | length):] }}",
"resourceType": "run",
"status": "TRIGGERED",
"trigger": "{{ .trigger | {by, origin, at} }}",
"context": {
"entity": "{{.entity.identifier}}",
"blueprint": "{{.action.blueprint}}",
"runId": "{{.run.id}}"
},
"payload": {
"entity": "{{ (if .entity == {} then null else .entity end) }}",
"action": {
"invocationMethod": {
"type": "GITHUB",
"repo": "<Enter GitHub repository>",
"org": "<Enter GitHub organization>",
"workflow": "trigger-opsgenie-incident.yml",
"omitUserInputs": false,
"omitPayload": false,
"reportWorkflowStatus": true
},
"trigger": "{{.trigger.operation}}"
},
"properties": {
"{{if (.inputs | has(\"message\")) then \"message\" else null end}}": "{{.inputs.\"message\"}}",
"{{if (.inputs | has(\"description\")) then \"description\" else null end}}": "{{.inputs.\"description\"}}",
"{{if (.inputs | has(\"responders\")) then \"responders\" else null end}}": "{{.inputs.\"responders\"}}",
"{{if (.inputs | has(\"tags\")) then \"tags\" else null end}}": "{{.inputs.\"tags\"}}",
"{{if (.inputs | has(\"details\")) then \"details\" else null end}}": "{{.inputs.\"details\"}}",
"{{if (.inputs | has(\"priority\")) then \"priority\" else null end}}": "{{.inputs.\"priority\"}}",
"{{if (.inputs | has(\"note\")) then \"note\" else null end}}": "{{.inputs.\"note\"}}",
"{{if (.inputs | has(\"impactedServices\")) then \"impactedServices\" else null end}}": "{{.inputs.\"impactedServices\"}}",
"{{if (.inputs | has(\"notifyStakeholders\")) then \"notifyStakeholders\" else null end}}": "{{.inputs.\"notifyStakeholders\"}}"
},
"censoredProperties": "{{.action.encryptedProperties}}"
}
}
},
"reportWorkflowStatus": true
},
"requiredApproval": false,
"publish": true
}

Let's test it!​

  1. Head to the Self Service hub
  2. Click on the Create Incident action for opsgenie
  3. Enter the required details in the input fields
  4. Click on Execute
  5. 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 🔥