Configure hostgroups for Nagios

Jack Wallen
Mar 28, 2010
Updated • Nov 30, 2012

If you've been following my Nagios articles here on Ghacks (see "Easily extend Nagios' functionality" and "Quickly install Nagios on Ubuntu" for more information) you are probably impressed with how powerful Nagios is. Well, I can happily say you haven't seen anything yet. Nagios is amazing in it's ability to extend and report. Of course, along with this power comes a bit of work to be done by the administrator. With Nagios there are no fancy widgets and wizards to walk you through simple configurations. Nagios requires you to get your fingers a bit dirty with the command line.

One cool ability of Nagios is that it allows you to group machines into services. Say, for instance, you have a number of machines that serve as Web servers or Samba servers. Instead of having to scroll around to find them, you can group those machines together, by service, to make for much easier monitoring. In this tutorial I am going to show you how to take advantage of this nifty feature.


I am going to assume that you already have Nagios installed and working. I will also assume you know which machines are on your network and what services they are running. For the sake of this tutorial, we will piece together all machines that fall under the categories: ssh-servers and debian-servers.

Machine-specific .cfg files

The first thing to do is to create a specific .cfg file for each machine you need to add.  This subject was already addressed in the "Easily extend Nagios' functionality" article. Without these .cfg files, Nagios will not be able to see the machines - this is critical for being able to group machines by service.

Setting up the groups

If you look in /etc/nagios3/conf.d you will find a file called hostgroups_nagios2.cfg (NOTE: The "2" is not a typo. For some reason the configuration files have not been renamed to reflect the migration from 2 to 3.) This is the file in charge of grouping machines together by service. A typical entry will look like:

# A list of your Debian GNU/Linux servers
define hostgroup {
hostgroup_name  debian-servers
alias           Debian GNU/Linux Servers
members         localhost, Elive, courtney-desktop

Figure 1

As you can see I already have three machines grouped together. You can have as many as you like. Now, when you take a look at the Nagios' Hostgroup Overview, you will see the machines you have defined listed (see Figure 1).

Notice the Host names listed. These names are taken from the configuration you see above. You can't, however, just edit the names to make them whatever you want. Those names have to reflect the host_name directive in the particular hosts .cfg file. So for courtney-desktop above you might find a courtney_desktop.cfg file containing the line host_name courtney-desktop.

Now, do the same for all of your SSH servers, by adding in any hosts that serve up ssh to clients. It's done the same way. In the /etc/nagios3/hostgroups_nagios2.cfg file you will all all hosts to the ssh-servers section.

Once you have added all your hosts to your groups, you have to make sure you restart Nagios in order for the changes to take effect. Do this with the command /etc/init.d/nagios3 restart. You can now view your groups in your browser.

Final thoughts

We keep chugging along with Nagios, making it ever more useful to the already-too-busy administrator. In upcoming articles we will tackle other Nagios-specific tasks.


Previous Post: «
Next Post: «


  1. Brad S said on May 1, 2014 at 1:58 pm

    You can do this through the GUI with CCM (Nagios Core Config Manager). CCM edits those CFG files and applies the configurations.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.