Name
sn_agent.MonitoringUtils
Description
Utilities to help when populating parameters on monitoring checks
Script
var MonitoringUtils = Class.create();
MonitoringUtils.prototype = {
initialize: function() {},
/*
* given application CI, find the listening port of this CI. Find the process associated with the CI and take the listening_on field from * there
*/
getListeningPort: function(ci) {
var processGr = new GlideRecord('cmdb_running_process');
if (ci.running_process) {
if (!processGr.get(ci.running_process + ''))
return;
} else {
// Find the relevant process
if (!ci.running_process_command && !ci.running_process_key_parameters)
return;
// Find the host of this application CI.
var host = this.findHost(ci);
if (!host)
return;
// Find running process record
processGr.addQuery('computer', host);
processGr.addQuery('command', ci.running_process_command + '');
processGr.addQuery('key_parameters', ci.running_process_key_parameters + '');
processGr.query();
if (!processGr.next())
return;
}
var listenPorts = processGr.listening_on;
if (!listenPorts) {
return;
}
var listenPortsStr = listenPorts + '';
var portsTemp = listenPortsStr.split(':');
// Remove from the array empty strings
var ports = [];
for (var portIndex in portsTemp) {
if (portsTemp[portIndex] == '')
continue;
ports.push(portsTemp[portIndex]);
}
if (ports.length == 0)
return null;
return ports.join();
},
findHost: function(ci) {
var relCiGr = new GlideRecord('cmdb_rel_ci');
relCiGr.addQuery('parent', ci.getUniqueValue());
relCiGr.addQuery('type', '60bc4e22c0a8010e01f074cbe6bd73c3'); // Runs-on relation type
relCiGr.query();
if (relCiGr.next())
return relCiGr.child;
},
type: 'MonitoringUtils'
};
/*
* split array into chunks
*/
MonitoringUtils.chunkArray = function(myArray, chunk_size) {
var index = 0;
var arrayLength = myArray.length;
var tempArray = [];
for (index = 0; index < arrayLength; index += chunk_size) {
myChunk = myArray.slice(index, index + chunk_size);
tempArray.push(myChunk);
}
return tempArray;
};
/*
Get credential sys_id from cred_alias
*/
MonitoringUtils.getCredIdFromCredName = function(credName) {
var gr = new GlideRecord('discovery_credentials');
gr.addQuery('name', credName);
gr.query();
if (gr.next())
return gr.getUniqueValue();
else
return '';
};
Sys ID
63dc8cc4c38613002a6f741e81d3aef8