5

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 ?

Antoine Benkemoun
  • 7,314
  • 3
  • 42
  • 60

2 Answers2

7

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

Massimo
  • 70,200
  • 57
  • 200
  • 323
3

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.

silviud
  • 2,687
  • 2
  • 18
  • 19