Automating contact rotation

In this recipe, we'll learn how to automatically arrange notifications so that they are only received by certain contacts in a group at certain times.

For companies with more than one person as dedicated network staff, it's common practice to have an on-call roster, where one member of staff will be the dedicated on-call person for a certain period of time, perhaps a week or two. The kind of setup we'll configure here allows filtering notifications so that they're only delivered to the contacts at appropriate times; notifications are generated by hosts and services and sent to all the contacts in the nominated group, but only one (or perhaps more than one) of the contacts actually receives it.

We'll set this up using two properties of contacts that allow us to restrict the time period within which they should receive notifications: host_notification_period and service_notification_period.

Getting ready

You should have a Nagios Core 4.0 or newer server, with at least one contact group configured already, and with at least two contacts within it. You should be familiar with configuring time periods and understand the basics of notifications as discussed earlier in this chapter.

We'll use the very simple example of three network operators, named as contacts alan, brenden, and charlotte, taking turns with monitoring duty every week. All three are members of the group ops, which is specified in the contact_groups directive for all the hosts and services on the network.

How to do it...

We can set up a basic alternating schedule for receiving notifications for our operators as follows:

  1. Change to the objects configuration directory for Nagios Core. The default is /usr/local/nagios/etc/objects. If you've put the definition for your host in a different file, move to that directory instead.
    # cd /usr/local/nagios/etc/objects
    
  2. Check the relevant file or files to ensure your contacts are defined and that they are members of the appropriate contact group. A good location for such information is in the contacts.cfg file.
    define contactgroup {
        contactgroup_name  ops
        alias              Network Operations
        members            alan,brenden,charlotte
    }
        define contact {
            use           generic-contact
            contact_name  alan
            alias         Alan Jones
            email         [email protected]
        }
        define contact {
            use           generic-contact
            contact_name  brenden
            alias         Brenden Peters
            email         [email protected]
        }
        define contact {
            use           generic-contact
            contact_name  charlotte
            alias         Charlotte Franks
            email         [email protected]
        }
  3. In this case, all our hosts and services are configured to send messages to the ops contact group:
        define host {
            ...
            contact_groups  ops
        }
        define service {
            ...
            contact_groups  ops
        }
  4. Define time periods to correspond to the times during which each of your contacts should be receiving messages. We'll use the special syntax of time period definitions to set up the definitions for this rotation:
    define timeperiod {
        timeperiod_name  alan-pager
        alias            Alan pager schedule
        2015-12-05 / 21  00:00-24:00
        2015-12-06 / 21  00:00-24:00
        2015-12-07 / 21  00:00-24:00
        2015-12-08 / 21  00:00-24:00
        2015-12-09 / 21  00:00-24:00
        2015-12-10 / 21  00:00-24:00
        2015-12-11 / 21  00:00-24:00
    }
    define timeperiod {
        timeperiod_name  brenden-pager
        alias            Brenden pager schedule
        2015-12-12 / 21  00:00-24:00
        2015-12-13 / 21  00:00-24:00
        2015-12-14 / 21  00:00-24:00
        2015-12-15 / 21  00:00-24:00
        2015-12-16 / 21  00:00-24:00
        2015-12-17 / 21  00:00-24:00
        2015-12-18 / 21  00:00-24:00
    }
    define timeperiod {
        timeperiod_name  charlotte-pager
        alias            Charlotte pager schedule
        2015-12-19 / 21  00:00-24:00
        2015-12-20 / 21  00:00-24:00
        2015-12-21 / 21  00:00-24:00
        2015-12-22 / 21  00:00-24:00
        2015-12-23 / 21  00:00-24:00
        2015-12-24 / 21  00:00-24:00
        2015-12-25 / 21  00:00-24:00
    }
  5. Go back, and configure each of your contacts with the host_notification_period and service_notification_period directives to filter notifications to be received only during their dedicated time period:
    define contact {
        use                          generic-contact
        contact_name                 alan
        alias                        Alan Jones
        email                        [email protected]
        host_notification_period     alan-pager
        service_notification_period  alan-pager
    }
    define contact {
        use                          generic-contact
        contact_name                 brenden
        alias                        Brenden Peters
        email                        [email protected]
        host_notification_period     brenden-pager
        service_notification_period  brenden-pager
    }
    define contact {
        use                          generic-contact
        contact_name                 charlotte
        alias                        Charlotte Franks
        email                        [email protected]
        host_notification_period     charlotte-pager
        service_notification_period  charlotte-pager
    }
  6. Validate the configuration and restart the Nagios Core server:
    # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    # /etc/init.d/nagios reload
    

With this done, the contacts configured should receive notifications only during their dedicated pager time. If these are our only contacts, then all the notifications generated will go to only one person at any given time.

How it works...

The host_notification_period and service_notification_period directives in the definitions for our contacts are used to limit the times during which these contacts should receive any notifications. Each of our contacts in this example has their own time period defined to correspond to their portion of the pager schedule.

Let's take a look at Alan's example:

    define timeperiod {
        timeperiod_name  alan-pager
        2015-12-05 / 21  00:00-24:00
        2015-12-06 / 21  00:00-24:00
        2015-12-07 / 21  00:00-24:00
        2015-12-08 / 21  00:00-24:00
        2015-12-09 / 21  00:00-24:00
        2015-12-10 / 21  00:00-24:00
        2015-12-11 / 21  00:00-24:00
    }

The second line of the directive, 2015-12-05 / 21 00:00-24:00, can be broken down as follows:

  • Starting from the 5th of December
  • Every 21 days,
  • From midnight to the following midnight (that is, the entire day)

The configuration then goes on to do the same for the remaining days of the first week when Alan will be on call and specifies that he will be on call the same day 21 days (three weeks) later. A similar configuration, but starting one week and two weeks later, is set up for the contacts brenden and charlotte respectively.

There's more...

Note that there's no reason time periods can't overlap. If it happens to suit us to arrange for more than one contact to receive a notification, we can do that. Similarly, we can leave gaps in the schedule if notifications aren't needed during a certain time period.

Time periods in Nagios Core are highly flexible; to see some examples of the various syntaxes you can use for defining them, take a look at the "Creating a new time period" recipe in Chapter 1, Understanding Hosts, Services, and Contacts.

See also

  • Creating a new contact, Chapter 1, Understanding Hosts, Services, and Contacts
  • Creating a new contact group, Chapter 1, Understanding Hosts, Services, and Contacts
  • The Configuring notifications for groups section in this chapter
  • Creating a new time period, Chapter 1, Understanding Hosts, Services, and Contacts
  • The Choosing states for notification section in this chapter
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.1.136