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:
**# What state is the LVS service in?
case “$1” in
OK)
# The service just came back up, so don’t do anything…
;;
WARNING)
# We don’t really care about warning states, since the service is probably still running…
;;
UNKNOWN)
# We don’t know what might be causing an unknown error, so don’t do anything…
;;
CRITICAL)
# Is this a "soft" or a "hard" state?
case "$2" in
SOFT)
;;
HARD)
/usr/bin/printf "=======>>> *****WARNING***** <=======\n\nActive LVS server may have changed, please check..." | /bin/mail -s "************* LVS FAILOVER *************" "$4"
esac
;;
esac
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.
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 [email protected]
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.
Forget that last suggestion and take a look here: nagios.sourceforge.net/docs/2_0/macros.html
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
$USER10$=lgill@…
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:
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.
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.
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.