Nagios Documentation

Introduction

Nagios is a popular open source computer system and network monitoring application software. It can be used to easily monitor all hosts, network equipment and services. It can send alerts when things go wrong to a contact address and again when they get better.

Monitoring the Localhost /Linux server

Prepare for Nagios Installation

Ensure that your system’s package repository and installed packages are up to date by issuing the following commands

apt-get update
apt-get upgrade

Install Dependencies

Before we can begin installing Nagios, we must first install several prerequisites. Issue the following command:

apt-get install build-essential php5-gd wget libgd2-xpm libgd2-xpm-dev

Create Users and Groups

Create a new system user account to run Nagios under. Issue the following commands:

adduser --system --no-create-home --disabled-login --group nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -a -G nagcmd www-data

Now we’re ready to continue with the installation of Nagios itself.

Install Nagios

Download Nagios Software

cd /opt/
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz

Build and Install Nagios Core

Issue the following command to extract, compile and install the Nagios Core software:

tar -xzvf /opt/nagios-3.2.1.tar.gz
cd /opt/nagios-3.2.1
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode

Configure Nagios Core

Begin by editing the /usr/local/nagios/etc/objects/contacts.cfg file’s email field Issue the following commands to configure the web interface for Nagios:

cd /opt/nagios-3.2.1
make install-webconf

Now issue the following command to create a password for the nagiosadmin user. You will use this password to log into the Nagios administration panel when it is configured.

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

Now reload the configuration of the web server by issuing the following command:

/etc/init.d/apache2 reload

Before we continue with the web configuration of Nagios we need to install the default plugins for Nagios.

Build and install Nagios Plugins

To install and configure the Nagios plugins, issue the following commands to extract, build, and install them:

cd /opt/
tar xzf /opt/nagios-plugins-1.4.14.tar.gz
cd /opt/nagios-plugins-1.4.14
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

We’re now ready to run Nagios for the first time and continue with the configuration process!

Running Nagios

Issue the following command to ensure that Nagios will be restarted following a system boot.

chmod +x /etc/init.d/nagios
/usr/sbin/update-rc.d -f nagios defaults

Run the following command to check your Nagios configuration file for errors:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Any errors will be shown in red. If everything is okay, you may issue the following command to start Nagios for the first time:

/etc/init.d/nagios start

Now you can access the web based administration and reporting tools by visiting

http://localhost/nagios

Monitoring Remote Linux Machines

Installations and Configurations

Remote Host

Download Nagios Plugins and NRPE Add-on

Download following files from Nagios.org and move to /home/downloads:
• nagios-plugins-1.4.11.tar.gz
• nrpe-2.12.tar.gz

Create nagios account

useradd nagios
passwd nagios

Install nagios-plugin

cd /home/downloads
tar xvfz nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
export LDFLAGS=-ldl
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec/

Install NRPE

cd /home/downloads
tar xvfz nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd

NB: No Xinetd? Sudo apt-get install xinetd

Setup NRPE to run as daemon (i.e as part of xinetd)

Modify the /etc/xinetd.d/nrpe to add the ip-address of the Nagios monitoring server to the only_from directive. Note that there is a space after the 127.0.0.1 and the nagios monitoring server ip-address

only_from = 127.0.0.1 10.10.9.29

Modify the /etc/services and add the following at the end of the file.

nrpe 5666/tcp # NRPE

Start the service

service xinetd restart
netstat -at | grep nrpe

Verify to make sure the NRPE is functioning properly

/usr/local/nagios/libexec/check_nrpe -H localhost

Modify the /usr/local/nagios/etc/nrpe.cfg

Nagios Monitoring Server

Download NRPE Add-on

Download nrpe-2.12.tar.gz from Nagios.org and move to /home/downloads:

Install check_nrpe on the nagios monitoring server

tar xvfz nrpe-2.12.tar.gz
cd nrpe-2.1.2
./configure
make all
make install-plugin

NB: No SSL headers? Sudo apt-get install libssl-devel Verify whether nagios monitoring server can talk to the remotehost.

