In this recipe, you'll learn how to create a new hostgroup; in this case, to group two web servers together. It is useful to have 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 that all we would have to do to get a new host monitored in the same way as all the other hosts would be to add it to the group, rather than having to specify the configuration manually.
You should have a working Nagios Core 4.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 web servers, or are monitored by the same team, or both at a physical location.
In this example, we have two web servers, sparta.example.net
and athens.example.net
, and we're going to add them to a group called webservers
.
We can add our new hostgroup webservers
to the Nagios Core configuration as follows:
Create a new file called
/usr/local/nagios/etc/objects/hostgroups.cfg
, if it doesn't already exist:Write the following code into the new file, substituting the names in bold to suit your own layout:
Move a directory up and then edit the
nagios.cfg
file:Add this line to the end of the file:
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 forsparta.example.net
andathens.example.net
ends up looking like this:Restart Nagios:
We should now be able to visit the Host Groups section of the web interface and see a new hostgroup with two members:
The preceding configuration that we have added includes a new file with a new hostgroup into the Nagios Core configuration and inserts appropriate hosts into the group. The hostgroup creates a separate section in the web interface for us to get a quick overview of only the hosts in that particular group.
The way we've added hosts to the preceding groups is actually not the only way to do it. If we prefer, we can instead name the hosts for the group inside the group definition, using the members
directive, so we could have something like the following:
We can also make a hostgroup that always includes every single host, if we find that useful:
0 Comments