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 Second Edition

You're reading from   Nagios Core Administration Cookbook Second Edition Over 90 hands-on recipes that will employ Nagios Core as the anchor of monitoring on your network

Arrow left icon
Product type Paperback
Published in Feb 2016
Publisher
ISBN-13 9781785889332
Length 386 pages
Edition 2nd 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 (13) Chapters Close

Preface 1. Understanding Hosts, Services, and Contacts FREE CHAPTER 2. Working with Commands and Plugins 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 on 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, to a hostgroup called webservers. The steps to do 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 4.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 sparta.example.net and athens.example.net hosts 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.example.net
    alias       athens
    address     192.0.2.22
    hostgroups  webservers
}
define host {
    use         linux-server
    host_name   sparta.example.net
    alias       sparta
    address     192.0.2.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 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. Reload the configuration:
    # /etc/init.d/nagios reload
    

It's important to note that if we were already monitoring these hosts with a per-host service of the same name, we will need to remove the definitions as well; Nagios Core will 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 exactly in the same way as adding it to an individual host, except it only requires one definition, which is then individually applied to all the hosts in the group. This means that it's a very good way to keep a Nagios Core configuration tidier. If we have a group with 50 different web servers in it and we need to monitor their HTTP services on the same basis for every one of them, we don't need to create 50 service definitions as well; we can just create one for its hostgroup, which amounts to a smaller and more easily updated configuration.

There's more...

Like the host_name directive for services, hostgroup_name 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 of them. 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 section in this chapter
  • The Creating a new hostgroup section in this chapter
  • Using inheritance to simplify a configuration, Chapter 9, Managing Configuration
You have been reading a chapter from
Nagios Core Administration Cookbook Second Edition - Second Edition
Published in: Feb 2016
Publisher:
ISBN-13: 9781785889332
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