Name

global.FixUnixFamilyModelForPatterns

Description

should add missing relations for IRE for Linux

Script

var FixUnixFamilyModelForPatterns = Class.create();
FixUnixFamilyModelForPatterns.prototype = Object.extendsObject(FixPatternsModelBasic, {
   
  addMissingRelationsForUnix : function() {
  	this.stepsCompleted = this.getStepsCompleted();
  	this.startLogRecord(this.scriptNames.UNIX);

  	//Do quick Prerequisite check to make sure we can run this migration
  	this.quickPrerequisiteCheck();
  	this.recordArray = [];
  	this.addUnixClassifiersToArray();

  	for (var i = 0; i < this.recordArray.length; i++) {
  		if (this.recordArray[i].status.equals(this.checkResult.FAIL))
  			this.classifierCheck = false;
  	}
  	var passLog = this.getPassLog("Classifier", this.classifierCheck);
  	this.infoMsg(passLog);

  	if (this.PASS_ALL) {
  		var startTime = new Date();
  		this.infoMsg("UNIX migration start");

  		//Update records for UNIX Servers
  		var unixFamilyArr = [];
  		unixFamilyArr.push('cmdb_ci_linux_server');
  		unixFamilyArr.push('cmdb_ci_hpux_server');
  		unixFamilyArr.push('cmdb_ci_aix_server');
  		unixFamilyArr.push('cmdb_ci_solaris_server');
  		this.addMissingRelationsForUnixType(unixFamilyArr);

  		//Migrate UNIX Classifications to Patterns
  		for (var j = 0; j < this.recordArray.length; j++)
  			this.enablePatternObj(this.recordArray[j]);
  		this.setPropertyForOSProbes('glide.discovery.ip_based.active', 'false');
  		this.updateDNSIPAddresses();

  		var endTime = new Date();
  		var totalTime = endTime.getTime() - startTime.getTime();
  		var formattedTime = this.msToTime(totalTime);
  		this.infoMsg('UNIX Migration took: ' + formattedTime);
  	} else
  		this.infoMsg('Unix migration prerequisite check FAILED - Please run ProbeToPatternPrerequisiteScript to check for issues.');
  	this.endLogs();
  },
  	
  addMissingRelationsForUnixType : function(unixFamilyArr) {
  	switch(this.stepsCompleted) {
  		case 0:
  			this.infoMsg('UNIX: Adding Network Adapter Relationships');
  			this.addNetworkAdapter(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 1:
  			this.infoMsg('UNIX: Adding File System Relationships');
  			this.addFileSystem(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 2:
  			this.infoMsg('UNIX: Adding IP Address Relationships');
  			this.addIpAddress(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 3:
  			this.infoMsg('UNIX: Adding Memory Module Relationships');
  			this.addMemoryModule(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 4:
  			this.infoMsg('UNIX: Adding Storage Relationships');
  			this.addStorage(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 5:
  			this.infoMsg('UNIX: Adding Storage Pool Relationships');
  			this.addStoragePool(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 6:
  			this.infoMsg('UNIX: Adding Disk Partition Relationships');
  			this.addDiskPartitions(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 7:
  			this.infoMsg('UNIX: Adding Exit Interface Relationships');
  			this.addExitInterfaceRule(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 8:
  			this.infoMsg('UNIX: Adding Next Hop Relationships');
  			this.addNextHopRule(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 9:
  			this.infoMsg('UNIX: Adding HBA Relationships');
  			this.addHBA(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 10:
  			this.infoMsg('UNIX: Adding Fibre Channel Relationships');
  			this.addFiberChannel(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 11:
  			this.infoMsg('UNIX: Adding Patches Relationships');
  			this.addPatches(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 12:
  			this.infoMsg('UNIX: Adding Router Interface Relationships');
  			this.addRouterInterface(unixFamilyArr);
  			this.saveLeftOversRelationsToCMDBRelCI();
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 13:
  			this.infoMsg('UNIX: Updating Exit Interface Route Names');
  			this.updateRouteInterfaceName(unixFamilyArr, 'router_interface');
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 14:
  			this.infoMsg('UNIX: Updating Dest IP Network Values');
  			this.fixDestIpNetwork(unixFamilyArr);
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 15:
  			this.infoMsg('UNIX: Adding Pool Member to Pool Relationships');
  			var poolTableArr = [];
  			poolTableArr.push('cmdb_ci_lvm_pool');
  			poolTableArr.push('cmdb_ci_mpio_pool');
  			poolTableArr.push('cmdb_ci_mpio_pool_group');
  			poolTableArr.push('cmdb_ci_storage_pool');
  			this.addRelationToCi("cmdb_ci_storage_pool_member", 'pool', poolTableArr, this.MEMBERS);
  			this.saveLeftOversRelationsToCMDBRelCI();
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 16:
  			this.infoMsg("UNIX: Creating Solaris Server to Instance Relationships");
  			this.createSolarisServerToInstanceRel();
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 17:
  			this.infoMsg("UNIX: Updating LVM Pool Member Names");
  			this.changeLVMPoolMemberName();
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  		case 18:
  			this.infoMsg('UNIX: Adding Packages Relationships');
  			this.createOneToManyRelationsForPackages();
  			this.stepsCompleted++;
  			this.updateStepsCompleted(this.stepsCompleted);
  			break;
  		case 19:
  			this.infoMsg('UNIX: All previous steps have been completed. Moving to enable patterns');
  			break;
  		default:
  			this.infoMsg('UNIX migration step count check FAILED - Please check probe_to_pattern_log for issues.');
  	}
  },

  changeLVMPoolMemberName : function() {
  	var table = 'cmdb_ci_lvm_pool_member';
  	var lvmPoolMemberGr = new GlideRecord(table);
  	lvmPoolMemberGr.query();
  	while (lvmPoolMemberGr.next()) {
  		var storageName = "";
  		var lvmPoolMemberName = lvmPoolMemberGr.getValue("name");
  		var storageValue = lvmPoolMemberGr.getValue("storage");
  		if (!storageValue || !lvmPoolMemberName)
  			continue;
  		var storageGr = new GlideRecord("cmdb_ci");
  		storageGr.get('sys_id', storageValue + '');
  		storageName = storageGr.getValue("name");
  		if (lvmPoolMemberName.startsWith("/dev/") && lvmPoolMemberName.equals(storageName)) {
  			jsObj = {};
  			jsObj.name = lvmPoolMemberName.substr(5);
  			jsObj.source = lvmPoolMemberGr.getValue("pool");
  			jsObj.sys_id = lvmPoolMemberGr.getValue("sys_id");
  			this.jsonArr.push(jsObj);
  			if (this.jsonArr.length >= this.CHUNK_SIZE)
  				this.batchUpdateRecords(table);
  		}
  	}
  	this.batchUpdateRecords(table);
  },

  // Adding missing relationships between Solaris Server to Solaris Virtual Instances
  // This is done by looking at the relationships these have to a common Solaris Zone
  createSolarisServerToInstanceRel : function() {
  	var relOneGr = new GlideRecord("cmdb_rel_ci");
  	relOneGr.addQuery('parent.sys_class_name', "cmdb_ci_vm_zones");
  	relOneGr.addQuery('child.sys_class_name', "cmdb_ci_solaris_server");
  	relOneGr.addQuery('type', this.RUNS_ON);
  	relOneGr.query();
  	while (relOneGr.next()) {
  		var solarisServer = relOneGr.child.sys_id + '';
  		var zoneServer = relOneGr.parent.sys_id + '';
  		var relTwoGr = new GlideRecord("cmdb_rel_ci");
  		relTwoGr.addQuery('child', zoneServer);
  		relTwoGr.addQuery('parent.sys_class_name', "cmdb_ci_solaris_instance");
  		relTwoGr.addQuery('type', this.REGISTERED);
  		relTwoGr.query();
  		while (relTwoGr.next()) {
  			var solarisInstance = relTwoGr.parent.sys_id + '';
  			this.addRelation(solarisServer, solarisInstance, this.OWNS);
  		}
  	}
  	this.saveLeftOversRelationsToCMDBRelCI();
  },

  // Create Packages Data Based on new Probes Model By Converting 1:1 Reference between Solaris Server and OS Packages to 1:M Relation between OS Package and Multiple Solaris Server
  createOneToManyRelationsForPackages: function() {
      var tableGr = new GlideRecord('cmdb_ci_os_packages');
      tableGr.query();
      var nameVersionSysIdMap = {};
      while (tableGr.next()) {
          var solaris_server_sys_id = tableGr.getValue('cmdb_ci');
  		var deleteRecord = false;
          if (!(solaris_server_sys_id == null || '' == '' + solaris_server_sys_id || typeof solaris_server_sys_id == 'undefined')) {
              var name = tableGr.getValue("name");
              var version = tableGr.getValue("version");
              var package_sys_id;
              var key = name + version;
              if (!nameVersionSysIdMap.hasOwnProperty(key)) {
                  tableGr.cmdb_ci = '';
                  tableGr.discovery_source = 'ServiceNow';
                  package_sys_id = tableGr.update();
                  nameVersionSysIdMap[key] = package_sys_id;
              } else {
                  package_sys_id = nameVersionSysIdMap[key];
  				deleteRecord = true;
              }
              this.addRelation(solaris_server_sys_id, package_sys_id, this.OWNS);
          }
          if (deleteRecord) {
              tableGr.deleteRecord();
          }
      }
      this.saveLeftOversRelationsToCMDBRelCI();
  },

  type: 'FixUnixFamilyModelForPatterns'
});

Sys ID

f034f5929fc31300ed6191aec32e70e9

Offical Documentation

Official Docs: