Using Nagios to trigger corrective action


#1

Is there a way to tell nagios to perform an action if an alert condition is met? For my specific situation, I’m monitoring disk space on a device. If the free space becomes 90% full, I’d not only like an alert, but would like to be able to touch a sentinel on each host that sends data to this device so that no further data is sent.

I apologize if this is a basic question. I have to claim Nagios newbie immunity. :slight_smile:

Thanks,
Aaron


#2

aachleon:

nagios has an event handler which can be configured to perform a specific action if an alert is triggered; you could use this to issue a command to the remote host where the device is (e.g. via nrpe)

however, if all you want is to only be notified once when the alert condition is met, you can configure this in the service object definition by setting the notification_interval directive to 0

hope this helps…


#3

You bet you can.
Have a look at your contacts.cfg. See how it’s using “service_notification_commands notify-by-email”? That means when a service alert happens and that contact (or contact group with that user in it) is listed in your service definition, it will run “notify-by-email”.

Have a look at your misccommands.cfg. See that “notify-by-email” command? that is what’s run when nagios sends out a service alert.

So what you need to do is define another command in misccommands.cfg. eg:
define command{
command_name touch-sentinel
command_line /bin/sentinelscript.sh
}

then make your sentinelscript.sh do what you need it to do! but heres the thing, make the script so that if you run it once, it touches the sentinal so that the data is no longer sent, but if it’s run again, it re-enables it. This is so that when the CRITICAL alert is sent out, it runs your sentinal script disabling what it needs to. Then when free space is recovered, you get an OK alert, and the script runs again to enable the sentinels again. I’m not sure how you’re going to do this since i’m not there, might i suggest keeping a file on the hosts with a 1 or a 0 in it, then doing a certain action based on that, and switching the number as necessary?

so, your last step, add the touch-sentinel command definition to your contacts.cfg.
“service_notification_commands notify-by-email,touch-sentinel”

not sure about the comma here. might want to test with a simple script to make sure it’s running the next command.

Good luck!