Monday 18 April 2016

NAGIOS: Handling state changes with event handlers

Event handlers allow us NAGIOS to perform action based on the state of a specific check.

For example if a host goes into hard problem state we could instruct nagios to execute a remote command through the NRPE plugin to restart the service.

We also have the ability to define a global host (or service) event handlers - for example if you wanted to run a script every time a host changes state. This can be performed by adding either (or both):




within nagios.conf.

Although personally - I am much more interested in performing an action based on when a specific service changes state. To do this we need to firstly define our new command (that will restart our service) in commands.cfg e.g.

define command{
command_name restart-httpd
command_line /usr/local/nagios/libexec/eventhandlers/restart-servicexyz  $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$

and add the event_handler variable which defines our command to our services configuration e.g.:

event_handler restart-httpd

Lastly we need to create a script that will act as our event handler - there is a good example here:


Post a Comment