Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 ?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Event handlers are your friends:

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

into your commands file add the command you need

define command{
# try this before

command_name my_restart

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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