Instance Discovery using Agent Table method

Started by gdodd, April 20, 2021, 12:18:59 AM

Previous topic - Next topic

gdodd

I am trying to write a discovery filter script for Windows services that start with a common name and are set to auto startup. I have experimented with different things all day with no luck.

Here is what I thought would work, but it does not

name = $1->get(0);
startup =  $1->get(4);
if (name like "3CX*" && startup == "Auto")
{
return true;
}
return false;

I was hoping $1 would return a row but seems it does not.

In the manual it says values are returned with ~~~ between them, but I am not sure how to read those in the script.

Any assistance would be appreciated.

Gary

Victor Kirhenshtein

Hi,

when using agent table for instance discovery instance names are taken from instance column in the table, in case of System.Services it will be service name. So $1 in filter script is always instance, you have no access to actual table row. I suggest to use script as instance discovery method instead of agent table, and process table i that script instead. It could looks like following:


services = $node->readAgentTable("System.Services");
if (services == null)
   return null;

instances = %();
for(r : services->rows)
{
   name = r->get(0);
   startup = r->get(4);
   if (name like "3CX*" and startup == "Auto")
      instances->append(name);
}

return instances;


Best regards,
Victor

gdodd


2b2bff

Just tried to use this as a starting point, but

$node->readAgentTable("System.Services");

does not work. However the older syntax
AgentReadTable($node, "System.Services");
does work.

What do I miss? A bug in 3.8.382?

gdodd

I am running 3.8.382. I just tested the script as written in this post and it finished successfully. So I do not think it is a bug.

Can you post your script and any error messages?

Gary

2b2bff

Wait, what? I just tested it again and it works...  :-[

You shouldn't change too much in a script at the same time. I tried to return an array of arrays in the script to work with the individual array in the filter script, but it seems you only can return an array of strings.

Hanfelt

Can you guys in this thread please show me with a couple of screenshots how you configured this. It seems im missing something out in my data collection configuration / template.

gdodd

I created a script in the Script Library names ThreeCXServiceFilter (I changed from == "Auto" to like "Auto*" because some are "Auto (Delayed)")

services = $node->readAgentTable("System.Services");
if (services == null)
   return null;

instances = %();
for(r : services->rows)
{
   name = r->get(0);
   startup = r->get(4);
   if (name like "3CX*" and startup like "Auto*")
      instances->append(name);
}

return instances;


In my template I added a Data Collection Configuration. See the screenshots for that configuration.

Let me know if you need anything else.

Hanfelt

Thank you so much  ;)

You know what i did i pasted the code in "Instance Discovery -> Instance discover filter script". No wonder it didnt work  ;D

Thanks again and have a great day.

Hanfelt

Ill add some more info to this. If someone wants a more readable status of the service poll you should under General change Data type to "String"

Then you go to Transformation and paste this code:

switch ( $1 )
{
case "0": return "Running";
case "1": return "Paused";
case "2": return "Start pending";
case "3": return "Pause pending";
case "4": return "Continue pending";
case "5": return "Stop pending";
case "6": return "Stopped";
case "255": return "Unable to get service state";
default: return "INVALID VALUE (".$1.")";
}


If you want to get notified via lets say e-mail when a service stops you will need to look at Thresholds, Event processing policy and also Actions configuration.