In Part 1 – I have covered OpsGenie Email Integration - https://www.quest.com/community/blogs/b/performance-monitoring/posts/foglight-for-it-ops-a-genie-approach---foglight-email-integration-part-1 .
In Part 2 – let’s see how Foglight’s can forward alarms to OpsGenie using RestAPI call.
Dataflow and REST API Integration can be done in two steps.
- Using RestAPI - POST Method
- Invoking RestAPI using Foglight Rules
RestAPI calls can be used from either products, in this blog we will be sending alarms from Foglight to OpsGenie. As a first step you will need API key from OpsGenie
STEP 1 – OPSGENIE END
A few simple steps (screenshots below)
- Open OpsGenie | Goto Settings
- On the navigation pane, looks for Integrations List
- Create and configure Rest API integration
- Generate API Key
- Ensure correct permissions are set
- Read Access
- Create and Update Access
- Delete Access
- This step will involve matching Foglight Alarm fields
- OpsGenie Incident variables can be dragged and dropped into Alert field
- Tag them to a particular team e.g.: “L2 – Engineer” or “L1 – Engineer”
- Save your configuration settings.
STEP 2 – Test if the configuration works –– Use the sample script to test.
Java Script Example - Java_OpsGenie.java
import javax.xml.soap.*; URL url = new URL("https://api.eu.opsgenie.com/v1/incidents/create"); @Field byte[] out = data.getBytes(StandardCharsets.UTF_8); OutputStream stream = http.getOutputStream(); System.out.println(http.getResponseCode() + " " + http.getResponseMessage()); |
The example script posts the information into the following alert fields
"message": Incident message
"description": Description of the alert
"responders": Team responsible for the incident/alert
"tags": Tag Criticality
"details": Action to be taken
"priority": Priority of the incident/alert
"impactedServices": Services impacted
Additional Information: Please note: I have attached other script formats at the bottom of this page, either script can be used in order to create sample incidents in OpsGenie) JSON Code Example - JSONCode_OpsGenie.json For this step any SoapUI tools can be used to perform tests – one of my favourites that I use is postman https://www.postman.com/ and Reqbin https://reqbin.com, some other tools you may use SoapUI - https://www.soapui.org/ For additional read refer to Foglight RestAPI Reference Guide 6.1.0 - https://support.quest.com/technical-documents/foglight/6.1.0/rest-api-reference-guide#TOPIC-1771676 OpsGenie API Overview - https://docs.opsgenie.com/docs/api-overview OpsGenie Incident API - https://docs.opsgenie.com/docs/incident-api |
STEP 3 – FOGLIGHT END
As Foglight is a java based product, I have used java script for this example. Follow the steps below
Goto Foglight UI | Administration | All Rules | Copy over the Broadcast Alarm to OPSGenie_BroadcastAlarm
Expand Fire Condition | Paste the Java code | Test the Rule Logic to ensure there are no errors or issues.
Click Save .
RESULT - Alarms fired in Foglight will be sent as Incidents in OpsGenie (Output below)
That's it - Have a great day!!
Samples Scripts
import requests from requests.structures import CaseInsensitiveDict url = "https://api.eu.opsgenie.com/v1/incidents/create" headers = CaseInsensitiveDict() headers["Content-Type"] = "application/json" headers["Authorization"] = "GenieKey 82e970c1-XXXX-XXX-XXXX-XXXXXXXX" data = """ { "message": "An example incident message", "description":"Every incident needs a description", "responders":[ {"name":"FoglightOperators", "type":"team"}, {"id":"95f8ebdf-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "type":"team"} ], "tags": ["Outage","Critical"], "details":{ "Action to be taken": "L1 - Engineer", "Work to be assessed": "L2 - Engineer" }, "priority": "P1", "impactedServices": [ "38179dc9-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "0285467c-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ] } """ resp = requests.post(url, headers=headers, data=data) print(resp.status_code)
curl -X POST https://api.eu.opsgenie.com/v1/incidents/create -H "Content-Type: application/json" -H "Authorization: GenieKey 82e970c1-XXXX-XXX-XXXX-XXXXXXXX" -d '{ "message": "An example incident message", "description":"Every incident needs a description", "responders":[ {"name":"FoglightOperators", "type":"team"}, {"id":"95f8ebdf-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "type":"team"} ], "tags": ["Outage","Critical"], "details":{ "Action to be taken": "L1 - Engineer", "Work to be assessed": "L2 - Engineer" }, "priority": "P1", "impactedServices": [ "38179dc9-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "0285467c-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ] }'
import javax.xml.soap.*; import javax.xml.namespace.QName; import java.util.Iterator; import java.net.URL; import java.nio.charset.StandardCharsets; URL url = new URL("https://api.eu.opsgenie.com/v1/incidents/create"); HttpURLConnection http = (HttpURLConnection)url.openConnection(); http.setRequestMethod("POST"); http.setDoOutput(true); http.setRequestProperty("Content-Type", "application/json"); http.setRequestProperty("Authorization", "GenieKey 82e970c1-XXXX-XXX-XXXX-XXXXXXXX"); @Field String data = "{\n \"message\": \"From Foglight example incident message\",\n \"description\":\"Every incident needs a description\",\n \"responders\":[\n {\"name\":\"FoglightOperators\", \"type\":\"team\"},\n {\"id\":\"95f8ebdf-XXXX-XXXX-XXXX-XXXXXXXXXXXX\", \"type\":\"team\"} \n ],\n \"tags\": [\"Outage\",\"Critical\"],\n \"details\":{\n \"Action to be taken\": \"L1 - Engineer\",\n \"Work to be assessed\": \"L2 - Engineer\"\n },\n \"priority\": \"P1\",\n \"impactedServices\": [\n \"38179dc9-XXXX-XXXX-XXXX-XXXXXXXXXXXX\", \n \"0285467c-XXXX-XXXX-XXXX-XXXXXXXXXXXX\"\n ]\n}"; byte[] out = data.getBytes(StandardCharsets.UTF_8); OutputStream stream = http.getOutputStream(); stream.write(out); System.out.println(http.getResponseCode() + " " + http.getResponseMessage()); http.disconnect();