[Nagiosplug-help] Event Handlers and NRPE

Philip Marcus pmarcus at structuredcommons.com
Fri Sep 12 00:06:42 CEST 2008


Dear Nagios Users,

(As I was writing this question, I tried something out which Solved my
problem, I'll include everything as I originally wrote it plus the
solution for future reference.)

I'm trying to use NRPE in conjunction with event_handlers, such that
when a service check enters a SOFT/HARD state an event_handler
executes an NRPE call to do something on the remote machine (like
restart apache).

I've got it *almost* working except that I don't know how the command
line arguments are passed to the check_nrpe command from the
event_handler definition.

Here are my relevant configs, what works and what doesn't:

Webserver running NRPE: I'll call this Web1
nrpe.cfg:
command[restart_apache]=/usr/local/nagios/libexec/eventhandlers/restart_apache
$ARG1$ $ARG2$ $ARG3$
(Note: To allow NRPE to accept command line arguments from a client,
you need to compile it with "./configure  --enable-command-args"  as
well as enable it in the nrpe.cfg with "dont_blame_nrpe=1"     This
has security implications mentioned in the SECURITY readme included
with the nrpe distribution. Read it!)


Nagios server: I'll call this Monitor1
commands.cfg
# check nrpe_event
define command{
        command_name    check_nrpe_event
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
-a $ARG2$ $ARG3$ $ARG4$
        }


from monitor1, if I run the command from the CLI as such:

../libexec/check_nrpe -H web1 -c restart_apache -a CRITICAL SOFT 2     or
../libexec/check_nrpe -H web1 -c restart_apache -a CRITICAL HARD 3

It works perfectly.

>From my service definition however, it doesn't work. Here is that definition:
define service{
        use                             local-service
        host_name                          web1
        service_description              HTTP
        check_command                 check_http
        event_handler                     check_nrpe_event!restart_apache
        }

It seems like no arguments ($ARG2$, $ARG3$, $ARG4$) are passed  to the
restart_apache check.

I've tried forcing the arguments like this:
define service{
        use                             local-service
        host_name                          web1
        service_description              HTTP
        check_command                 check_http
        event_handler
check_nrpe_event!restart_apache!CRITICAL!HARD!3
        }

And that works, however it has unintended consequences as its executed
for every SOFT/HARD State change.

My question:
Is it possible, and if so, How do I pass the $SERVICESTATE$,
$SERVICESTATETYPE$, $SERVICEATTEMPT$  to the event_handler
check_nrpe_event!restart_apache service definition?

Reading my own question above, I just tried this:

define service{
        use                                    local-service
        host_name                        web1
        service_description            HTTP
        check_command               check_http
        event_handler
check_nrpe_event!restart_apache!$SERVICESTATE$!$SERVICESTATETYPE$!$SERVICEATTEMPT$
        }

And it works!!!


Thank you Nagios and NRPE.

Philip




More information about the Help mailing list