Name

global.AddProbeAdditionalParameters

Description

Add additional parameters to probe which will be later consumed by patterns.

Script

var AddProbeAdditionalParameters = Class.create();
AddProbeAdditionalParameters.prototype = {
  initialize: function() {
  },

  /* 
  * add additional parameters to probe.
  * In case the host class extends cmdb_ci_logical_datacenter, we follow the Hosted-on relation to 
  * cmdb_ci_service_account and add to the probe the logical_datacenter and service_account 
  * details
  */
  addParamsToProbe: function(probe, endpointId, hostId, hostClass) {
  	// We need to add parameters only in the case of host extending cmdb_ci_logical_datacenter
  	if (!GlideDBObjectManager.get().isInstanceOf(hostClass,'cmdb_ci_logical_datacenter')) {
  		if (!GlideDBObjectManager.get().isInstanceOf(hostClass,'cmdb_ci_cloud_load_balancer')) {

  		return "Host class " + hostClass + " is not logical datacenter and not cmdb_ci_cloud_load_balancer";
  
       } else {
  		 // the host class is cmdb_ci_cloud_load_balancer. Find the logical datacenter from here
           var relLb = new GlideRecord('cmdb_rel_ci');
  	     relLb.addQuery('parent', hostId);
  	     relLb.addQuery('type', '5f985e0ec0a8010e00a9714f2a172815'); // 'Hosted On'
  	     relLb.query();
  	     if (!relLb.next()) {
  		     gs.log("No logical datacenter found from cloud load balancer with ID " + hostId);
  		     return "No logical datacenter found from cloud load balancer with ID " + hostId;
  	     }
  		 hostId = relLb.child; // hostId now is the logical datacenter
       }
  	}
  	
  	
  	// Find the service account
  	var relGr = new GlideRecord('cmdb_rel_ci');
  	relGr.addQuery('parent', hostId);
  	relGr.addQuery('type', '5f985e0ec0a8010e00a9714f2a172815'); // 'Hosted On'
  	relGr.query();
  	if (!relGr.next()) {
  		gs.log("No service account found from logical datacenter with ID " + hostId);
  		return "No service account found from logical datacenter with ID " + hostId;
  	}

  	// Adding cloud parameters to probe
  	var serviceAccount = relGr.child;
  	if (JSUtil.notNil(serviceAccount)) {
  		var cloudAppDiscovery = new CloudApplicationDiscovery();
  		cloudAppDiscovery.addParamsToContext(probe, serviceAccount, hostId);
  	} else {
  		gs.log("No service account found as child of relation " + relGr.sys_id);
  		return "No service account found as child of relation " + relGr.sys_id;
  	}
  	
  	// Add target CI type to the probe parameters
  	this.addTargetCiType(endpointId, probe);
  	
  	return "OK";
  },
  
  addTargetCiType:function(endpointId, probe) {
  	var gr = new GlideRecord('cmdb_ci_endpoint');
  	gr.get(endpointId);
  	if (!gr.isValid())
  		return;
  	if (JSUtil.notNil(gr.host_name)) {
  	    var findHostStategies = new FindHostStrategies();
  	    var ldc = findHostStategies.findLogicalDataCenterFromHostname(gr.host_name);
  	    var ci_class_name = findHostStategies.getCiClassName();
  		//  Add target CI type to the probe, with the exception of load balancer
  		if (JSUtil.notNil(ci_class_name) && 'cmdb_ci_lb_service' != ci_class_name && 'cmdb_ci_cloud_load_balancer' != ci_class_name && 'cmdb_ci_dns_name' != ci_class_name)
  	        probe.addParameter('target_ci_type', ci_class_name);
  	}
  },
  
  type: 'AddProbeAdditionalParameters'
};

Sys ID

f3bfdc29c31322003e76741e81d3aef6

Offical Documentation

Official Docs: