I would like Nagios to execute a Bash command/script when it detects a host down or up. This would allow me to react to down hosts to some degree which would be very interesting.

How would I do this ?

link|improve this question

feedback

2 Answers

up vote 4 down vote accepted

Event handlers are your friends: http://nagios.sourceforge.net/docs/3_0/eventhandlers.html.

link|improve this answer
Thank you very much that is exactly what I was looking for :-) – Antoine Benkemoun Dec 20 '10 at 17:05
feedback

into your commands file add the command you need

define command{
# try this before

command_name my_restart
command_line /usr/lib64/nagios/plugins/my_restart.sh $HOSTADDRESS$ $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
}   

into your service defination

define service{
 .....
event_handler           my_restart
 ....

}

the arguments that you receive into your script are the ones defined into the command file, you can see them as well by doing echo $@ into your script - is important to know the host address in case that you will call against a remote host and the service state (you take different actions on CRITICAL, OK or WARNING)

i suggest you have some logging into your script at least at the beginning.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.