You are here
Using Event Handlers with Opsview
Event handlers are a very neat feature which allows your Opsview system to move away from “just monitoring” to pro-actively trying to rectify a fault when it appears.
For example, if Apache fails and the service goes to critical, we can have an event handler automatically (i.e. without any administrator involvement) restart/start the apache process again, which can save a lot of downtime and business outages.
To do this, you must first create the script you wish to have ran. In this example, our Perl/Python script will be starting an apache2 instance - so it will run when our service check “Apache2 processes” goes critical (i.e. “0”), against our web server host.
For reference, The example script is below:
echo "restarting apache"
# insert event handler action here...
/usr/local/nagios/libexec/check_nrpe -H $NAGIOS_HOSTADDRESS -c eh_apache_restart >/dev/null 2>&1
# record event to syslog
logger "Apache 2 restarted by Opsview $NAGIOS_HOSTADDRESS"
The key parts are in bold. The first part just shows that when the service check goes to “critical”, i.e. apache is 0, then do the 2nd part, i.e. restart apache or whichever action or command is relevant your install.
To allow Opsview to run your event handler, you will need to store it in: /usr/local/nagios/libexec/eventhandlers/
As you can see, we already have our apache_restart script in there, which will simply run a command such as “/etc/init.d/apache2 start” when the service fails.
Now that we have done the hard part of creating our event handler, we will need to add it to the appropriate service check.
To do this, log in to your Opsview installation, and navigate to “SETTINGS > SERVICE CHECKS”, and click on the service check in question; in our example “HTTP”.
Once inside your service check, click on “Advanced”, and you will see a window similar to below:
As you can see, we have a field called “Event Handler”. In this field, we just enter the name of the script - “apache_restart”, and click submit. And again, apply our new configuration via “SETTINGS > Apply Changes”:
Now when Apache fails, we should automatically try and start it again thanks to our event handler.
More like this
Proactive monitoring continues to prove its significance for all types of organizations.