Event Handler


Can anybody see the problem with my event handler? Its purpose is simply to email the IT dept when our LVS cluster fails from one to the other. The event handler works fine and is activated at the correct time but it is not reading the $CONTACTEMAIL$ macro passed to it. The command def is:

define command{
command_name lvsnotify
command_line /usr/local/nagios/libexec/eventhandlers/LVS.sh $SERVICESTATE$ $STATETYPE$ $SERVICEATTEMPT$ $CONTACTEMAIL$

And the event hadler script is:

**# What state is the LVS service in?
case “$1” in
# The service just came back up, so don’t do anything…
# We don’t really care about warning states, since the service is probably still running…
# We don’t know what might be causing an unknown error, so don’t do anything…

    # Is this a "soft" or a "hard" state?
    case "$2" in
            /usr/bin/printf "=======>>> *****WARNING***** <=======\n\nActive LVS server may have changed, please check..." | /bin/mail -s "************* LVS FAILOVER *************" "$4"

exit 0**

The event handler reads all of the arguments passed except the “$4” which is the CONTACTEMAIL. I can see the eventhabdler activating in the log file and if I pass the email addresses manualy in the script or on the command line as nagios it works.

Can anybody help?


possibly worth checking with quotes and/or escaping the . and @



Sorry I dont follow…


i was thinking of putting the email address in quotes. but it already is quoted in the script…

looking at the mail scripts from nagios i noticed the $CONTACTEMAIL$ macro is NOT quoted… possibly this?



you mean the $4 variable? Already tried this with and without quotes. Im no programmer but my scripts are normally ok. This one has got me stumped, it executes the eventhandler and as ive stated before if I pass the arguments on the command line ie:

/usr/local/libexec/eventhandlers/LVS.sh CRITICAL HARD 3 lgill@lgill.com

it works??


Since you didn’t use $3 in your script, why not remove $SERVICEATTEMPT$ and make it:
command_line /usr/local/nagios/libexec/eventhandlers/LVS.sh $SERVICESTATE$ $STATETYPE$ $CONTACTEMAIL$
Of course, change your script to use $3 instead of $4.


Already tried this, have tried again but no joy im afraid. Am I going mad or does this make no sense at all!


Try replaceing $CONTACTEMAIL$ with $ARG1$


In the Command definition?


Forget that last suggestion and take a look here:
Notice how it says
$CONTACTEMAIL$ No No for Service Event Handlers, Global Service Event Handler, OCSP Command Host Event Handlers, Global Host Event Handler, OCHP Command.
So, that macro is not available to the event handler.
But, it does say that $ARGx$ is available to the event handler, so yes, perhaps you should define a ARG5 or 6 or something in your resource.cfg file and make your command line look like this:
command_line /usr/local/nagios/libexec/eventhandlers/LVS.sh $SERVICESTATE$ $STATETYPE$ $ARG5$


I could add the email addresses in resource.cfg i.e


But this is the same as adding the mail addresses in the script, as I am doing at the moment. Ultimatley I would like to use the $CONTACTEMAIL$ macro. I have tried:


This doesn’t work, any suggestions?


Well, as I said, $CONTACTEMAIL$ is not valid for event handlers, so of course $USER10$ = $CONTACTEMAIL$ isn’t going to work either.
$USER10$ is valid, and could be used.


So theres no way of re-defining $USER10$ to read from the contact.cfg file to do the same job as $CONTACTEMAIL$ does in the notification?


I just realized, why are you using an eventhandler, instead of notification logic to alert you? It might be a better idea to define your command in misccommands.cfg and turn off event handling.


When a particualr service is critical on our server, it fails over to the pasive server. All i want nagios to do is send out 1 notification to the contactgroup. If I use the notification logic I get a recovery as well. I suppose I could set up a dedicated group for LVS failover but it seems a bit overkill for one e-mail.

I’ll just set the e-mails in the scripts manually


For that contact group, just don’t allow recovery alerts, if you don’t want them. Or, define it in the service, and the service/host will not notify upon recovery.


Ahh yes but I want recovery notification for the actual service check. I just want 1 e-mail to tell support there may have been a failover…?