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 hostgroup


In this recipe, we'll learn how to create a new hostgroup; in this case, we'll do this to group together two webservers. This is useful for having distinct groups of hosts that might have different properties, such as being monitored by different teams, or running different types of monitored services. It also allows us to view a group breakdown in the Nagios Core web interface, and to apply a single service to a whole group of hosts, rather than doing so individually. This means we can set up services for a new host simply by adding it to a group, rather than having to specify the configuration manually.

Getting ready

You should have a working Nagios Core 3.0 or better server running, with a web interface.

You should also have at least two hosts that form a meaningful group; perhaps they're similar kinds of servers, such as webservers, or are monitored by the same team, or all at a physical location.

In this example, we have two webservers, sparta.naginet and athens.naginet, and we're going to add them to a group called webservers.

How to do it...

We can add our new hostgroup webservers to the Nagios Core configuration as follows:

  1. Create a new file called /usr/local/nagios/etc/objects/hostgroups.cfg, if it doesn't already exist:

    # cd /usr/local/nagios/etc/objects
    # vi hostgroups.cfg
    
  2. Add the following code into the new file, substituting the names in bold to suit your own layout:

    define hostgroup {
         hostgroup_name  webservers
         alias           Webservers with Greek names
    }
  3. Move a directory up, and then edit the nagios.cfg file:

    # cd ..
    # vi nagios.cfg
    
  4. Add the following line to the end of the file:

    cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
  5. For each of the hosts we want to add to the group, find their definitions, and add a hostgroups directive to put them into the new hostgroup. In this case, our definitions for sparta.naginet and athens.naginet end up looking as follows:

    define host {
        use         linux-server
        host_name   sparta.naginet
        alias       sparta
        address     10.128.0.21
        hostgroups  webservers
    }
    define host {
        use         linux-server
        host_name   athens.naginet
        alias       athens
        address     10.128.0.22
        hostgroups  webservers
    }
  6. Restart Nagios:

    # /etc/init.d/nagios restart
    

We should now be able to visit the Host Groups section of the web interface, and see a new hostgroup with two members:

How it works...

The configuration we added includes a new file with a new hostgroup into the Nagios Core configuration, and inserts the appropriate hosts into the group. At the moment, all this is doing is creating a separate section in the web interface for us to get a quick overview of only the hosts in that particular group.

There's more...

The way we've added hosts to groups is actually not the only way to do it. If we prefer, we can name the hosts for the group inside the group definition, using the members directive, so that we could have a code snippet similar to the following:

define hostgroup {
    hostgroup_name  webservers
    alias           Webservers with Greek names
    members         athens.naginet,sparta.naginet
}

This extends to allowing us to make a hostgroup that always includes every single host, if we find that useful:

define hostgroup {
    hostgroup_name  all
    alias           All hosts
    members         *
}

If we're going to use hostgroups extensively in our Nagios Core configuration, then we should use whichever method is going to be easiest for our configuration. We can use both, if necessary.

It's worth noting that a host can be in more than one group, and there is no limit on the number of groups we can declare, so we can afford to be quite liberal with how we group our hosts into useful categories. Examples could be organizing servers by function, manufacturer, or colocation customer, or routers by BGP or OSPF usage; it all depends on what kind of network we're monitoring.

See also

  • The Creating a new host and Running a service on all hosts in a group recipes in this chapter

  • 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