Debianhelp.co.uk


Nagios Installation and configuration

What is nagios ?

Nagios is a host and service monitor designed to inform you of network problems before your clients, end-users or managers do. It has been designed to run under the Linux operating system, but works fine under most *NIX variants as well. The monitoring daemon runs intermittent checks on hosts and services you specify using external "plugins" which return status information to Nagios. When problems are encountered, the daemon can send notifications out to administrative contacts in a variety of different ways (email, instant message, SMS, etc.). Current status information, historical logs, and reports can all be accessed via a web browser.

Nagios Features

Nagios has a lot of features, making it a very powerful monitoring tool. Some of the major features are listed below:

Monitoring of network services (SMTP, POP3, HTTP, NNTP, PING, etc.)

Monitoring of host resources (processor load, disk and memory usage, running processes, log files, etc.)

Monitoring of environmental factors such as temperature

Simple plugin design that allows users to easily develop their own host and service checks

Ability to define network host hierarchy, allowing detection of and distinction between hosts that are down and those that are unreachable

Contact notifications when service or host problems occur and get resolved (via email, pager, or other user-defined method)

Optional escalation of host and service notifications to different contact groups

Ability to define event handlers to be run during service or host events for proactive problem resolution

Support for implementing redundant and distributed monitoring servers

External command interface that allows on-the-fly modifications to be made to the monitoring and notification
behavior through the use of event handlers, the web interface, and third-party applications

Retention of host and service status across program restarts

Scheduled downtime for suppressing host and service notifications during periods of planned outages

Ability to acknowledge problems via the web interface

Web interface for viewing current network status, notification and problem history, log file, etc.

Simple authorization scheme that allows you restrict what users can see and do from the web interface

Nagios Requirements

The only requirement of running Nagios is a machine running Linux (or UNIX variant) and a C compiler. You will probably also want to have TCP/IP configured, as most service checks will be performed over the network.

You are not required to use the CGIs included with Nagios. However, if you do decide to use them, you will need to have the following software installed.

A web server (preferrably Apache)

Thomas Boutell's gd library version 1.6.3 or higher (required by the statusmap and trends CGIs)

Download Nagios

http://www.nagios.org/download/

Nagios Documentation

http://www.nagios.org/docs/

Nagios Screenshots

http://www.nagios.org/about/screenshots.php

Nagios FAQ

http://www.nagios.org/faqs/

Installing Nagios in Debian From Source Code

Prerequisites

The below packages are very important to install on your debian system to complete the nagios installation without any problem

#apt-get install make gcc g++

Create Nagios User/Group

You're probably going to want to run Nagios under a normal user account, so add a new user (and group) to your system with the following command (this will vary depending on what OS you're running):

#adduser nagios

This should create the user account and a default group with the same name (nagios). This can be checked by

# grep nagios /etc/passwd

This should show the group (if created) with the members.

If the group is missing then create the group by,

# groupadd nagios

This group can be used as the group that  Nagios uses as a Command group.

Identify Web Server User

You're probably going to want to issue external commands (like acknowledgements and scheduled downtime) from the web interface. To do so, you need to identify the user your web server runs as (typically apache, although this may differ on your system). This setting is found in your web server configuration file. The following command can be used to quickly determine what user Apache is running as (paths may differ on your system):

# grep "^User" /etc/apache2/apache2.conf

Add Webserver user (www-data/apache) and Nagios user (nagios)

# usermod -G nagios nagios

#usermod -G www-data,nagios www-data

Check if the users are the members of the group by

# grep nagios /etc/group

Create Installation Directory

Create the base directory where you would like to install Nagios as follows

#mkdir /usr/local/nagios

Change the owner of the base installtion directory to be the Nagios user and group you added earlier as follows:

#chown -R nagios:nagios /usr/local/nagios

Prior to that, it is imporant to install the GD-Utils for the Status Maps to work properly.

In Debian, the following should install the required libraries:

# apt-get install libgd2-xpm libgd2-xpm-dev libgd2 libgd2-dev libpng12-dev libjpeg62-dev libgd-tools libpng3-dev

Now, download the GD-Utils from the following website:

http://www.boutell.com/gd/http/gd-2.0.33.tar.gz

Untar the downloaded Tar file by

# tar -zxvf gd-2.0.33.tar.gz

Change to the directory and run the config script.

# cd gd-2.033

# ./configure

Now, install using

# make && make install

This should install the GD-Utils.

Download the latest version of nagios from the following link

http://www.nagios.org/download/

Unpacking The Distribution

To unpack the Nagios distribution, use the following command

#tar xzf nagios-2.6.tar.gz

or

#unp nagios-2.6.tar.gz

If you want to install unp package check here

This will create the Nagios-version folder (nagios-2.6)

Change directory to the newly created directory

#cd nagios-version (nagios-2.6)

Run the configure script

