Name

sn_em_arm.EvtMgmtAlertMgmtScaleOutNumberChange

Description

No description available

Script

var EvtMgmtAlertMgmtScaleOutNumberChange = Class.create();
EvtMgmtAlertMgmtScaleOutNumberChange.prototype = {
  initialize: function() {
      this.scopedAlertMgmtJobName = "Event Management - Evaluate Scoped Alert Rules Management";
      this.ARM_ADD_SCALE_OUT_JOB_SYS_ID = '10b2f0cadb821510a0b3d03cd3961964';
  },

  execute: function() {
      var zboot = false;
      var evtMgmtCommons = new global.EvtMgmtCommons();
      if (evtMgmtCommons.isNewInstance()) { //work only for new installations
          zboot = true;
          var alertMgmtScaleOutNumberChange = new sn_em_arm.EvtMgmtAlertMgmtScaleOutNumberChange();
          var numOfProcesses = 2;
          alertMgmtScaleOutNumberChange.changePropertyValue(numOfProcesses);
          alertMgmtScaleOutNumberChange.handleOOBJob();
          alertMgmtScaleOutNumberChange.handleOOBHashes(numOfProcesses);
      }
      // Disable the move to scaleout job if it run or if instance is not zbooted
      var message = zboot ? "Upgrade to ARM processing job Scale-out was completed" : "The instance is not zbooted, thus no automatic move to ARM processing job Scale-out was performed";
      gs.info("'ARM - Add Scale Out Capabilities' job was deactivated intentionally and automatically because: "+ message);
      this.disableScheduledJob(this.ARM_ADD_SCALE_OUT_JOB_SYS_ID, message);
  },

  changePropertyValue: function(num) {
      if (!num || !parseInt(num, 10))
          return;

      var gr = new GlideRecord('sys_properties');
      gr.addQuery('name', "sn_em_arm.alert_management.num_of_jobs");
      gr.query();
      if (gr.next()) {
          gr.setValue('value', num);
          gr.update();
      }
  },

  handleOOBJob: function() {
      // this method changes the OOB job (number 1) name and state in order to start working in multi-job mode
      var jobSysId = '66c2c17b1bb195106e852f836b4bcb93';
      var newName = 'Event Management - Evaluate Scoped Alert Rules Management1';
      var script = "var evtMgmtAlertMgmtJobWrapper = new EvtMgmtAlertMgmtJobWrapper();\n evtMgmtAlertMgmtJobWrapper.executeForJob(1);";
      var gr = new GlideRecord('sysauto_script');
      var job = gr.get(jobSysId);
      if (job) {
          gr.setValue('name', newName);
          gr.setValue('active', 'true');
          gr.setValue('script', script);
          gr.update();
      }
  },

  isGrExist: function(tableName, name) {
      var gr = new GlideRecord(tableName);
      gr.addQuery('name', name);
      gr.query();
      return gr.next();
  },

  handleOOBHashes: function(num) {
      // this method handles the moving from 1 job to 2 jobs only( since there is no need to get the minimum hash value)
      if (!num || !parseInt(num, 10))
          return;
      var hashName1 = "analytics_trigger_g2";
      var hashName2 = "last_calculated_alert_management_job";
      for (var i = 0; i < num; i++) {
          this.addHashValues(hashName1, i);
          this.addHashValues(hashName2, i);
      }
  },

  addHashValues: function(hashName, num) {
      // we want to duplicate the existing hash if it exists
      // if not - we will create a new one
      var name = hashName + "_" + num;

      var gr = new GlideRecord('sa_hash');
      gr.initialize();
      gr.addQuery('name', name);
      gr.query();
      if (!gr.next()) {
          var hashValue = new GlideDateTime();
          gr.setValue('name', name);
          gr.setValue('hash', hashValue);
          gr.insert();
      }
  },

  // Takes a given scheduled job's sys_id and turns it to in-active, if exists.
  disableScheduledJob: function(sysId, message) {
      var scheduledJob = new GlideRecord('sysauto_script');
      scheduledJob.addQuery('sys_id', sysId);
      scheduledJob.addActiveQuery();
      scheduledJob.query();
      if (scheduledJob.next()) {
          if (message) {
              message = '/**** ' + message + ' ****/';
              scheduledJob.setValue('script', message + '\n' + scheduledJob.getValue('script') + '\n' + message);
          }
          scheduledJob.setValue('active', 'false');
          scheduledJob.update();
      }
  },

  type: 'EvtMgmtAlertMgmtScaleOutNumberChange'
};

Sys ID

25c0db431bf5d1106e852f836b4bcbfd

Offical Documentation

Official Docs: