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.

  1. Using RestAPI - POST Method
  2. 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)

  1. Open OpsGenie | Goto Settings
  2. On the navigation pane, looks for Integrations List
  3. Create and configure Rest API integration
  4. Generate API Key
  5. Ensure correct permissions are set
    1. Read Access
    2. Create and Update Access
    3. Delete Access
  6. This step will involve matching Foglight Alarm fields
  7. OpsGenie Incident variables can be dragged and dropped into Alert field
  8. Tag them to a particular team e.g.: “L2 – Engineer” or “L1 – Engineer”
  9. 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.*;
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();

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
Python Example  - PythonCode_OpsGenie.py
Shell Script Example - ShellScript_OpsGenie.bash

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/
SmartBear - https://smartbear.com/ppc/ready-api/soapui/

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 

ShellScript_OpsGenie.bash       

PythonCode_OpsGenie.py
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)
     
JSONCode_OpsGenie.json
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"
    ]
}'
     
Java_OpsGenie.java
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();

Anonymous
Related Content