You are here

Blog

Using Event Handlers with Opsview

Event Handlers in OpsviewEvent 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:

if

then

        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"

fi

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/

Opsview Event Handlers

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:

event handler check

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”:

Apply event handler changes

Now when Apache fails, we should automatically try and start it again thanks to our event handler.

Get unified insight into your IT operations with Opsview Monitor

webteam's picture
by Opsview Staff,
Administrator

More like this

Feb 05, 2016
white_paper
By Opsview Staff, Administrator
Summary
Nov 22, 2016
blog
By David Chatterton, Customer Success Engineer

Proactive monitoring continues to prove its significance for all types of organizations.

Feb 05, 2016
white_paper
By Opsview Staff, Administrator
Overview