Configuring notifications for groups

In this recipe, we'll learn how to define a contact group for a host. We'll demonstrate this as part of the general best practice of sending notifications to contact groups, rather than to individual contacts. This allows for more flexibility in assigning individual contacts to the appropriate groups for receiving appropriate notifications.

Getting ready

You should have a Nagios Core 4.0 or newer server with at least one host configured already. We'll use the example of sparta.example.net, a host defined in its own file, which we'll configure to send its notifications to an existing contact group called noc.

How to do it...

We can configure notifications to be sent to our contact group 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. The notifications will need to be directed to a contact group object. We will need to ensure that an appropriate contact_group definition exists for this. A valid definition might look something like the following, perhaps kept in contacts.cfg:
    define contactgroup {
        contactgroup_name  noc
        alias              Network Operations
        members            john,jane
    }
  3. If any contacts are referenced for the group, you should ensure those are also defined. They might look something like this:
    define contact {
        use            generic-contact
        contact_name   john
        alias          John Smith
        email          [email protected]
    }
    define contact {
        use            generic-contact
        contact_name   jane
        alias          Jane Doe
        email          [email protected]
    }
  4. Edit the file containing your host definition and find the definition within the file:
    # vi sparta.example.net.cfg
    

    The host definition may look something like this:

    define host {
        use                  linux-server
        host_name            sparta.example.net
        alias                sparta
        address              192.0.2.21
    	notification_period  24x7
    }
  5. Add or edit the value for the contact_groups directive to noc:
    define host {
        use                  linux-server
        host_name            sparta.example.net
        alias                sparta
        address              192.0.2.21
        notification_period  24x7
        contact_groups       noc
    }
  6. If the contacts directive for the host is already defined, you may wish to remove it, though you don't have to.
  7. 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, all notifications for this host should be sent to each member of the noc group, in our example, the contacts jane and john.

How it works...

Defining the contacts that should receive notifications for particular hosts can be done by referring to them individually, as groups, or both. We could have managed the same result as the preceding one by defining the contacts directive for the host as jane,john, referring to the individual contacts directly rather than by their group name, with the two names separated by a comma.

Much the same configuration process applies for setting the contact group for services, rather than hosts; we add a value for the contact_groups directive to the service definition:

define service {
    ...
    contact_groups  noc
}

When an event takes place for the host or service that prompts a notification and the valid notification_option flags are set for that event, Nagios Core will check the values of both the contacts and the contact_groups directives for the host to determine whom to send the notification to. In our case, the server finds the value of contact_groups to be noc and so refers to that contact group to identify the individual contacts within it; it then sends the notification to each of them.

There's more...

Which of the two methods to use for defining contacts for hosts or services, whether by individual contact references or groups, is up to you. For large numbers of hosts and services, it tends to be easier to direct notifications to the appropriate groups rather than individuals, as it affords us more flexibility in choosing who the notifications should be sent to by simply changing the individuals in the group.

Note that we can use both methods if necessary; if for a particular host or service it would be appropriate to also send a notification to an individual contact named james, we could define the host as follows:

define host {
    ...
    contact_groups  noc
    contacts        james
}

You need to define at least one contact or contact group for a host or service, or have it inherit one through a template, for it to be a valid host configuration for Nagios Core.

See also

  • The Configuring notification periods section in this chapter
  • Creating a new contact, Chapter 1, Understanding Hosts, Services, and Contacts
  • Creating a new contact group, Chapter 1, Understanding Hosts, Services, and Contacts
  • The Choosing states for notification section in this chapter
  • The Automating contact rotation 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.84.29