/usr/local/nagios/libexec/check_nrpe -H 10.10.10.239

Create host and service definition for remote host

Create a new configuration file /usr/local/nagios/etc/objects/hostname.cfg to define the host and service definition for this particular remote host.

Add the following command to /usr/local/nagios/etc/objects/commands.cfg

define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Add the host to Nagios Configuration files

Edit /usr/local/nagios/etc/nagios.cfg file to include the new host defined

Restart the nagios service

Restart the nagios as shown below and login to the nagios web (http://localhost/nagios/) to verify the status of the remotehost linux sever that was added to nagios for monitoring.

service nagios reload

Monitoring Remote Windows Machines

Remote Windows Host

Install NSClient++ on the remote windows server

Download NSCP 0.3.1 (NSClient++-Win32-0.3.1.msi) from NSClient++ Project. NSClient++ is an open source windows service that allows performance metrics to be gathered by Nagios for windows services. Go through the following five NSClient++ installation steps to get the installation completed.
(1) NSClient++ Welcome Screen
(2) License Agreement Screen
(3) Select Installation option and location. Use the default option and click next.
(4) Ready to Install Screen. Click on Install to get it started.
(5) Installation completed Screen.

Modify the NSClient++ Service

Go to Control Panel -> Administrative Tools -> Services. Double click on the “NSClientpp (Nagios) 0.3.1.14 2008-03-12 w32′′ service and select the check-box that says “Allow service to interact with desktop”.

Modify the NSC.ini

(1) Modify NSC.ini and uncomment *.dll:

Edit the C:\Program Files\NSClient++\NSC.ini file and uncomment everything under [modules] except RemoteConfiguration.dll and CheckWMI.dll

(2) Modify NSC.ini and uncomment allowed_hosts.

Edit the C:\Program Files\NSClient++\NSC.ini file and Uncomment allowed_host under settings and add the ip-address of the nagios-server.

(3) Modify NSC.ini and uncomment port.

Edit the C:\Program Files\NSClient++\NSC.ini file and uncomment the port# under [NSClient] section

(4) Modify NSC.ini and specify password.

You can also specify a password the nagios server needs to use to remotely access the NSClient++ agent.

Start the NSClient++ Service

Start the NSClient++ service either from the Control Panel -> Administrative tools -> Services -> Select “NSClientpp (Nagios) 0.3.1.14 2008-03-12 w32′′ and click on start (or) Click on “Start -> All Programs -> NSClient++ -> Start NSClient++ (Win32) . Please note that this will start the NSClient++ as a windows service.
Later if you modify anything in the NSC.ini file, you should restart the “NSClientpp (Nagios) 0.3.1.14 2008-03-12 w32′′ from the windows service.

Nagios monitoring server

Verify check_nt command and windows-server template

Verify that the check_nt is enabled under /usr/local/nagios/etc/objects/commands.cfg

# 'check_nt' command definition
define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
}

Verify that the windows-server template is enabled under /usr/local/nagios/etc/objects/templates.cfg

Uncomment windows.cfg in /usr/local/nagios/etc/nagios.cfg

# Definitions for monitoring a Windows machine
cfg_file=/usr/local/nagios/etc/objects/windows.cfg

Modify /usr/local/nagios/etc/objects/windows.cfg

By default a sample host definition for a windows server is given under windows.cfg, modify this to reflect the appropriate windows server that needs to be monitored through nagios.

Define windows services that should be monitored.

Following are the default windows services that are already enabled in the sample windows.cfg. Make sure to update the host_name on these services to reflect the host_name defined in the above step.

Enable Password Protection

If you specified a password in the NSC.ini file of the NSClient++ configuration file on the Windows machine, you’ll need to modify the check_nt command definition to include the password. Modify the /usr/local/nagios/etc/commands.cfg file and add password as shown below.

define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s My2Secure$Password -v $ARG1$ $ARG2$
}

Verify Configuration and Restart Nagios.

Verify the nagios configuration files as shown below.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios reload