-
Suggestion
-
Resolution: Unresolved
-
None
-
1
-
Customers have asked if we can produce an integration that will forward alert actions from Opsgenie to JSM/Compass Operations.
They would like us to produce something similar to this existing Opsgenie to Opsgenie integration.
Workaround:
This workaround will require Linux server to run a basic script via OEC.
- Download the appropriate Linux OEC package from here and install it on your Linux server.
- Edit the file /home/opsgenie/oec/conf/config.json delete all the existing text and paste in the below config.
If your Opsgenie is hosted on EU subdomain change the baseUrl https://api.eu.opsgenie.com
Replace the following values below:
<API Key> replace this with the API key from the OEC integration in the source Opsgenie instance:
<Atlassian ID Email address> The Atlassian ID email address of user used to authenticate the JSM/Compass API.
<Atlassian API Token> Log into https://id.atlassian.com then visit https://id.atlassian.com/manage-profile/security/api-tokens to generate a API token.
<Atlassian Cloud ID> You can find the Cloud ID by following the instructions in this document.
<Jira/compass Team ID> browse to your destination team in JSM or Compass you will find the Team Id referenced in the URL of the team. If you are using JSM the team ID can be found here in the URL https://example.atlassian.net/jira/people/team/<Team ID>, else if you are using compass the team id is located here in the URL https://example.atlassian.net/compass/operations/<Team ID>/on-call.
{ "apiKey": "<API Key>", "baseUrl": "https://api.opsgenie.com", "logLevel": "DEBUG", "globalFlags": { "atlassianCredentials": "<Atlassian ID Email address>:<Atlassian API Token>", "atlassianCloudId": "<Atlassian Cloud ID>", "atlassianProduct": "compass", "destinationTeamId": "<Jira/compass Team ID>" }, "actionMappings": { "Create": { "filepath": "/home/opsgenie/oec/scripts/actionExecutor.sh", "sourceType": "local", "stdout": "/home/opsgenie/oec/output/output.txt", "stderr": "/home/opsgenie/oec/output/error.txt" }, "Acknowledge":{ "filepath": "/home/opsgenie/oec/scripts/actionExecutor.sh", "sourceType": "local", "stdout": "/home/opsgenie/oec/output/output.txt", "stderr": "/home/opsgenie/oec/output/error.txt" }, "Close":{ "filepath": "/home/opsgenie/oec/scripts/actionExecutor.sh", "sourceType": "local", "stdout": "/home/opsgenie/oec/output/output.txt", "stderr": "/home/opsgenie/oec/output/error.txt" }, "AddNote":{ "filepath": "/home/opsgenie/oec/scripts/actionExecutor.sh", "sourceType": "local", "stdout": "/home/opsgenie/oec/output/output.txt", "stderr": "/home/opsgenie/oec/output/error.txt" } }, "pollerConf": { "pollingWaitIntervalInMillis": 100, "visibilityTimeoutInSec": 30, "maxNumberOfMessages": 10 }, "poolConf": { "maxNumberOfWorker": 12, "minNumberOfWorker": 4, "monitoringPeriodInMillis": 15000, "keepAliveTimeInMillis": 6000, "queueSize": 0 } }
- Create a folder /home/opsgenie/oec/output
- create a file /home/opsgenie/oec/scripts/actionExecutor.sh edit the file and paste in the below content.
#!/bin/bash if test "${1}" = "-atlassianCredentials"; then atlassianCredentials=${2} elif test "${3}" = "-atlassianCredentials"; then atlassianCredentials=${4} elif test "${5}" = "-atlassianCredentials"; then atlassianCredentials=${6} elif test "${7}" = "-atlassianCredentials"; then atlassianCredentials=${8} fi if test "${1}" = "-atlassianCloudId"; then atlassianCloudId=${2} elif test "${3}" = "-atlassianCloudId"; then atlassianCloudId=${4} elif test "${5}" = "-atlassianCloudId"; then atlassianCloudId=${6} elif test "${7}" = "-atlassianCloudId"; then atlassianCloudId=${8} fi if test "${1}" = "-atlassianProduct"; then atlassianProduct=${2} elif test "${3}" = "-atlassianProduct"; then atlassianProduct=${4} elif test "${5}" = "-atlassianProduct"; then atlassianProduct=${6} elif test "${7}" = "-atlassianProduct"; then atlassianProduct=${8} fi if test "${1}" = "-destinationTeamId"; then destinationTeamId=${2} elif test "${3}" = "-destinationTeamId"; then destinationTeamId=${4} elif test "${5}" = "-destinationTeamId"; then destinationTeamId=${6} elif test "${7}" = "-destinationTeamId"; then destinationTeamId=${8} fi payload1=${10} apiKey=${12} sourceApiUrl=${14} payload=$(echo $payload1 | paste -sd "~" -) customerSubDomain=$(echo $payload | jq -r .customerDomain) if test "$sourceApiUrl" = "https://api.eu.opsgenie.com"; then appUrl="https://${customerSubDomain}.app.eu.opsgenie.com" else appUrl="https://${customerSubDomain}.app.opsgenie.com" fi if test "$atlassianProduct" = "jsm"; then atlassianProdcutUrl="https://api.atlassian.com/jsm/ops/api/${atlassianCloudId}/v1/alerts" elif test "$atlassianProduct" = "compass"; then atlassianProdcutUrl="https://api.atlassian.com/compass/cloud/${atlassianCloudId}/ops/v1/alerts" fi alertId=$(echo $payload | jq -r .params.alertId) oecAction=$(echo $payload | jq -r .action) alertMsg=$(echo $payload | jq -r .params.alert.message) alertData() { curl -X GET "${sourceApiUrl}/v2/alerts/${alertId}" -H "Content-Type: application/json" -H "Authorization: GenieKey ${apiKey}" | jq .data } alertData=$(alertData) alertDescription=$(echo $alertData | jq -r .description) alertSrc() { echo $payload | jq -r .params.alert.source } alertSource="Env: ${customerSubDomain} - Source: $(alertSrc)" alertTagArray=$(echo $payload | jq -r .params.alert.tags) alertDetailsList=$(echo $payload | jq -r .params.alertDetails) alertAlias=$(echo $payload | jq -r .params.alertAlias) alertActions=$(echo $payload | jq -r .params.alert.actions) alertPriority=$(echo $payload | jq -r .params.alert.priority) partnerAlertId=$(echo $payload | jq -r .params.alertDetails.partnerAlertId) case $oecAction in Create) body() { cat << EOF { "message": "$alertMsg", "tags": $alertTagArray, "extraProperties": $alertDetailsList, "alias": "$alertAlias", "actions": $alertActions, "description": "Original alert: $appUrl/alert/detail/$alertId/details\n\n$alertDescription", "source": "$alertSource", "priority": "$alertPriority", "responders": [{"id": "$destinationTeamId", "type": "team"}] } EOF } createAlert() { curl --request POST "${atlassianProdcutUrl}" --user "${atlassianCredentials}" --header "Content-Type: application/json" --header "Accept: application/json" --data "$(body)" } alertResponse=$(createAlert) requestId=$(echo $alertResponse | jq -r .requestId) echo $requestId sleep 0.5s destinationAlertId=$(curl --request GET "${atlassianProdcutUrl}/requests/${requestId}" --user "${atlassianCredentials}" --header "Content-Type: application/json" --header "Accept: application/json" | jq -r .alertId) echo $destinationAlertId body2() { cat << EOF { "details": { "partnerAlertId": "$destinationAlertId" } } EOF } curl -X POST "${sourceApiUrl}/v2/alerts/${alertId}/details" -H "Content-Type: application/json" -H "Authorization: GenieKey ${apiKey}" --data "$(body2)" ;; Acknowledge) curl --request POST "${atlassianProdcutUrl}/${partnerAlertId}/acknowledge" --user "${atlassianCredentials}" --header "Content-Type: application/json" --header "Accept: application/json" ;; Close) curl --request POST "${atlassianProdcutUrl}/${partnerAlertId}/close" --user "${atlassianCredentials}" --header "Content-Type: application/json" --header "Accept: application/json" ;; AddNote) note=$(echo $payload | jq -r .params.alert.note | sed 's^~~^\\n\\n^g') body3() { cat << EOF { "note": "$note" } EOF } echo $(body3) curl --request POST "${atlassianProdcutUrl}/${partnerAlertId}/notes" --user "${atlassianCredentials}" --header "Content-Type: application/json" --header "Accept: application/json" --data "$(body3)" ;; esac
- Once done you must grant execute permission on the file /home/opsgenie/oec/scripts/actionExecutor.sh
- Start the OEC service and trigger a test alert in the source Opsgenie.