Name

sn_em_arm.EvtMgmtAlertMgmtGetActionsFromRulesScoped

Description

No description available

Script

gs.include('EvtMgmtAlertMgmtProcess');
gs.include('EvtMgmtGetActionsFromRulesScoped');
gs.include('EvtMgmtCommons');
gs.include('EvtMgmtAlertMgmtMediator');


var EvtMgmtAlertMgmtGetActionsFromRulesScoped = Class.create();

EvtMgmtAlertMgmtGetActionsFromRulesScoped.LEGACY_FLOW = "sn_em_alert_mgmt_c.Create Task Legacy";

EvtMgmtAlertMgmtGetActionsFromRulesScoped.prototype = {

  type: 'EvtMgmtAlertMgmtGetActionsFromRulesScoped',

  initialize: function() {
      this.fEvtMgmtAlertMgmtProcess = new EvtMgmtAlertMgmtProcess();
  },

  getRemediationsAndLaunches: function(alertSysId, retrieveParams, alertGR) {
      var fEvtMgmtGetActionsFromRulesScoped = new EvtMgmtGetActionsFromRulesScoped();
  	var evtMgmtAlertMgmtMediator = new global.EvtMgmtAlertMgmtMediator();

      //will be called only only when the alert management plugin is activated
      var alert;
      if (!alertGR) {
          alert = new GlideRecord('em_alert');
          alert.get(alertSysId);
      } else {
          alert = alertGR;
      }
      var result = {};
      result.toolsForAlert = [];
      result.manualRemediationData = [];
      result.subflows = [];
      var ciSysID = alert.getValue('cmdb_ci');
      var remediationsForCi;
      //if we want to take the also the ci remediations from the alert... TODO..?
      //if(ciSysID){
      //	remediationsForCi=SNC.RemediationScriptableApi.getRemediationForCI(ciSysID,'','');
      //}

      //Add Alert Management manual actions
      var manuallyActionsList = this.fEvtMgmtAlertMgmtProcess.runForAlert(alert, true, true, retrieveParams);
      if (retrieveParams.retrieveLaunchApplications) {
          result.toolsForAlert = fEvtMgmtGetActionsFromRulesScoped.getLaunchApplicationObjectsList(manuallyActionsList.launchApplications);
      }
      if (retrieveParams.retrieveRemediations) {
          if (evtMgmtAlertMgmtMediator.getRemediationObjectsList && (typeof evtMgmtAlertMgmtMediator.getRemediationObjectsList == 'function'))
              result.manualRemediationData = evtMgmtAlertMgmtMediator.getRemediationObjectsList(manuallyActionsList.remediations, true, alertSysId);
          else
              result.manualRemediationData = fEvtMgmtGetActionsFromRulesScoped.getRemediationObjectsList(manuallyActionsList.remediations, true, alertSysId);
      }
      if (retrieveParams.retrieveSubflows) {
          result.subflows = this.getSubflowObjectList(manuallyActionsList.subflows, alertSysId);
      }


      //get the legacy actions remediations and launch application and union with the new ones 		
      if (gs.getProperty('evt_mgmt.alert.management.enable_legacy_alert_action_rules', 'true') == 'true') { // if property is turned on, used to disable legacy alert rules where not needed
          var alertManagementActions = fEvtMgmtGetActionsFromRulesScoped.getRemediationsAndLaunches(alertSysId, retrieveParams);
          //union:
          result.toolsForAlert = alertManagementActions.toolsForAlert.concat(result.toolsForAlert);
          result.manualRemediationData = alertManagementActions.manualRemediationData.concat(result.manualRemediationData);
      }

      result = this.removeDuplicates(result);
      //return the subflows and remediations in one list
      result.manualRemediationData = result.manualRemediationData.concat(result.subflows);
      delete result.subflows;
      return result;
  },

  /*
  functions for retrieving the deduplication keys
  */

  getRemediationKey: function(action) {
      return action["workflowId"];
  },

  getSubflowKey: function(action) {
      if (action["workflowId"] == EvtMgmtAlertMgmtGetActionsFromRulesScoped.LEGACY_FLOW) {
          return action["workflowId"] + "_" + action["rule"];

      }
      return action["workflowId"];
  },

  getLaunchApplicationKey: function(action) {
      return action["url"];
  },

  removeDuplicates: function(result) {
      var fEvtMgmtCommons = new global.EvtMgmtCommons();
      if (result.manualRemediationData.length > 0) //removeDuplicatesFromList gets 'this.getRemediationKey' as function reference
          result.manualRemediationData = fEvtMgmtCommons.removeDuplicatesFromList(result.manualRemediationData, this.getRemediationKey);
      if (result.toolsForAlert.length > 0)
          result.toolsForAlert = fEvtMgmtCommons.removeDuplicatesFromList(result.toolsForAlert, this.getLaunchApplicationKey);
      if (result.subflows.length > 0)
          result.subflows = fEvtMgmtCommons.removeDuplicatesFromList(result.subflows, this.getSubflowKey);
      return result;
  },

  startAction: function(alertSysId, ciSysId, workflowSysId, workflowDisplayName, rule, isSubflow, actionId) {
      var contextId;
      if (!isSubflow) {
          contextId = this.fEvtMgmtAlertMgmtProcess.executeRemediation(alertSysId, ciSysId, rule, workflowSysId, workflowDisplayName, true, undefined, undefined, actionId);
      } else {
          contextId = this.fEvtMgmtAlertMgmtProcess.executeSubflowManually(alertSysId, workflowSysId, workflowDisplayName, rule, actionId);
      }
      return contextId;
  },

  getSubflowObjectList: function(subflowList, alertSysId) {
      var subflowsArray = [];
      for (var i = 0; i < subflowList.length; i++) {
          var subflow = {};
          var subflowFullName = subflowList[i].action.getReferenceExecutionName();
          subflow.actionId = subflowList[i].action.getActionSysid();
          subflow.workflowId = subflowFullName;
          subflow.workflowName = subflowList[i].action.getReferenceActionDisplayName();
          subflow.alertManagementRule = true;
          subflow.rule = subflowList[i].rule;
          subflow.ruleName = subflowList[i].ruleName;

          subflow.ruleOrder = subflowList[i].ruleOrder;
          subflow.alertSysId = alertSysId;
          subflow.isSubflow = true;
          subflowsArray.push(subflow);
      }
      return subflowsArray;
  },

};

Sys ID

cd9919aeb7d920107c038229ce11a98d

Offical Documentation

Official Docs: