Page 1 of 1

NRDS and Event Handlers

Posted: Thu Jan 28, 2016 9:28 am
by blariv
I cannot seem to get this to work and I'm sure it is even supported. Remote Linux passive disk checks w/ NRDS and trying to run a logrotate event handler.

Do i need to have active checks to trigger the handler?

command[Check Disk]=/usr/local/nagios/libexec/check_disk -w 10% -c 5% -p /
$USER1$/check_nrpe -H $HOSTADDRESS$ -c "/usr/sbin/logrotate -f /etc/logrotate.conf"

CentOS release 6.3 (Final)
Nagios XI Version : 2012R2.7

Thanks!

Re: NRDS and Event Handlers

Posted: Thu Jan 28, 2016 1:11 pm
by lmiltchev
This should work but it will require some work.

1. First, make sure you can run "logrotate" as nagios user.

Code: Select all

su nagios
sudo /usr/sbin/logrotate -f /etc/logrotate.conf
Most probably, you will need to modify the "/etc/sudoers" to make this work. I was running XI on my remote machine, so I added the following two lines:

Code: Select all

NAGIOSXI ALL = NOPASSWD: /usr/sbin/logrotate *
NAGIOSXIWEB ALL = NOPASSWD: /usr/sbin/logrotate *
2. Setup a command in the "/usr/local/nagios/etc/nrpe/common.cfg" or "/usr/local/nagios/etc/nrpe.cfg", depending on how you installed NRPE.

Code: Select all

command[logrotate]=sudo /usr/sbin/logrotate -f /etc/logrotate.conf
Restart xinetd (or NRPE if it's running as a standalone daemon) so that changes can take effect.

Note: If you test this command from the CLI on the Nagios XI server, you will get an error, because there is no output that is returned.

Code: Select all

[root@localhost tmp]# /usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c logrotate
NRPE: Unable to read output
Don't worry about it - you can temporarily change your command to this:

Code: Select all

command[logrotate]=sudo /usr/sbin/logrotate -f /etc/logrotate.conf;echo "Logs rotated"
just for testing purposes.

Code: Select all

[root@localhost tmp]# /usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c logrotate
Logs rotated
3. Create a command to be used as an event handler, for example:
example01.PNG
4. Modify your "disk" service to use the event handler.
example02.PNG
5. Double check the host config for the "disk" service to make sure the "Address" filed contains a valid IP address. As this is a passive check, you may have a name in the address filed, which will cause the "$HOSTADDRESS$" macro not to resolve.

Hope this helps. Let us know if you run into some issues.