oreilly.comSafari Books Online.Conferences.


Nagios, Part 2
Pages: 1, 2, 3

Starting Nagios

Now that we have configured the hosts and the services to monitor, we are ready to fire up Nagios and start monitoring. We will start Nagios using the init script that we had installed earlier.

root@ducati:/usr/local/nagios/etc# /etc/rc.d/rc.nagios start 
Starting network monitor: nagios 
/bin/bash: -l: unrecognized option 
 [ ... ]

If you receive the above error message, it means the 'su' command installed on your server does not support the '-l' option. To fix it, open up /etc/rc.d/rc.nagios (or its equivalent on your system) and remove the 'l' where it says 'su -l'. You will end up with 'su -' which means the same thing. After making the change, run the above startup command again. If you receive 'permission denied' errors. Just reset the ownership information on your Nagios installation directory and it will be resolved.

root@ducati:/usr/local/nagios# chown -R nagios  /usr/local/nagios 
root@ducati:/usr/local/nagios# chgrp -R nagios  /usr/local/nagios

If everything went smoothly, Nagios should now be running. The following command will show you whether Nagios is up and running and the process ID associated with it, if it is indeed running.

root@ducati:/usr/local/nagios# /etc/rc.d/rc.nagios status
  PID TTY          TIME CMD
  22645 ?        00:00:00 nagios

The same command will stop Nagios when called with the 'stop' paramter instead of 'start' or 'status'.

The Web Interface

Although Nagios has already started monitoring and is going to send us the notifications if and when something goes wrong, we need to set up the Web interface to be able to interactively monitor services and hosts in real time. The Web interface also gives a view of the big picture by making use of graphics and statistical information.

Sure enough, we need to have a Web server already set up in order to be able to access the Nagios Web interface. For this article we will assume that we are running the Apache Web server. I will use the exact same configuration that is included in the official Nagios documentation because it works fine.

Addition to httpd.conf

ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/
<Directory "/usr/local/nagios/sbin/">
 AllowOverride AuthConfig
 Options ExecCGI
 Order allow,deny
 Allow from all

Alias /nagios/ /usr/local/nagios/share/
<Directory "/usr/local/nagios/share">
 Options None
 AllowOverride AuthConfig
 Order allow,deny
 Allow from all

This configuration creates a Web alias '/nagios/cgi-bin/' and directs it to the cgi scripts in your Nagios 'sbin' directory. Assuming your main Web site is set up at, you will be able to access the Nagios Web interface at . At this point, the Nagios Web interface should come up properly, but you will notice that you cannot access any of the pages. You will get an error message that looks like the following.

It appears as though you do not have permission to view information for any of the hosts you requested... If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.

This is a security precaution that is designed to only allow authorized people to be able to access the monitoring interface. The authentication is handled by your Web server using Basic HTTP Authentication (i.e. .htaccess). Nagios then uses the credentials for the user who has logged in and matches it with the contacts.cfg contact_name entries to determine which sections of the Web interface the current user can access.

Configuring .htaccess based authentication is easy provided that your Web server is already configured to use it. Please refer to the documentation for your Web server if it's not configured. We will assume that our Apache server is configured to look at the .htaccess file and apply the directives found in it.

First, create a file called .htaccess in the /usr/local/nagios/sbin directory. If you would like to lock up your Nagios Web interface completely, you can also put a copy of the same file in the /usr/local/nagios/share directory.

Put the following in this .htaccess file.

AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user

When you're adding your first user, the password file that .htaccess refers to will not be present. You need to run the 'htpasswd' command with the -c option to create the file.

htpasswd -c /usr/local/nagios/etc/htpasswd.users oktay
New password: ******
Re-type new password: ******
Adding password for user oktay

For the rest of your users, use the 'htpasswd' command without the '-c' option so as not to overwrite the existing one. After you add all of your users, you can go back to the Web interface which will now pop up an authentication dialog. Upon successful authentication, you can start using the Web interface. I will not go into detail about using the Web interface since it's pretty self explanatory. Notice that your users will only be able to access information for servers that they are associated with in the Nagios configuration files. Also, some sections of the Web interface will be disabled for everyone by default. If you would like to enable those, take a look at 'etc/cgi.cfg'. For instance, in order to allow the user 'oktay' to access the 'Process Info' section, uncomment the 'authorized_for_system_information' line and add 'oktay' to the list of names delimited by commas.

This is all you need to install and configure Nagios to do basic monitoring of your servers and individual services on these servers. You can then fine tune your monitoring system by going through all of the configuration files and modifying them to match your needs and requirements. Going through all plugins in the libexec directory will also give you a lot of ideas about what local and remote services you can monitor. Nagios also comes with software that can be used to monitor a server's disk and load status remotely. Finally, Nagios comes with so many features that no single article could explain all of it. Please refer to the official documentation for more advanced topics that aren't covered here.

Happy hacking.

Web Resources:

Official Nagios Web Site:
Official NetSaint Web Site:
Nagios Plugins:
Nagios ScreenShots:
htpasswd man Page:

Oktay Altunergil works for a national web hosting company as a developer concentrating on web applications on the Unix platform.

Return to

Sponsored by: