Name
global.getRunningProcess
Description
No description available
Script
function getRunningProcess(computer_id, port, pid, ip){
var data = new SNC.PrePatternExecutionData();
var isQueryByPid = false;
var processGR = new GlideRecord("cmdb_running_process");
processGR.addQuery("computer", computer_id);
processGR.addQuery("absent", false);
if(pid !== -1) {
processGR.addQuery("pid",pid);
isQueryByPid = true;
}
//set the behaviour as in top down listen on port, search for min pid
processGR.orderBy("pid");
processGR.limit(1);
if(port !== -1)
processGR.addQuery("listening_on","CONTAINS", ":"+port+":");
processGR.query();
var shouldAddProcess;
if (processGR.next()) {
if(!isQueryByPid) {
// Now we will check if the process is listening on the correct IP
var tcpConn = new GlideRecord("cmdb_tcp");
tcpConn.addQuery("process", processGR.getValue("sys_id"));
tcpConn.addQuery("type", "on");
// In case the listed IP = 0.0.0.0 which means all IPs are acceptable
tcpConn.addQuery("ip", ip).addOrCondition("ip","0.0.0.0");
tcpConn.addQuery("port", port);
tcpConn.query();
shouldAddProcess = tcpConn.next();
}else {
shouldAddProcess = true;
}
if (shouldAddProcess) {
if(processGR.getValue("name").trim() == "nginx: worker process" &&
processGR.getValue("command").trim() == "nginx: worker process" &&
!processGR.getValue("parameters"))
{
var parentProcessGR = new GlideRecord("cmdb_running_process");
parentProcessGR.addQuery("computer",computer_id);
parentProcessGR.addQuery("pid", processGR.getValue("ppid"));
parentProcessGR.query();
if (parentProcessGR.next()) {
data.addGlideRecordEntry('pre_cmdb_running_process',parentProcessGR);
}
}else{
data.addGlideRecordEntry('pre_cmdb_running_process',processGR);
}
} else {
//please don't change this message. should be identical to ClassificationData.MISSING_PROCESS_IN_CMDB_MSG
data.setInfoMessage("Process not found in cmdb");
}
}else {
//please don't change this message. should be identical to ClassificationData.MISSING_PROCESS_IN_CMDB_MSG
data.setInfoMessage("Process not found in cmdb");
}
return data;
}
Sys ID
3c2bb867677132009e052dbd2685efad