Hey guys,
I am using the following rule automatic rule to add a template if a specific SNMP values has been found:
transport = CreateSNMPTransport($node);
if (transport == null) {
return false;
}
value = SNMPGetValue(transport, ".1.3.6.1.2.1.25.4.1.0");
if (value == null) {
return false;
}
else {
return true;
}
This works so far pretty well.
But now I have some device where I want to check if specific processes are running on it.
I want to check via SNMP thecomplete hrSWRunTable (.1.3.6.1.2.1.25.4.2) if there is a process with a specific name (hrSWRunName has the OID .1.3.6.1.2.1.25.4.2.1.2).
So maybe I have to get all values form the tabel and then iterate over the entries and compare them. But I don't know how.
Do you have an idea how I should adjust my rule to find out if the process is running?
Maybe there is a better solution?
Btw: I am using NetXMS Version 2.0.7.
Thanks in advance guys.
Best regards,
Danny
Okay- I just solved my own problem.
In case somebody wants to do something similar (or maybe for the docs) here is how I solved this:
process = "My-Running-SW-In-The-hrSWRunTable.exe"; // defines process name for lookup
// Create SNMP transport for node
transport = CreateSNMPTransport($node);
if (transport == null) {
return false;
}
// walk over running software processes
// .iso.org.dod.internet.mgmt.mib-2.host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunName
vars = SNMPWalk(transport, ".1.3.6.1.2.1.25.4.2.1.2");
if (vars == null) {
return false;
}
found_process = false; // set flag initially to false
// find process, set flag and break loop if process found
foreach (v: vars) {
if(v->value == process) {
trace(1, "SNMP WALK; Search for process: ".process."; Found: ".v->name."=".v->value);
found_process = true;
break;
}
}
if (found_process == true) {
return true; // process has been found
} else {
return false; // process has not been found
}
Best regards,
Danny
Just one comment: code block
if (found_process == true) {
return true; // process has been found
} else {
return false; // process has not been found
}
could be replaced with simple
return found_process;
Best regards,
Victor