Name
sn_em_ai.EvtMgmtAnomalyMBDataPointsHandler
Description
No description available
Script
var EvtMgmtAnomalyMBDataPointsHandler = Class.create();
EvtMgmtAnomalyMBDataPointsHandler.prototype = {
initialize: function() {
this.TimeRangeForAlertAnomalyMetrics = "evt_mgmt.TimeRangeForAnomalyMetricsInHours";
this.timeRange = gs.getProperty(this.TimeRangeForAlertAnomalyMetrics, 1);
this.timeRangeInSec = this.timeRange * 3600;
this.logAnalyticsStr = "Log Analytics";
},
process: function(alertSysId) {
var alertGr = new GlideRecord("em_alert");
alertGr.addQuery("sys_id", alertSysId);
alertGr.query();
var result = {};
var errMessage = "";
if (alertGr.next()) {
var additional_info = alertGr.getValue("additional_info");
var additionalInfo = JSON.parse(alertGr.getValue("additional_info"));
if (!additionalInfo) {
errMessage = gs.getMessage("Failed to parse additional info");
gs.error("AnomalyMBDataPointsHandler: Failed to parse additional info in alert %0 returning empty state", alertSysId);
return this.errorResponse(errMessage);
}
var creationTime = alertGr.getValue('initial_remote_time');
if (!creationTime){
errMessage = gs.getMessage("Event creation time is empty");
gs.error("AnomalyMBDataPointsHandler: Event creation time is empty in alert %0 returning empty state", alertSysId);
return this.errorResponse(errMessage);
}
var start = new GlideDateTime(creationTime);
start.subtract(this.timeRangeInSec * 1000);
var end = new GlideDateTime(creationTime);
end.addSeconds(this.timeRangeInSec);
//Distinguish between Log Anlytics alerts, and other OI anomalies according
if (this.isValidTag(additionalInfo, 'sn_source') && this.logAnalyticsStr == additionalInfo.sn_source) {
//Log Analytics alert
var logAnalyticsMetricData = new EvtMgmtLogAnalyticsMetricData();
result = logAnalyticsMetricData.getMetricPoints(additionalInfo, start, end);
} else {
//OI
var oiGr = new GlideRecord("sys_plugins");
oiGr.addQuery("name", "Operational Intelligence");
oiGr.query();
if (oiGr.next()) {
var anomalyMetricData = new AnomalyMetricData();
result = anomalyMetricData.getAllData(alertSysId, start, end);
} else
errMessage = gs.getMessage("Operational Intelligence Plugin is not installed");
gs.error("AnomalyMBDataPointsHandler: Operational Intelligence Plugin is not installed returning empty state");
return this.errorResponse(errMessage);
}
}
var userTimeZone = gs.getSession().getTimeZoneName();
if (userTimeZone == "NULL_OVERRIDE") { // timezone is the same timezone as the instance
result.timezone = "LOCAL_TIMEZONE";
} else {
result.timezone = userTimeZone;
}
return result;
},
// check if the JSON tag/key is valid
isValidTag: function(element, tag) {
var val = element.hasOwnProperty(tag);
return val;
},
errorResponse: function(errMessage) {
return {
"count": null,
"expected": {
"value": errMessage,
"type": "Error"
},
metrics: []
};
},
type: 'EvtMgmtAnomalyMBDataPointsHandler'
};
Sys ID
61559b7c538b1010cf0addeeff7b121e