When working with JSM Incidents there is no way to automatically link Opsgenie Alerts to JSM Incidents. Or is there?
With the new Incident REST API and the Opsgenie Alerts API, we can GET Alerts and also link alerts using two API requests.
In this example, we will be using a Manually triggered rule to first get the Opsgenie Alerts where the Status is Open and there is a message of intermittent. This default value set on the Manually Triggered Automation Rule will look for Alerts that meet this criteria. Please note that this default value can be changed based on your use case and if you want to look at the message/status, or other values on the Alerts:
Default Value for User Inputs
status: open AND message: intermittent
Smart Value for Manually Triggered Rule
{{userInputs.alertsQuery}}
Then we will be using a GET request to get the Alerts to later link using the following Web request URL. Please be sure that the smart value from the Manual Trigger is used for the query, and then url Encode the request URL, similar to below:
https://api.opsgenie.com/v2/alerts?query={{userInputs.alertsQuery.urlEncode}}
You will also need to get a Genie Key from an Opsgenie API integration to authorize the API request and get the Alerts:
Lastly, we will link the alerts to the JSM Incident dynamically using the following POST web request URL. Please be sure to use your own cloud for your Jira site with experimental API headers, using Basic Authorization:
https://api.atlassian.com/jsm/incidents/cloudId/<cloud_id>/v1/incident/{{id}}/alert/add
X-ExperimentalApi opt-in
Authorization Basic <api_key>
Also, here is the custom JSON data you want to pull in the web response data from the previous API GET request:
{ "alertIds": {{webResponse.body.values.id.asJsonStringArray}} }
Create an API integration -https://support.atlassian.com/opsgenie/docs/create-a-default-api-integration/
Christian Beaulieu
JSM Support Engineer 3
Atlassian
Phoenix, Arizona
2 accepted answers
4 comments