Setting up an event handler script
In this recipe, we'll learn how to set up an event handler script for Nagios Core. Event handlers are commands that are run on every state change for a host or service (whether for all hosts or services, or just particular ones). They are defined in a similar way to notification commands and check commands for plugins.
In this example, we'll implement a simple event handler that writes the date, the host state, and the number of check attempts to a separate file for a single host. This is a trivial example to demonstrate the concept; a more practical and complex application for the use of event handlers is given in the Setting up a redundant monitoring host recipe, in Chapter 10.
Getting ready
You will need a server running Nagios Core 3.0 or higher. You should be familiar with defining new commands, as per the Creating a new command recipe in Chapter 2 and the Writing low-priority notifications to an MOTD recipe in Chapter 4, Configuring Notifications.