Name

sn_cmdb_int_util.ADMProcessorUtil

Description

No description available

Script

var ADMProcessorUtil = Class.create();
ADMProcessorUtil.prototype = {

  DISCOVERY_SOURCE: "",

  initialize: function(discoverySource) {
      this.DISCOVERY_SOURCE = discoverySource;
      this.adm = new GlobalApplicationDependencyMappingHelper();
  },

  processADMData: function(tcpConnections, runningProcess, computerSNK, props) {

      var output = {
          state: "",
          comment: ""
      };

      var computerSysId = this.getSysIdOfComputer(computerSNK);

      if (!gs.nil(computerSysId)) {
          var result = this.runADM(tcpConnections, runningProcess, computerSysId, this.DISCOVERY_SOURCE, props);
          this.adm.initializeBySysId(computerSysId);
          this.adm.mapCi();
          output.comment = "Processed TCP and Running Processes - " + result;
          output.state = "processed";
      } else {
          output.comment = "Unable to find SysId for ComputerSNK - " + computerSNK;
          output.state = "error";
      }
      return output;

  },

  getSysIdOfComputer: function(sourceNativeKey) {
      var grs = new GlideRecord("sys_object_source");
      grs.addQuery("name", this.DISCOVERY_SOURCE);
      grs.addQuery("id", sourceNativeKey);
      grs.query();

      while (grs.next()) {
          var grr = new GlideRecord(grs.target_table + '');
          if (grr.get(grs.target_sys_id + ''))
              return grr.sys_id + '';
      }
      return null;
  },

  runADM: function(tcpConnections, runningProcess, ciSysId, discoSource, props) {
      var gr = new GlideRecord('cmdb_ci_computer');
      gr.get(ciSysId);
      var srvname = gr.getValue('name');
      var srvclass = gr.getValue('sys_class_name');
      gs.debug("runADM [" + ciSysId + "]: " + srvname + " in " + srvclass);
      var admHandler = new ADMHelper(tcpConnections, runningProcess, ciSysId, props);
      var admjson = admHandler.addConnectionsAndRelationshipsToCMDB(1, srvname);
      var apps = admjson[0];
      var rels = admjson[1];
      var srvire = {
          "className": srvclass,
          "lookup": [],
          "values": {
              "sys_id": ciSysId,
              "name": srvname
          }
      };
      srvire.values['sys_id'] = new String(ciSysId).valueOf();

      gs.debug("Base Server CI IRE JSON: " + JSON.stringify(srvire));
      var irejson = {};
      var ireitems = [];
      var irerels = [];
      irejson.items = ireitems;
      irejson.relations = irerels;
      irejson.items.push(srvire);
      irejson.items = irejson.items.concat(apps);
      irejson.relations = irejson.relations.concat(rels);
      irejson = JSON.stringify(irejson);
      var ireOutput = sn_cmdb.IdentificationEngine.createOrUpdateCI(discoSource, irejson);
      return ireOutput;
  },

  getSysIdOfRefField: function(fieldName, tableName) {
      var sysId = '';
      var record = new GlideRecord(tableName);
      record.addQuery('name', fieldName);
      record.query();
      if (!record.next()) {
          record.newRecord();
          record.name = fieldName;
          record.insert();
          sysId = record.sys_id;
      } else {
          sysId = record.sys_id;
      }
      return sysId;
  },

  

  type: 'ADMProcessorUtil'
};

Sys ID

fa78dc5a77502110258d2344681061b4

Offical Documentation

Official Docs: