[SOLVED] Nagios integration

Started by Guillaume, May 11, 2015, 05:25:57 PM

Previous topic - Next topic

Guillaume

Hello everyone!

I am trying to make the switch from Nagios to NetXMS and things have not been easy. Since the network service part of NetXMS is kind of on and off, I was wondering if it would be possible to use NetXMS's scripting interface to interact with the already-installed nrpe plugin on every server?

The command to interact with such a plugin is quite simple, something like:

/usr/lib64/nagios/plugins/check_nrpe -H webserver -c check_disk_custom -a 20 10 /

Where the syntax is
-H: target host
-c: the custom command to run on the remote server
-a: a list of arguments

In my example, the plugin checks for free disk space on "webserver" on the disk "/" with a 20% and a 10% threshold.

Would such a scripted solution be acceptable and, if so, where/how can I code it?

Thank you!

Alex Kirhenshtein

You can add them as external parameter (please note that "$" is escaped):
ExternalParameter=CheckDiskCustom:/usr/lib64/nagios/plugins/check_nrpe -H webserver -c check_disk_custom -a 20 10 / >/dev/null 2>&1 ; echo $$?

Guillaume

Hello!

Thanks for the really quick reply, it's super appreciated. I am not really clear on where to put such external parameter...

Is it in the agent configuration of the NetXMS server? If so, I tried adding a test line in nxagentd.conf file but after that I am unsure of where to use it in the web console...

Is it in the target server's agent configuration? Since I am trying to avoid installing the agent on every server so it's not really an option...

Thanks for any clarification

Alex Kirhenshtein

Yes, it's part of agent configuration (nxagentd.conf).
You can use single instance of the agent, for example:
ExternalParameter=CheckDiskCustom(*):/usr/lib64/nagios/plugins/check_nrpe -H $1 -c check_disk_custom -a 20 10 / >/dev/null 2>&1 ; echo $$?

then configure DCIs on the server: CheckDiskCustom(webserver), CheckDiskCustom(dbserver), etc. $1 will be int he command will be replaced with first DCI parameter, $2 will be replaced with second and so on.

If you want these DCIs to appear on the target nodes (e.g webserver) instead of keeping them all on the node where agent is installed – create them there and select server where agent is running as DCI proxy. Check this post for additional explanation: https://www.netxms.org/forum/configuration/netxms-agent-checks-on-non-agent-compatible-hosts/

Guillaume

Good morning!

I "successfully" added an External parameter on my monitoring server and I can add it in the Data Collection Configuration section of my netxms server node. The exact line I added, for future reference, is this one:
ExternalParameter=Nagios(*):/etc/netxms/plugins/$1 -H $2 -c $3 -a $4 / >/dev/null 2>&1 ; echo $$?

After adding it in netxms server's DCI page, I have a first question:
How can I get the "full" return of the command? (I know that I can then extract the part I need with the scripting part of the DCI)

What I mean is, the command
/etc/netxms/plugins/check_nrpe -H webserver -c check_disk_custom -a 20 10 /
returns something like:
DISK OK - free space: / 961 MB (50% inode=84%);| /=951MB;1995;2005;0;2015
In the Last Value page of the node though, I only have numeric value even though I defined the DCI return as "String". What am I missing?

Second question:
On my "target" node, I tried defining a new DCI with my netxms server as the proxy in order to have access to my custom "Nagios(*)" command. Unfortunately, I am unable to access any parameter... Am I missing some key configuration part here, or do I need to open some specific port in my firewalls so my target node can receive the parameters list from the server node?

Thank you again for your great support! You truly are a "Hero Member"

Victor Kirhenshtein

Hi,

value of external parameter is whatever is written to stdout by command. So you can simply remove redirection to /dev/null:


ExternalParameter=Nagios(*):/etc/netxms/plugins/$1 -H $2 -c $3 -a $4 / 2>&1


Best regards,
Victor

Guillaume

#6
Thank you!  ;D

I managed to get most of the commands working! I will continue tweaking until I get the result I want.

A few questions still stand though:

When I try to add a Nagios DCI directly on the target node (Those commands are on the netxms server so I have to define it as proxy) I do not get any parameter listing. When I create those DCI's in a template though, I can apply this template to any node and the DCI is working and can be modified. Is this an interface bug, or am I missing something in my configuration (like a port in the firewall)?
EDIT: I can add the DCI "manually", but the popup produced by the Parameter's "Select..." button shows nothing.

How can I properly split the resulting string of my command in order to get a convincing output? Can I do it directly in netxms or would it be better to make an external script to pre-format the command's result before passing it to netxms? I looked through https://wiki.netxms.org/wiki/UM:NetXMS_Scripting_Language_(NXSL) for something similar to a split function but to no avail.

Victor Kirhenshtein

When you use "Select" button for DCI configuration, it get parameters supported by node you are configuring it on, not by proxy node (which actually an interface bug). When you do it in template, it shows all parameters supported on at least one node.

You can use any approach for splitting - whatever is easier for you. In NXSL often most efficient way to split string is to use regular expressions. For example, for string like this:

DISK OK - free space: / 961 MB (50% inode=84%);| /=951MB;1995;2005;0;2015

it could be


if ($1 match "^DISK ([A-Za-z]+).*free space:.*([0-9]+) .*")
{
    // here $1 will contain status ("OK" in example)
    // $2 will contain free space (961 in example)
}


Best regards,
Victor

Guillaume

Thank you again, Victor and Alex!

My issue is "resolved", now I have to craft a solution to extract the values I want. On to other challenges!! (Like LDAP integration....)