Have Nagios execute a command when it detects a down host

Solution 1:

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

Solution 2:

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.