Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Nagios Core Administration Cookbook

You're reading from   Nagios Core Administration Cookbook The ideal book for System Administrators who want to move their network monitoring to an advanced level. This book covers the powerful features and flexibility of Nagios Core, and its recipes can be applied to virtually any network.

Arrow left icon
Product type Paperback
Published in Jan 2013
Publisher Packt
ISBN-13 9781849515566
Length 366 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Tom Ryder Tom Ryder
Author Profile Icon Tom Ryder
Tom Ryder
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Nagios Core Administration Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Understanding Hosts, Services, and Contacts 2. Working with Commands and Plugins FREE CHAPTER 3. Working with Checks and States 4. Configuring Notifications 5. Monitoring Methods 6. Enabling Remote Execution 7. Using the Web Interface 8. Managing Network Layout 9. Managing Configuration 10. Security and Performance 11. Automating and Extending Nagios Core 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 a group ops, 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 3.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 a part of our network operations team. We want both of them 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         john@naginet
}
define contact {
    use           generic-contact
    contact_name  jane
    alias         Jane Doe
    email         jane@naginet
}

How to do it...

We can create our new ops contactgroup as follows:

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

    # cd /usr/local/nagios/etc
    # vi contacts.cfg
    
  2. Add the following definition to the file, substituting 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 similar to the following code snippet:

    define contact {
        use            generic-contact
        contact_name   john
        alias          John Smith
        email          john@naginet
        contactgroups  ops
    }
    define contact {
        use            generic-contact
        contact_name   jane
        alias          Jane Doe
        email          jane@naginet
        contactgroups  ops
    }
  4. Restart the Nagios Core server:

    # /etc/init.d/nagios restart
    

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 the contacts to which notifications should be sent. Notifications are sent to all the addresses in the group. This can replace the contacts directive where we individually name the contacts.

There's more...

This means, for example, that instead of having a service definition similar to the following:

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

We could use the following code snippet:

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

If John Smith were to leave the operations team, then we could simply remove his contact definition, and nothing else would require changing; from then on, only Jane Doe would receive the service notifications. 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 recipe in this chapter

  • The Automating contact rotation recipe in Chapter 4, Configuring Notifications

  • The Using inheritance to simplify configuration recipe in Chapter 9, Managing Configuration

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image