As of version 1.53 a new generic event handler script has been included in the download bundle. Restart Windows services etc
This is a generic use, parameter driven event handler script. It allows for simple command definitions to run event handlers under various conditions.
Initial command definitions have been provided that can restart Windows services and reboot Windows computers (take care with this one!).
The command definitions (event_restart_win_service and event_reboot_win) are right at the bottom of this page.
An example service definition (Services - Print Spooler) is on this page.
The example commands use the
net command that is part of the Samba suite. This command provides remote access to Windows machine and among other things allows you to remotely restart services and reboot the computer. The particular command, therefore, must be installed for these event handler examples to work.
The event handler script is not limited to Windows. It can run any commands on the Nagios host.
It can run multiple commands depending on
- The type of Nagios alert (SOFT or HARD)
- The number of times the check has SOFT alerted
- If the check is the last SOFT check before the service check goes to HARD state (and notifications etc are sent)
- The text contained within the service output or the text not contained in the service output
- If the alert type is WARNING, CRITICAL, UNKNOWN or OK
Run the script event_generic.pl with no parameters to read the detailed help which also contains multiple examples.
This event handler relies on Nagios setting environment variables so that it can work out service status, check attempts etc. These variables must be passed in the environment when the event handler is run.
In the nagios config file the setting.
enable_environment_macros must be enabled.
If this setting is not enabled, this event handler can not work at all.
If you are using sudo to run your event handlers you may need to enable passing of the Nagios environment variables in the sudoers files.
Normally you will need a configuration entry like
Defaults env_keep = "NAGIOS*" (if its the first entry)
Defaults env_keep += "NAGIOS*" (if there are multiple entries - add this line after the others)
Troubleshooting any event handler is tricky. When an event handler is run by Nagios a whole lot of environment variables are set that are critical to the operation of the event handler. So to properly run an event handler, you need to provide all these variables. Just running it from the command line without setting these variables will not work. There are a couple of ways to sort this out.
1) Set them all on the command line yourself. The ones you need to set are all listed in the first 40 lines or so of the event handler code. This does give you fine control over testing. We actually made it easy to do this by providing the -e ENVTEST parameter. Run the event_generic.pl with no parameters to read the detailed help on how to use the ENVTEST setting.
2) Let Nagios do all the work. Set up the checks/event handler via Nagios and then make the service fault. An easy way to do this is to submit Warning/Critical events to Nagios by using the "Submit passive check result for this service" link on the service page. Submit one and then simply reload your browser screen to resubmit multiple.
Often you'll find you need more information about what the event handler is doing. Add -d FILENAME to this event handler command line and it will dump a whole lot of info about what it is doing to FILENAME. You need to make sure FILENAME is writable by the Nagios process. If you get nothing in FILENAME then Nagios is not triggering it (or maybe you still have a permissions problem). If FILENAME is the string "stdout" then the plugin will dump everything to STDOUT (only useful if running from the command line).
Also, adding the -x option will include all the Nagios environment variables which can sometimes add more value to the debug information.