Configure hostgroups
for Nagios
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.
Assumptions
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
}
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 acourtney_desktop.cfg file containing the linehost_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.
No comments:
Post a Comment