# ./configure --prefix=/usr/local/nagios --with-cgiurl=/nagios/cgi-bin --with-htmurl=/nagios/ --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagios

where
--prefix=/usr/local/nagios is the Nagios root folder
--with-cgiurl=/nagios/cgi-bin is the Nagios CGI folder
--with-htmurl=/nagios/ is the Nagios HTML/Website folder
--with-nagios-user=nagios is the Nagios user
--with-nagios-group=nagios is the Nagios group
--with-command-group=nagios is the Nagios command group which has webserver user (Apache) and the nagios user as members.

If you want more oprtion just type the following command

#./configure --help

 ./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
 -h, --help              display this help and exit
     --help=short       display options specific to this package
     --help=recursive  display the short help of all the included packages
 -V, --version           display version information and exit
 -q, --quiet, --silent  do not print `checking...' messages
     --cache-file=FILE cache test results in FILE [disabled]
 -C, --config-cache   alias for `--cache-file=config.cache'
 -n, --no-create        do not create output files
     --srcdir=DIR         find the sources in DIR [configure dir or `..']

Installation directories:
 --prefix=PREFIX         install architecture-independent files in PREFIX[/usr/local/nagios]
 --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX[PREFIX]

By default, `make install' will install all the files in `/usr/local/nagios/bin', `/usr/local/nagios/lib' etc.  You can specify an installation prefix other than `/usr/local/nagios' using `--prefix', for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
 --bindir=DIR           user executables [EPREFIX/bin]
 --sbindir=DIR          system admin executables [EPREFIX/sbin]
 --libexecdir=DIR       program executables [EPREFIX/libexec]
 --datadir=DIR          read-only architecture-independent data [PREFIX/share]
 --sysconfdir=DIR      read-only single-machine data [PREFIX/etc]
 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
 --localstatedir=DIR    modifiable single-machine data [PREFIX/var]
 --libdir=DIR              object code libraries [EPREFIX/lib]
 --includedir=DIR       C header files [PREFIX/include]
 --oldincludedir=DIR   C header files for non-gcc [/usr/include]
 --infodir=DIR           info documentation [PREFIX/info]
 --mandir=DIR           man documentation [PREFIX/man]

System types:
 --build=BUILD     configure for building on BUILD [guessed]
 --host=HOST       cross-compile to build programs to run on HOST [BUILD]

Optional Features:
 --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
 --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
--disable-statusmap=disables compilation of statusmap CGI
--disable-statuswrl=disables compilation of statuswrl (VRML) CGI
--enable-DEBUG0 shows function entry and exit
--enable-DEBUG1 shows general info messages
--enable-DEBUG2 shows warning messages
--enable-DEBUG3 shows scheduled events (service and host checks... etc)
--enable-DEBUG4 shows service and host notifications
--enable-DEBUG5 shows SQL queries
--enable-DEBUGALL shows all debugging messages
--enable-nanosleep enables use of nanosleep (instead sleep) in event timing
--enable-event-broker enables integration of event broker routines
--enable-embedded-perl will enable embedded Perl interpreter
--enable-cygwin enables building under the CYGWIN environment

Optional Packages:
 --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
 --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
--with-nagios-user=<user> sets user name to run nagios
--with-nagios-group=<grp> sets group name to run nagios
--with-command-user=<user> sets user name for command access
--with-command-group=<grp> sets group name for command access
--with-mail=<path_to_mail> sets path to equivalent program to mail
--with-init-dir=<path> sets directory to place init script into
--with-lockfile=<path> sets path and file name for lock file
--with-gd-lib=DIR sets location of the gd library
--with-gd-inc=DIR sets location of the gd include files
--with-cgiurl=<local-url> sets URL for cgi programs (do not use a trailing slash)
--with-htmurl=<local-url> sets URL for public html
--with-perlcache turns on cacheing of internally compiled Perl scripts

Some influential environment variables:
 CC          C compiler command
 CFLAGS    C compiler flags
 LDFLAGS   linker flags, e.g. -L<lib dir> if you have libraries in a
                nonstandard directory <lib dir>
 CPPFLAGS  C/C++ preprocessor flags, e.g. -I<include dir> if you have
                 headers in a nonstandard directory <include dir>
 CPP           C preprocessor

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.


#make all

this will Compile Nagios and the CGIs

#make install

This will Install the binaries and HTML files (documentation and main web page)

#make install-init

This will install the Startup scripts

# make install-commandmode

this will Create the required directory for command file and assign appropriate permissions to it for the external commands.

# make install-config

This installs *SAMPLE* config files in /usr/local/nagios/etc .You'll have to modify these sample files before you can use Nagios.

This will complete the installation Now we need to know the Directory Structure and File locations

#cd /usr/local/nagios

You should see five different subdirectories. A brief description of what each directory contains is given below.

Sub-Directory Contents

bin/ Nagios core program
etc/ Main, resource, object, and CGI configuration files should be put here
sbin/ CGIs
share/ HTML files (for web interface and online documentation)
var/ Empty directory for the log file, status file, retention file, etc.
var/archives Empty directory for the archived logs
var/rw Empty directory for the external command file

Now one thing you need to concentrate is /usr/local/nagios/etc directory where all the sample configuration files stores.

cgi.cfg-sample    nagios.cfg-sample bigger.cfg-sample   misccommands.cfg-sample  checkcommands.cfg-sample  minimal.cfg-sample  resource.cfg-sample

The above are the sample configuration files you need to rename those files to .cfg files i am showing here one example you need to do for the other files

# mv bigger.cfg-sample bigger.cfg

Important Note :- In nagios 2.x(For nagios 1.x versions it creats at the time of installation) hosts.cfg,services.cfg,commands.cfg and other configuration files are not crteated by default we need to create these files using the existing sample files like bigger.cfg and minimal.cfg and other files

We will see more about these file in Configuration section

Now, you have a completely installed nagios to work on. The next steps would be to install the plugins and start configuring Nagios.

Install Nagios Plugins

In order for Nagios to be of any use to you, you need to install nagios plugins. Plugins are usually installed in the libexec/ directory of your Nagios installation (i.e. /usr/local/nagios/libexec). Plugins are scripts or binaries which perform all the service and host checks that constitute monitoring.

Download the latest version of nagios Plugins from the following

http://sourceforge.net/projects/nagiosplug/

The nagios-Plugins version at the time of writing this document is nagios-plugins-1.4.5

Download Nagios Plugins

# wget http://mesh.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.5.tar.gz

Untar the downloaded file

# tar -zxvf nagios-plugins-<version>.tar.gz [here nagios-plugins-1.4.5.tar.gz]

This will create a new directory nagios-plugins-<version> [here nagios-plugins-1.4.5]

Change to the Directory and run the Configure Script

# cd nagios-plugins-1.4.5

# ./configure

Run the following to make and install the plugins

# make && make install

This should install the pugins in the /usr/local/nagios/libexec directory.

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.

/usr/local/nagios/libexec# ./check_ssh -h
check_ssh (nagios-plugins 1.3.0-alpha1) 1.1.1.1
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 (remi@sinfomic.fr)

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

This shows us that the check_ssh plugin accepts one required parameter host, and two optional paramters, timeout and port.

Now the complete Nagios Directory structure

bin/ Nagios core program
etc/ Main, resource, object, and CGI configuration files should be put here
sbin/ CGIs
share/ HTML files (for web interface and online documentation)
var/ Empty directory for the log file, status file, retention file, etc.
var/archives Empty directory for the archived logs
var/rw Empty directory for the external command file
libexec/ nagios plugins available in this

Now Basic installation of nagios completed.Now you need to configure the web interface for nagios.

Configure the Web interface For Nagios in Debian

Find how to setup the web-interface and configure the user authentication for nagios. This article also describes how to force teh CGIs to use Authentication.

Once Nagios and the plugins are installed. It's time to create the front end web interface for nagios. For this, you need to configure the Alias for the web interface and the script alias for the CGIs on your webserver.

In Debian with Apache2 you can do this by the following:

Create the config file for nagios in Apache

Creating the config file nagios (or in any name that you want the alias to called as) in the /etc/apache2/sites-available/ with the following contents (copy & paste using VI):

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

<Directory "/usr/local/nagios/sbin">
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>

Alias /nagios /usr/local/nagios/share

<Directory "/usr/local/nagios/share">
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>

Enable the website

# a2ensite nagios

This enables the site and you can find a soft link to the /etc/apache2/sites-available/nagios under /etc/apache2/sites-enabled/ directory.

Restart apache

# /etc/init.d/apache2 restart

Setup User Authentication

You can setup the authentication for the users to have access to the interface and hence not open to all.

This can be done by

# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Enter the required password when prompted. This will setup htaccess on the site by creating a new file named htpasswd.users under /usr/local/nagios/etc/ with the first user nagios admin. This forces Apache to use the htpasswd.users to check and authenticate the users

You can add as many user you wish by

# htpasswd /usr/local/nagios/etc/htpasswd.users (username)

NOTE: Remember to remove -c from the previous command and substitute the username accordingly.

Force CGI s to use Authentication

For the CGIs to use Authentication on Nagios, edit the file /usr/local/nagios/etc/cgi.cfg and set

use_authentication=1

You can now access the web interface at http://<IPADDRESS OR HOSTNAME>/nagios/

This completes the setup of the web interface and the user and CGI authentication procedures.

1)When I click the "3-D Status Map" link my browser tries to download and save the statuswrl.cgi file ?

A)This will happen if you do not have a VRML client/plugin installed for your web browser. Installing a VRML plugin should resolve this issue.

Download VRML Plugin for your Browser

http://cic.nist.gov/vrml/vbdetect.html

Now you need to configure the Nagios Configuration files this is very important