Automatic Config of new objects

Started by MatthewDreher, May 18, 2016, 09:17:58 PM

Previous topic - Next topic

MatthewDreher

Hello all,

I'm setting up NetXMS for the first time and was wondering if there's an easy way to do what I'm looking for.  Here's the end goal:  When I add a server/node, I'd like to automatically scan it for services (probably based on a set of pre-determined ports) and automatically add monitors to it for those services. 

Any thoughts?

Thanks

tomaskir

You can do this with auto-bind templates.
(auto-bind scripts are run on each configuration poll)

We do exactly this in our system, when we add a device NetXMS will basically automatically discover what is available on that device, and start monitoring it.

MatthewDreher

Mind sending me a sample?  I'm quite new to setting this up.

tomaskir

Here is an example of how to bind a template to a node if its running "freeradius" process.
We use this to automatically bind templates which monitor FreeRadius on VMs running it.

searchProcess = "freeradius";
procArray = AgentReadList($node, "System.ProcessList");

if (procArray == null)
  return false;

foreach (process : procArray) {
  if (index(process, searchProcess) != 0)
    return true;
}

return false;



Here is the auto-bind script we use with our MikroTik monitoring template.

return $node->sysDescription ~= "RouterOS";


Here is a bit more complex one.
This one binds a template which monitors a PPPoE access concentrator.
Basically, if a node terminates at least 1 client pppoe connection, this template is bound to it.

transport = CreateSNMPTransport($node);
if (transport == null)
  return false;

// this is the ppp-like connection count OID
oid = ".1.3.6.1.4.1.9.9.150.1.1.1.0";

pppCount = SNMPGetValue(transport, oid);
if (pppCount == null)
  return false;

if (pppCount > 0)
  return true;

return false;


You can find full documentation on NXSL here:
https://wiki.netxms.org/wiki/Scripting_Guide

MatthewDreher

That helps a ton.  One final question.  If I want a template to automatically apply a service check against a server (custom port 80 or http check for example) how would I put that in?  Would I just use localhost and port 80? 

ServiceCheck.Custom(localhost,80) with threshold >= 1

Sorry if these sound like horribly newbie questions.

tomaskir

#5
If you want to check the website from the agent running on that node, then yes.
(that is not very useful tho, because it may run locally, but may not run remotely)

So usually, you want to check from the NetXMS server.
Here you would set "Source node" to the NetXMS server.

Assuming you are binding from the template then, you would set the DCI parameter as:
ServiceCheck.Custom(%{node_primary_ip},80)

This will replace the %{node_primary_ip} macro in each DCI for the IP address of the node the DCI is bound to.
https://wiki.netxms.org/wiki/UM:Data_Collection#Macros_in_template_items

As a last note, I recommend doing ServiceCheck.HTTP rather than ServiceCheck.Custom, since it will actually check the website returned.
Documentation here: https://wiki.netxms.org/wiki/Subagent:PortCheck

MatthewDreher

Ok, then how would I get it to automatically apply to the netxms server?  Does just returning true in the script add the template to the netxms server and $node adds it to the newly added node?

tomaskir

Template auto-bind script it evaluated against each node during that node's configuration poll.
So "return true;" will bind it to that node.

If you want to bind only to the NetXMS server itself, use

return $node->isLocalMgmt;

MatthewDreher

Perfect.  I think that's all I need at this point.  Really appreciate the assistance.

MatthewDreher

nm, definitely got more questions.

So, using your above code, I have a server that has IIS installed.  Ideally, I'd look for the open port or a service on the box.  In this case, the service is w3wp.exe, the iis service.  I'd like the template to apply once the node is added, add the template to the netxms server, and automatically monitor the new node for port 80

Auto Apply rule would be this:

searchProcess = "w3wp.exe";
procArray = AgentReadList($node, "System.ProcessList");

if (procArray == null)
  return false;

foreach (process : procArray) {
  if (index(process, searchProcess) != 0)
    return $node->isLocalMgmt;
}

return false;


and dci paramater would be ServiceCheck.Custom(%{node_primary_ip},80) (I'm just doing the custom port for simplicity atm, I'll be adding in the http later).

Not working obviously.

tomaskir

Your above code will apply this template to a node that has the "w3wp.exe" process running AND is the NetXMS server itself.

Is this really what you want to do?

MatthewDreher

no, I want to check the node to see if it has the service running, then apply a monitor to the netxms server to monitor against the node for port 80

tomaskir

Your auto-bind script will be

searchProcess = "w3wp.exe";
procArray = AgentReadList($node, "System.ProcessList");

if (procArray == null)
  return false;

foreach (process : procArray) {
  if (index(process, searchProcess) != 0)
    return true;
}

return false;


On the DCI, the parameter will be:

ServiceCheck.Custom(%{node_primary_ip},80)


Make sure to set "Source node" in the DCI configuration to the NetXMS server.

The template will be bound to the node running the IIS server, not to the NetXMS server.
(since the NetXMS server is not the one offering the HTTP service, the DCI should not be on the NetXMS server)

The service check will be performed from the NetXMS server to the IIS node tho.
(that is what the "Source node" setting configures)

MatthewDreher

Ok, perfect.  Thanks again for the help.