Name

sn_sow_em.EvtMgmtAlertGroupResolutionHandler

Description

No description available

Script

var EvtMgmtAlertGroupResolutionHandler = Class.create();
EvtMgmtAlertGroupResolutionHandler.prototype = {
  initialize: function() {
  	
  	this.GROUP_TYPE = {
  		CI_PATTERN: "CI_PATTERN",
  		CI_CLASS_PATTERN: "CI_CLASS_PATTERN",
  		CMDB: "CMDB",
  		OTHER: "OTHER",
  		SINGLE_ALERT: "SINGLE_ALERT"
  	};

  	GROUP_SOURCE = "groupSource";
  	GROUP_ID = "groupId";
  },

  getErrorObj: function(emptyParams) {

  	var errorObj = {};
  	errorObj["errorMsg"] = "";

  	if (emptyParams.length == 1)
  		errorObj["errorMsg"] = "The parameter " + emptyParams.pop() + " is mandatory";
  	if (emptyParams.length > 1)
  		errorObj["errorMsg"] = "The parameters " + emptyParams.join() + " are mandatory";

  	return errorObj;
  },

  getGroupInfoObj: function(alertParentSysId) {

  	var groupInfo = {};

  	var gr = new GlideRecord("em_agg_group");
  	gr.addQuery("primary_alert_id", alertParentSysId);
  	gr.query();

  	if (gr.next()) {

  		groupInfo[GROUP_ID] = gr.getUniqueValue();
  		groupInfo[GROUP_SOURCE] = gr.getValue("source");
  	}

  	return groupInfo;
  },

  getPatternSysId: function(groupSysId) {

  	var patternId = "";

  	var gr = new GlideRecord("sa_agg_group_pattern");
  	gr.addQuery("group_id", groupSysId);
  	gr.query();

  	if (gr.next())
  		patternId = gr.getValue("pattern_id");

  	return patternId;
  },

  buildResolutionInfo: function(resolutionInfo, groupType, alertSysId, alertCISysId, patternSysId, text) {

  	resolutionInfo["groupType"] = groupType;
  	resolutionInfo["alertSysId"] = alertSysId;
  	resolutionInfo["alertCISysId"] = alertCISysId;
  	resolutionInfo["patternSysId"] = patternSysId;
  	resolutionInfo["text"] = text;
  },

  handleGroupReasoning: function(resolutionData, alertSysId, alertParentSysId, alertCISysId, alertGroupSysId, alertGroupSource) {

  	var groupType = "";
  	var patternSysId = "";
  	var text = "";  // TODO: Update text in future releases according to the type of the Alert group


  	// Need to get group id and group source for secondary alert using the parent.
  	// For Automated group - if it's pattern, then we don't know just by the alert data if it's ci based or ci class based,
  	// so we need to query em_agg_group (getGroupInfoObj) to get the actual group source
  	if (!alertGroupSysId || !alertGroupSource) {
  		var groupInfoObj = this.getGroupInfoObj(alertParentSysId);
  		alertGroupSysId = groupInfoObj[GROUP_ID];
  		alertGroupSource = groupInfoObj[GROUP_SOURCE];
  	}

  	switch (alertGroupSource) {

  		case '1':  // Automated (CI based pattern or aggregated)

  			patternSysId = this.getPatternSysId(alertGroupSysId);
  			if (patternSysId)
  				groupType = this.GROUP_TYPE.CI_PATTERN;
  			else  // Aggregated
  				groupType = this.GROUP_TYPE.OTHER;

  			break;

  		case '7':  // CI class based pattern

  			patternSysId = this.getPatternSysId(alertGroupSysId);
  			if (patternSysId)
  				groupType = this.GROUP_TYPE.CI_CLASS_PATTERN;

  			break;

  		case '4':  // CMDB

  			if (!alertCISysId) {
  				resolutionData["emptyParams"].push("alertCISysId");
  				return;
  			}

  			groupType = this.GROUP_TYPE.CMDB;

  			break;

  		default:  // OTHER
  			// TODO: Update text in future releases according to the type of the Alert group
  			groupType = this.GROUP_TYPE.OTHER;
  	}

  	this.buildResolutionInfo(resolutionData["resolutionInfo"], groupType, alertSysId, alertCISysId, patternSysId, text);
  },

  getResolutionInfo: function(alertSysId, alertParentSysId, alertGroupSysId, alertGroupSource, alertCISysId) {

  	var resolutionData = {};
  	resolutionData["emptyParams"] = [];
  	resolutionData["resolutionInfo"] = {};

  	if (!alertSysId)
  		return this.getErrorObj(["alertSysId"]);

  	if (!alertGroupSource)
  		return this.getErrorObj(["alertGroupSource"]);

  	switch (alertGroupSource) {

  		case '6':  // single Alert (no group)

  			this.buildResolutionInfo(resolutionData["resolutionInfo"], this.GROUP_TYPE.SINGLE_ALERT, alertSysId, "", "", "");
  			break;

  		case '5':  // Secondary Alert

  			if (!alertParentSysId)
  				return this.getErrorObj(["alertParentSysId"]);

  			this.handleGroupReasoning(resolutionData, alertSysId, alertParentSysId, alertCISysId);
  			break;

  		case '1':  // Automated Alert

  			this.handleGroupReasoning(resolutionData, alertSysId, alertSysId, alertCISysId, alertGroupSysId);
  			break;

  		default:
  			this.handleGroupReasoning(resolutionData, alertSysId, alertParentSysId, alertCISysId, alertGroupSysId, alertGroupSource);
  	}
  	
  	if (resolutionData["emptyParams"].length > 0)
  		return this.getErrorObj(resolutionData["emptyParams"]);
  	
  	return resolutionData["resolutionInfo"];
  },

  type: 'EvtMgmtAlertGroupResolutionHandler'
};

Sys ID

997d77575b24411069a0d01fb681c745

Offical Documentation

Official Docs: