HowTo: Configure HostGroups for multiple hosts in Nagios 4

Nagios Hostgroup
Nagios Hostgroup

Configure HostGroups for Multiple Hosts in Nagios 4

What is HostGroups?

HostGroups is the most feasible and important functionality provided by Nagios.

HostGroups is used to group one or multiple hosts, and you will have the option to check all these hosts in one place & on a single page.

Why we require host groups?

Suppose you have more than 100 hosts configured on Nagios including all Prod, Dev, Stage environment, and you want a quick look at all your Production hosts on Nagios with the status of each service, so in such a scenario hostgroup feature is useful.

You will get the overview of all the hosts and services on the single page otherwise you need to go under the host tab and then search for a host which you want to check & it will be a time-consuming process.

Basically, hostsgroups helps you to ease your daily process with a monitoring application.

Advantages of Hostgroups

  • Helps to easily find a category for the Production / Dev / Test environment.
  • With a Single click able to schedule downtime.
  • Allows you to group machines into services.
  • Create an Operating system based host groups.
  • Able to Enable and disable host alerts in single click.

In this article, we are going to learn to configure hostgroups in Nagios and will try to explain each and every part of hostgroups. So you guys can able to configure host groups easily at your organization.

I hope you have a basic understanding of Nagios and the other features of Nagios. If you are using the Nagios for the first time then you should go through the below links to understand the working of Nagios.

Configuration Of Hostgroups

Step 1: Create  a Hostgroup File

When you install the Nagios, It will not provide you default hostgroup file in the Nagios directory.

Here you need to first create a hostgroup file inside the “/usr/local/nagios/objects” directory where you will find all the Nagios configuration files.

Nagios configuration files has “.cfg” extension. We will create a file called “hostsgroup.cfg”

vim /usr/local/nagios/objects/hostsgroup.cfg

define hostgroup {
           hostgroup_name    Remote_host
         alias             Remote_host
         members           nagios_host

Below are parameters used in hostgroups,

  • Hostgroup_name: Give the name of your website or project
  • Alias: Any short name of your site or project
  • Members: Give the name which you used in the host.cfg file as host_name.

Note: The value which you provide for the Members parameter should be correct otherwise host groups will not load/shows the hosts.

Here I have added a single member in the host group if you are using two web servers for a single-site then add the host_name of both web server in comma-separated form like members webserver1,webserver2

Like above you can add multiple hosts in a single host group file.

Step 2: Give Permissions

Once you create hostsgroup.cfg file, it will create with a normal login user permissions. We need to change permissions with the required Nagios permissions. 

So that Nagios user will able to read the file.

  • chown nagiosuser.nagios hostsgroup.cfg
  • chmod 664 hostsgroup.cfg


Step 3: Add Hostgroup File

Now you need to define the “hostsgroup.cfg” file in main nagios configuration file i.e. “nagios.cfg”.

When you define hostsgroup.cfg file nagios.cfg then nagios will be able to execute the defined parameters from hostsgroup.cfg file.

vim /usr/local/nagios/etc/nagios.cfg

#Add below line

Save and close the file.

Step 4: Verify Configuration & Restart Nagios Service

After all the necessary configuration changes, you need to check for syntax warnings and restart the Nagios service to reflect the newer changes on Nagios.

To check for errors & warning in configuration,

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Restart Nagios Service,

service nagios restart

Now open Nagios web interface in the browser and click on the “Host Groups” tab in the navigation bar. You will find added hosts in the host group.


Configure hostsgroup in nagios

Also, you will have two sub-options or views for the host group.

  • Summary View
  • Grid View
hostgroup summary view

If you’re facing any difficulties while configuring HostsGroup. Please do comment on your queries or problem via the comment section, till then stay tuned to for more such valuable articles.

Thank You 🙂


Welcome to Linuxgrow. I'm Prashant, a tech-blogger from Mumbai, India. I started Linuxgrow as a passion and to share my knowledge about technologies. Here at Linuxgrow, I write about Linux technologies, Aws Cloud, Wordpress blogging and scripting knowledge. You can read more about me at About us page. Thank You :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *