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

Running a service on all hosts in a group


In this recipe, we'll create a new service, but instead of applying it to an existing host, we'll apply it to an existing hostgroup. In this case, we'll create a group called webservers. The steps for this are very similar to adding a service for just one host; only one directive is different.

Getting ready

You should have a working Nagios Core 3.0 or better server running, with a web interface. You should be familiar with adding services to individual hosts.

You should also have at least one hostgroup defined, with at least one host in it; we'll use a group called webservers, with the hosts sparta.naginet and athens.naginet defined in it.

For reference, here is the hostgroup definition and the definitions for the two hosts in it:

define hostgroup {
    hostgroup_name  webservers
    alias           Webservers
}
define host {
    use         linux-server
    host_name   athens.naginet
    alias       athens
    address     10.128.0.22
    hostgroups  webservers
}
define host {
    use         linux-server
    host_name   sparta.naginet
    alias       sparta
    address     10.128.0.21
    hostgroups  webservers
}

How to do it...

We can create the service definition for the webservers group as follows:

  1. Change to the directory containing the file in which the webservers hostgroup is defined, and edit it:

    # cd /usr/local/nagios/etc/objects
    # vi hostgroups.cfg
    
  2. Add the following code snippet just after the hostgroup definition. Change the lines in bold to suit your own template and hostgroup names:

    define service {
        use                    generic-service
        hostgroup_name         webservers
        service_description    HTTP
        check_command          check_http
    }
  3. Restart the Nagios Core server:

    # /etc/init.d/nagios restart
    

It's important to note that if we are already monitoring those hosts with a per-host service of the same name, then we will need to remove those definitions as well; Nagios Core may not start if a service of the same description is already defined on the same host.

How it works...

Adding a service to a hostgroup works in exactly the same way as adding it to an individual host, except that it only requires one definition, which is then individually applied to all the hosts in the group. This means it's a very good way to keep a Nagios Core configuration tidier. If we have a group of 50 different web servers in it and we need to monitor their HTTP services on the same basis for each one of them, then we don't need to create 50 service definitions; we can just create one for their hostgroup, which amounts to a smaller and more easily updated configuration.

There's more...

Like the host_name directive for services, the hostgroup_name directive can actually have several hostgroups defined, separated by commas. This means that we can apply the same service to not just one group, but several. For services that we would want to run on several different groups (for example, basic PING monitoring) this can amount to a much more flexible configuration.

See also

  • The Creating a new service and Creating a new hostgroup recipe 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