Nagios nrpe Tomcat service restart


#1

Hi all,

I’ll try to explain my problem, I’d like nagios to restart my tomcat service in another host. And seems that the configuration is not 100% good as the event handler is not starting the script in the tomcat server.

My environment is:
Nagios Server has nagios 3.0
The service configuration uses generic-service with max_attempts to 4 and is the following:

define service{
use generic-service
host_name SERVER68
service_description Ping WebApup
check_command check_http!-H SERVER68 -u IP:54321/pingWebapp.jsp -p 54321 -s OK
event_handler restart-tomcat0!$SERVICESTATE$!$SERVICESTATETYPE$!$SERVICEATTEMPT$
notifications_enabled 1
}

I setup a eventhandlers.cfg file called from nagios.cfg that creates a command:

define command{
command_name restart-tomcat0
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c restart-tomcat0 $ARG1$ $SARG2$ $ARG3$
}

In the tomcat server I have running nrpe.2-12 compiled with --enable-command-args to allow remote commands and configured with dont_blame_nrpe=1:
ps axu |grep nrpe
nagios 7580 0.0 0.0 39880 1024 ? Ss 11:16 0:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/bin/nrpe.cfg -d

And in nrpe.cfg I have the following command:
command[restart-tomcat0]=/usr/local/nagios/libexec/eventhandler/restart-tomcat0 $ARG1$ $ARG2$ $ARG3$

Well that was the configuration, now the logs. When I shutdown the Tomcat service the Nagios server log writes the following:

[1216116472] SERVICE ALERT: SERVER68;Check Booking;CRITICAL;SOFT;1;Connection refused
[1216116472] SERVICE EVENT HANDLER: SERVER68;Check Booking;(null);(null);(null);restart-tomcat0!$SERVICESTATE$!$SERVICESTATETYPE$!$SERVICEATTEMPT$
[1216116502] SERVICE ALERT: SERVER68;Ping WebApup;CRITICAL;SOFT;1;Connection refused
[1216116532] SERVICE ALERT: SERVER68;Check Booking;CRITICAL;SOFT;2;Connection refused
[1216116532] SERVICE EVENT HANDLER: SERVER68;Check Booking;(null);(null);(null);restart-tomcat0!$SERVICESTATE$!$SERVICESTATETYPE$!$SERVICEATTEMPT$
[1216116562] SERVICE ALERT: SERVER68;Ping WebApup;CRITICAL;SOFT;2;Connection refused
[1216116592] SERVICE ALERT: SERVER68;Check Booking;CRITICAL;SOFT;3;Connection refused
[1216116592] SERVICE EVENT HANDLER: SERVER68;Check Booking;(null);(null);(null);restart-tomcat0!$SERVICESTATE$!$SERVICESTATETYPE$!$SERVICEATTEMPT$

Here it’s supposed the event handler to execute the script what does not.

[1216116622] SERVICE ALERT: SERVER68;Ping WebApup;CRITICAL;SOFT;3;Connection refused
[1216116652] SERVICE ALERT: SERVER68;Check Booking;CRITICAL;HARD;4;Connection refused
[1216116652] SERVICE EVENT HANDLER: SERVER68;Check Booking;(null);(null);(null);restart-tomcat0!$SERVICESTATE$!$SERVICESTATETYPE$!$SERVICEATTEMPT$

Also here it’s supposed the event handler to execute the script what does not.

[1216116682] SERVICE ALERT: SERVER68;Ping WebApup;CRITICAL;HARD;4;Connection refused

The strange thing comes up when from the Nagios Server command line I execute the nagios command and restart the service.

/usr/local/nagios/libexec/check_nrpe -H SERVER68 -c restart-tomcat0 -a CRITICAL SOFT 3

The log from nrpe in the Tomcat server does not write anything special (my guess):

Jul 15 11:59:18 SERVER68 nrpe[7580]: Daemon shutdown
Jul 15 11:59:20 SERVER68 nrpe[9198]: Starting up daemon
Jul 15 11:59:20 SERVER68 nrpe[9198]: Warning: Daemon is configured to accept command arguments from clients!
Jul 15 11:59:20 SERVER68 nrpe[9198]: Listening for connections on port 5666
Jul 15 11:59:20 SERVER68 nrpe[9198]: Allowing connections from: IP Nagios Server

What am I doing wrong?

Thank you,
Carlos


#2

Hey all, well finally I found the problem. I made a silly mistake in eventhandlers.cfg in the Nagios Server, the second argument was bad written, instead of $ARG2$ I wrote $SARG2$.

define command{
command_name restart-tomcat0
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c restart-tomcat0 $ARG1$ $SARG2$ $ARG3$
}

So, the goog thing is that this topic will also help Nagios admins to set up nrpe to restart services remotely with command arguments.

thank you,
Carlos