This article explains how to close Opsgenie alerts when the related Jira issue is moved to another project using Jira automation rules.
These automations work by triggering a POST request to the Opsgenie /close API endpoint when an issue is moved to a new project.
This is broken out into two rules:
These both need to be global automations (Settings > System > Global automation)
The summary of the automation rule looks like this:
The automation triggers when any issue is moved from the project where alerts are being sent. We also need a filter for the ‘fromOG’ label NOT being present because these issues were not created from Opsgenie alerts.
Our second automation rule (below) will cover the issues that WERE created from opsgenie alerts.
On the web request, we’ll use this URL:
https://api.opsgenie.com/v2/alerts/{{changelog.key.fromString.urlEncode}}/close?identifierType=alias
The smart value in the URL, {{changelog.key.fromString.urlEncode}}, will pull the original issue key and encode it for a URL.
In the headers, you’ll need to add an Authorization header from an API integration. The body will be custom data and just ‘{}’ in the field.
For alerts that were created by other integrations
Since alerts from other integrations won’t have the issue key as an alias, we need to add a step to first get that data from the alert.
The summary of the automation rule looks like this:
Time we’re filtering for the labels WITH ‘fromOG’, since these issues were created by Opsgenie.
The first web request is a GET to the alert API that lists alerts where the issue key is in the alert's details. Here is the URL:
https://api.opsgenie.com/v2/alerts?query=details.value%3A{{changelog.key.fromString.urlEncode}}
Now we can use the response from the previous step as an encoded smart value, which we'll send to the '/close' endpoint:
https://api.opsgenie.com/v2/alerts/{{webResponse.body.data.id}}/close
Now, all Opsgenie alerts linked to a Jira issue will be closed when any Jira issue is moved to a new project.
In order to ensure that we continue to provide useful content, please let us know if this Article is helpful (Thumbs Up/Down). Also, to help us improve, feel free to provide additional feedback (directly in the community).
John M
Support Engineer
Atlassian
111 accepted answers
1 comment