Nagios notifications: Setting up alerts in the network monitoring tool

In this tip on the open source network monitoring tool Nagios, learn how to set up custom configurations that can send Nagios notifications to admins at any time of the day.

This is the fourth tip in a series on the open source network monitoring tool Nagios.

In a basic Nagios setup, notifications will already be available. When using notifications, Nagios sends out a message if a monitored device is no longer available. By default, Nagios notifications are sent via email to one specified contact. In this tip, you'll learn how to create different configurations that will send notifications to different administrators at various times throughout the day.

Default configuration for setting up Nagios notifications
Before learning how to set up these configurations, let's first take a look at the default configuration, which has one contact and one contact group specified in /etc/nagios/objects/contacts.cfg. It appears as follows:

define contact{
            contact_name              nagiosadmin
            use                               generic-contact
            alias                             Nagios Administration
            email                           [email protected]

define contactgroup{
            contactgroup_name     admins
            alias                             Nagios Administrators
            members                      nagiosadmin

In the default configuration’s current definition, alerting will hardly ever work. To send mail messages to a mailbox, the user must be the owner of the mailbox, and must open it regularly to act upon incoming messages. Much time may pass from when the mail message is sent and when the user acts upon it.

Setting up different time periods for Nagios notifications
By default, all alerts are sent around the clock. You may set up different time periods by creating multiple solutions. You should start from the /etc/nagios/objects/timeperiods file, where time periods are defined. For example, you can add a time period for the evening hours by adding the following text to the file:

define timeperiod{
            timeperiod_name        night
            alias                             do not disturb
            sunday                         00:00-06:00
            monday                       00:00-06:00|
            tuesday                        00:00-06:00
            wednesday                   00:00-06:00
            thursday                      00:00-06:00
            friday                           00:00-06:00
            saturday                       00:00-06:00

Using these time periods, you can now set up different user accounts for different time periods and specify different actions to occur for off-hour events. This makes sure that alerts sent in the middle of the night are sent to the right person.

If you have set up multiple user accounts by defining multiple contacts in the contacts.cfg files, and multiple time periods as described in the examples above, you can now configure any host or service to send alerts to a specific person. You could, therefore, create different host definitions with different actions, and notifications would be sent to different people, depending on the time of day. For example, the following text would allow you to run the check-host-alive command only once every 60 minutes at night, and apart from this configuration, you could create an alternative that would do the same every 15 minutes during the day:

define host{
            host_name                   my-server
            hostgroups                   linuxservers
            check_command         check-host-alive
            check_period               night
            contact                         nagiosadmin
            notification_interval    120
            notification_period      night
            notification_options     d,u

This configuration, along with your normal configuration, will allow for night time-specific host monitoring parameters.

Now you’ve learned how to use multiple Nagios contacts and time period definitions to set up customized monitoring. Using these techniques allows you to make sure that the right person receives the right Nagios notifications at the right time of the day. In a later article in this series, you'll learn how to send alerts that are defined as Nagios contacts directly to users’ desktops.

Dig Deeper on IT compliance and governance strategies