Book Image

Nagios Core Administration Cookbook - Second Edition

By : Tom Ryder
Book Image

Nagios Core Administration Cookbook - Second Edition

By: Tom Ryder

Overview of this book

Nagios Core is an open source monitoring framework suitable for any network that ensures both internal and customer-facing services are running correctly and manages notification and reporting behavior to diagnose and fix outages promptly. It allows very fine configuration of exactly when, where, what, and how to check network services to meet both the uptime goals of your network and systems team and the needs of your users. This book shows system and network administrators how to use Nagios Core to its fullest as a monitoring framework for checks on any kind of network services, from the smallest home network to much larger production multi-site services. You will discover that Nagios Core is capable of doing much more than pinging a host or to see whether websites respond. The recipes in this book will demonstrate how to leverage Nagios Core's advanced configuration, scripting hooks, reports, data retrieval, and extensibility to integrate it with your existing systems, and to make it the rock-solid center of your network monitoring world.
Table of Contents (18 chapters)
Nagios Core Administration Cookbook Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Creating a new contactgroup


In this recipe, we'll create a new contactgroup into which we can add our contacts. Like hostgroups and servicegroups, contactgroups mostly amount to convenient shortcuts. In this case, it allows us to define a contactgroup as the recipient of notifications for a host or service definition. This means that we could define an ops group, for example, and then even if people joined or left the group, we wouldn't need to change any definitions for the hosts or services.

Getting ready

You should have a working Nagios Core 4.0 or better server running.

You should also have at least two contacts that form a meaningful group. In this case, we have two staff members, John Smith and Jane Doe, who are both part of our network operations team. We want them both to be notified for all the appropriate hosts and services, so we'll add them to a group called ops. Here are the definitions with which we're working:

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]
}

How to do it...

We can create our new ops contactgroup as follows:

  1. Change to our Nagios Core configuration objects directory and edit the contacts.cfg file:

    # cd /usr/local/nagios/etc
    # vi contacts.cfg
    
  2. Add the following definition to the file, substituting in your own values in bold as appropriate:

    define contactgroup {
        contactgroup_name  ops
        alias              Network operators
    }
  3. For each of the contacts that we want to add to the group, find their definitions and add the contactgroups directive to them. The definitions will end up looking something like this:

    define contact {
        use            generic-contact
        contact_name   john
        alias          John Smith
        email          [email protected]
        contactgroups  ops
    }
    define contact {
        use            generic-contact
        contact_name   jane
        alias          Jane Doe
        email          [email protected]
        contactgroups  ops
    }
  4. Reload the configuration:

    # /etc/init.d/nagios reload
    

How it works...

With this group set up, we are now able to use it in the contactgroups directive for hosts and services to define which contacts notifications should be sent to. Notifications are sent to all the addresses in the group. This can replace the contacts directive, where we name contacts individually.

There's more...

As an example, consider the following service definition:

define service {
    use                  generic-service
    host_name            sparta.example.net
    service_description  HTTP
    check_command        check_http
    contacts             john,jane
}

Instead of having a service definition as the preceding one, we could use this:

define service {
    use                  generic-service
    host_name            sparta.example.net
    service_description  HTTP
    check_command        check_http
    contact_groups       ops
}

If John Smith were to leave the operations team, we could simply remove his contact definition and nothing else would require changing; from then on, only Jane would receive the services notification. This method provides a layer of abstraction between contacts and the hosts and services for which they receive notifications.

See also

  • The Creating a new contact section in this chapter

  • Automating contact rotation, Chapter 4, Configuring Notifications

  • Using inheritance to simplify a configuration, Chapter 9, Managing Configuration