In Part 2 – I have covered how to forward Foglight alarms to OpsGenie using RestAPI. (please see the link below)
https://www.quest.com/community/blogs/b/performance-monitoring/posts/foglight-for-it-ops-a-genie-approach-for-foglight-alarm-integration-part-2-restapi-integration

In Part 3 – let’s see how to use Foglight alarm variables and how they can be mapped to OpsGenie’s Alarm fields and priority (eg: P1, P2, P3…)
(Note: Same steps can be applied to any IT OPS tool or ticketing system)

As the Foglight’s “Broadcast Alarm” is an event driven rule and uses “AlarmSystemEvent” type – in this example we will use basic Foglight Alarm parameters like alarm source name, message and its severity. We will call basic parameters as follows in order to map with Opsgenie’s fields (-> source, message, description and priority)

Foglight Alarm Parameters

OpsGenie Fields

src="Foglight Alarm Source: "+@event.sourceName

sev=@event_foglight_severity_level_name

msg1="Foglight Alert: +@event.message+ "+@event_foglight_rule_alarm_link

msg="Foglight has a "+@event_foglight_severity_level_name+" message ::"+@event.message

src – Used for “Alarm Source” field

sev/sev1 – Used for “Priority” field

msg1 – Used for “Description” field

msg – Used for “message” field

To map to OpsGenie's alarm priority – you can add a simple “if condition” to match to Foglight’s Alarm severity.
(Note: You may add more flavour to the “if condition” i.e. to map to specific set of rules or alarms etc or only Fatal Alarms)

if (sev=="Fatal")
{
sev1="P1"
} else if (sev == "Critical"){
sev1="P2"
} else {
sev1="P3"
}

To send data to OpsGenie tool, simply use dollar $ sign to Foglight's variables as shown below

"source\": \"$src\"
"priority\": \"$sev1\",
\"description\":\"$msg1\",
"message\": \"$msg\",

For further details please see the sample code below that can be used as part of your Foglight’s Broadcast Alarm Rule Condition.

import javax.xml.soap.*;
import javax.xml.namespace.QName;
import java.util.Iterator;
import java.net.URL;
import java.nio.charset.StandardCharsets;

src="Foglight Alarm Source: "+@event.sourceName
sev=@event_foglight_severity_level_name
msg1="Foglight Alert: +@event.message+ "+@event_foglight_rule_alarm_link
msg="Foglight has a "+@event_foglight_severity_level_name+" message ::"+@event.message

if (sev=="Fatal")
{
sev1="P1"
} else if (sev == "Critical"){
sev1="P2"
} else {
sev1="P3"
}

URL url = new URL(https://api.eu.opsgenie.com/v2/alerts);
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod("POST");
http.setDoOutput(true);
http.setRequestProperty("Content-Type", "application/json");
http.setRequestProperty("Authorization", "GenieKey fe52df58-XXXX-XXXX-XXXX-XXXXXXXXX");

String data = "{\n \"description\":\"$msg1\",\n \"impactedServices\": [\"38179dc9-f005-XXXX-XXXX-XXXX-XXXXXXXXX\", \"0285467c-XXXX-XXXX-XXXX-XXXXXXXXX\"],\n \"message\": \"$msg\",\n \"source\": \"$src\",\n \"tags\": [\"Critical\", \"Outage\"],\n \"priority\": \"$sev1\",\n \"responders\": [{\n \"type\": \"team\",\n \"id\": \"95f8ebdf-XXXX-XXXX-XXXX-XXXXXXXXX\"\n }, {\n \"type\": \"team\",\n \"id\": \"a858b685-XXXX-XXXX-XXXX-XXXXXXXXX\"\n }],\n \"extraProperties\": {\n \"Action to be taken\": \"L1 - Engineer\",\n \"Work to be assessed\": \"L2 - Engineer\"\n },\n \"notifyStakeholders\": false\n}";

byte[] out = data.getBytes(StandardCharsets.UTF_8);

OutputStream stream = http.getOutputStream();
stream.write(out);

System.out.println(http.getResponseCode() + " " + http.getResponseMessage());
http.disconnect();

Save the Rule | Test the Rule Logic to ensure there are no errors or issues.

RESULT - Alarms fired in Foglight will be sent as alerts in OpsGenie 

Foglight Alarms in OpsGenie

         

Example of Foglight Alarm

               

Same Alarm in OpsGenie

               

That's it - Have a great day.

Anonymous
Parents Comment Children
No Data
Related Content