Pages: 1, 2
At this point the Nagios installation is complete. However, it is not very useful at its current state, because it lacks the actual monitoring applications. These applications, the duty of which is to check whether a particular monotired service is functioning properly, are called plugins. Nagios comes with a default set of such plugins, but they have to be downloaded and installed seperately. (Please visit the Nagios Web site for the latest download URL.)
Download the latest Nagios Plugins package and decompress it. You will need to run the configure script that is provided in order to prepare the package for compilation on your system. You will find that that the plugins are installed in a fashion similar to the actual Nagios program. Once again, you can just run configure if you are OK with the default settings for the username, group, and directory where Nagios is installed.
Type the following script on a single line:
root@ducati:~/tmp/nagios/nagiosplug-1.3-beta1# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
You might get notifications about missing programs or Perl modules while
configure is running. These are mostly OK, unless you specifically need the mentioned application to monitor a service.
Once configure is complete, compile all of the plugins.
root@ducati:~/tmp/nagios/nagiosplug-1.3-beta1# make all
If no errors were reported, you are ready to install the plugins.
root@ducati:~/tmp/nagios/nagiosplug-1.3-beta1# make install
The plugins will be installed in the
libexec directory of your Nagios base directory (
/usr/local/nagios/libexec, in my case).
root@ducati:~/tmp/nagios/nagiosplug-1.3-beta1# cd /usr/local/nagios/libexec/
There are a few rules that all Nagios plugins should implement, making them suitable for use by Nagios. All plugins provide a
--help option that displays information about the plugin and how it works. This feature helps a lot when you're trying to monitor a new service using a plugin you haven't used before.
For instance, to learn how the
check_ssh plugin works, run the following command.
root@ducati:/usr/local/nagios/libexec# ./check_ssh -h check_ssh (nagios-plugins 1.3.0-alpha1) 126.96.36.199 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute copies of the plugins under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING. Copyright (c) 1999 Remi Paulmier (firstname.lastname@example.org) Usage: check_ssh -t [timeout] -p [port] <host> check_ssh -V prints version info check_ssh -h prints more detailed help by default, port is 22 root@ducati:/usr/local/nagios/libexec#
This shows us that the
check_ssh plugin accepts one required parameter
host, and two optional paramters,
There's nothing especially complicated about the plugins. In fact, you can run the plugins manually to check services on the console.
root@ducati:/usr/local/nagios/libexec# ./check_ssh www.example.com SSH ok - protocol version 1.99- - server version
Nagios Post-Install Configuration
Now that both Nagios and the plugins are installed, we are almost ready to start monitoring our servers. However, Nagios will not even start before we configure it properly.
Let's start by taking a look the sample configuration files.
root@ducati:~/tmp/nagios# cd /usr/local/nagios/etc root@ducati:/usr/local/nagios/etc# ls -1 cgi.cfg-sample checkcommands.cfg-sample contactgroups.cfg-sample contacts.cfg-sample dependencies.cfg-sample escalations.cfg-sample hostgroups.cfg-sample hosts.cfg-sample misccommands.cfg-sample nagios.cfg-sample resource.cfg-sample services.cfg-sample timeperiods.cfg-sample
Since these are sample files, the Nagios authors added a
.cfg-sample suffix to each file. First, we need to copy or rename each one to
*.cfg, so that the software can use them properly. (If you don't change the configuration filenames, Nagios will still try to access them with the
.cgi extension, and not be able to find them. The authors must have wanted to ensure that everyone create their own custom configuration files.)
Before renaming the sample files, I like to take a backup of them, just in case I need to refer to them later.
root@ducati:/usr/local/nagios/etc# mkdir sample root@ducati:/usr/local/nagios/etc# cp *.cfg-sample sample/
You can either rename each file manually, or use the following command to take care of them all at once.
Type the following script on a single line:
root@ducati:/usr/local/nagios/etc# for i in *cfg-sample; do mv $i `echo $i | sed -e s/cfg-sample/cfg/`; done;
The following is what you should end up with in the
root@ducati:/usr/local/nagios/etc# ls -1 cgi.cfg checkcommands.cfg contactgroups.cfg contacts.cfg dependencies.cfg escalations.cfg hostgroups.cfg hosts.cfg misccommands.cfg nagios.cfg resource.cfg sample/ services.cfg timeperiods.cfg
First we will start with the main configuration file,
nagios.cfg. You can pretty much leave everything as is, becasue the Nagios installation process will make sure the file paths used in the configuration file are correct. There's one option, however, that you might want to change. The
check_external_commands is set to
0 by default. If you would like to be able to change the way Nagios works, or directly run commands through the Web interface, you might want to set this to
1. There are still some other options you need to set in
cgi.cfg to configure which usernames are allowed to run external commands.
In order to get Nagios running, you will need to modify all but a few of the sample configuration files. Configuring Nagios to monitor your servers is not as difficult as it looks; I have found that the best approach to configuring Nagios properly the first time is to use the debugging mode of the Nagios binary. You can run Nagios in this mode by running:
root@ducati:/usr/local/nagios/etc# ../bin/nagios -v nagios.cfg
This command will go through the configuration files and report any errors that were found. Start fixing the errors one by one, and run the command again to find the next error. For our purposes, I will disable all hosts and services definitions that come with the sample configuration files and merely use the files as templates for our own hosts and services. We will keep most of the files as is, and remove the following (we will create them from scratch):
hosts.cfg services.cfg contacts.cfg contactgroups.cfg hostgroups.cfg dependencies.cfg escalations.cfg
We will not be going into the more advanced configuration that requires using
escalations.cfg, so just remove these two files so that the sample configuration in these do not stop Nagios from starting up. Still, Nagios requires that these files are present in the
etc directory, so create two empty files and name them
escalations.cfg by running the following as root.
root@ducati:/usr/local/nagios/etc# touch dependencies.cfg root@ducati:/usr/local/nagios/etc# touch escalations.cfg
We now have all of the configuration files we need and are ready to start configuring them to suit our monitoring needs. In my next article, I will cover the configuration file basics, how to define services to be monitored, how to configure Nagios to notify people when a service is down, and how to configure and use the Web interface that comes with Nagios.
Until then, Happy Hacking.
Official Nagios Web Site: http://www.nagios.org
Official NetSaint Web Site: http://www.netsaint.org
Nagios Plugins: http://nagiosplug.sourceforge.net
Nagios ScreenShots: http://www.nagios.org/screenshot.php
htpasswd man Page: http://www.rt.com/man/htpasswd.1.html
Oktay Altunergil works for a national web hosting company as a developer concentrating on web applications on the Unix platform.
Return to ONLamp.com.