Nagios

Nagios Configuration

Before You Begin

Nagios is quite powerful and flexible, but it can take a lot of work to get it configured just the way you’d like it to be. Nagios being such a vast and extensive product, this document is in no way a reference manual for Nagios. This is written primary with the aim of setting up monitoring, as quickly as possible.

If you just want to setup Nagios, download the Scripts for setting it up. We have written the scripts, so as to make the things easier, but it is highly recommended to go through the documents.

Prerequisites and Tips

  • Always have a separate host as the monitoring node/server and do not install it with other critical services.
  • Nagios runs on multiple platforms like Linux, Solaris, and windows and has very minimum system requirements by today’s standards.
  • The services and number of hosts that are monitored, drive the requirements. Say, if you have 400 hosts with ssh, http ping monitor, then it will be quite I/O extensive.
  • If you are planning a MySql DB integration with Nagios, it is still better to have a disk with good throughput.
  • RAM 1 GB and Disk Space 4 GB
Note: We have production setups running with just 128 MB RAM, monitoring about 300 nodes and 60 - 75 services per host, along with MRTG and they work fine. It depends how we tune things and how many “Active” and “Passive” checks we have.

Dependencies

Make sure “apache” is working on the server by verifying from browser: http://localhost

Verify whether gcc is installed [root@localhost]#rpm -qa | grep gcc
Verify whether GD is installed [root@localhost]# rpm -qa gd

Nagios Overview

Nagios is a powerful monitoring system that provides you with instant awareness of your organization’s mission-critical IT infrastructure. Nagios allows you to detect and repair problems and mitigate future issues before they affect end- users and customers.

By using Nagios, you can:

  • Plan for infrastructure upgrades before outdated systems cause failures.
  • Respond to issues at the first sign of a problem.
  • Automatically fix problems when they are detected.
  • Coordinate technical team responses.
  • Ensure your organization’s SLAs are being met.
  • Ensure IT infrastructure outages have a minimal effect on your organization’s bottom line.

Setup/Installation

Download nagios and nagios-plugin from the nagios repository http://www.nagios.org/download/

If you want to get it through command line, then you can download it using

wget http://sourceforge.net/projects/nagios/files/nagios- 3.x/nagios-3.2.1/nagios-3.2.1.tar.gz/download
wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1 .4.14/nagios-plugins-1.4.14.tar.gz/download

Create a nagios User who will manage the Nagios interface. Must have root privileges.

/usr/sbin/useradd -m nagios
passwd nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

/usr/sbin/groupadd nagcmd; /usr/sbin/usermod -a -G nagcmd nagios; /usr/sbin/usermod -a -G nagcmd apache

Nagios Extraction and Setup

Please check the latest version and download it and follow the steps below.

tar zxvf nagios-3.2.1.tar.gz
cd nagios-3.2.1/ ./configure --with-command-group=nagcmd

Note: On Red Hat, the ./configure command mentioned above might not work and hang at the when it was displaying the message: checking for redhat spopen problem… Add –enable-redhat-pthread-workaround to the. /configure command as a work-around.

make all; sudo make install; sudo make install-init
sudo make install-config; sudo make install-commandmode

Basic Configuration

  1. After installing nagios, we need to do some basic level configuration. Sample configuration files are copied to /usr/local/nagios/etc directory.
  2. We need to edit the /usr/local/nagios/etc/objects/contacts.cfg”, config file and change the email address to the address we want to receive alerts. In our case, it is nagios@localhost.
  3. After installing and configuring nagios, we need to configure the web interface through which we will monitor and manage the services.
  4. Install the Nagios web config file in the Apache conf.d directory.
sudo make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface.

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

Restart Apache to make the new settings take effect.

sudo service httpd restart

Open the following link using browser.

http://localhost/nagios/

Note: If you see message like this "(Return code of 127 is out of bounds - plugin may be missing)" on the right panel, which means your configuration is correct as of now. The above message indicates that the nagios plugins are missing and we will install the plugins in the next step.

Nagios Plug-ins

Nagios provides many useful plug-in to get us started monitoring all the basics. We also need to get the plugins installed to monitor the basic services. Some of the plugins include checks like host check, local disk usage check, HTTP check, Current Load on the system etc. Let’s now get the plugin installed.

tar zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14/
./configure --with-nagios-user=nagios --with-nagios- group=nagios
make ; sudo make install

Now we have the core nagios and nagios plug-in installed, now lets’s put our nagios configuration into action. We will start the nagios service and start monitoring services on localhost.

Verification

Verify whether the nagios configuration file is fine before starting the nagios service.

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

Start the nagios service

sudo service nagios start; sudo chkconfig --add nagios; sudo chkconfig nagios on

Login to the web interface and click on “Services” on the left hand side panel and start
http://localhost/nagios/. It will ask for the username and password, which you provided above, start monitoring your services.

Setup for monitoring clients across network

  • Download NRPE Add-on Install check_nrpe, Create host and service definition for remote host
  • Download Nagios Plugins and NRPE Add-on Create nagios account Install Nagios Plugins
  • Setup NRPE to run as daemon Modify the /usr/local/nagios/etc/nrpe.cfg

How the Communication happen, between the client and the server.

Example: Assume that we want to check the disk space on the remote node.

  • Nagios will execute check_nrpe command on nagios-server and request it to monitor disk usage on remote host using check_disk command.
  • The check_nrpe on the nagios-server will contact the NRPE daemon on remote host and request it to execute the check_disk on remote host.
  • The results of the check_disk command will be returned back by NRPE daemon to the check_nrpe on nagios-server.

Following flow summarizes the above explanation:

 Nagios Server (check_nrpe) —–> Remote host (NRPE deamon) —–> check_disk
 Nagios Server (check_nrpe) <—– Remote host (NRPE
 deamon) <—– check_disk (returns disk space usage)

On each of the Client hosts, do the below steps:

Download Nagios Plugins and NRPE Add-on or copy from the server.
Download following files from Nagios.org: nagios-plugins-1.4.11.tar.gz; nrpe-2.12.tar.gz
Create nagios account: useradd nagios

Install nagios-plugin

[remotehost]# tar xvfz nagios-plugins-1.4.11.tar.gz [remotehost]# cd nagios-plugins-1.4.11 [remotehost]# export LDFLAGS=-ldl
[remotehost]# ./configure --with-nagios-user=nagios --with- nagios-group=nagios --enable-redhat-pthread-workaround [remotehost]# make [remotehost]# make install
[remotehost]# chown nagios.nagios /usr/local/nagios [remotehost]# chown -R nagios.nagios /usr/local/nagios/libexec/

Install NRPE

[remotehost]# 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

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 (in this example, nagios monitoring server ip-address is: 192.168.1.2)

only_from = 127.0.0.1 192.168.1.2
 Modify the /etc/services and add the following at the end of the file.
 nrpe 5666/tcp # NRPE

Start the service

[remotehost]#service xinetd restart
 Verify whether NRPE is listening
[remotehost]# netstat -at | grep nrpe tcp 0 0 *:nrpe *:* LISTEN
 Verify to make sure the NRPE is functioning properly
[remotehost]# /usr/local/nagios/libexec/check_nrpe -H localhost NRPE v2.12

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

The nrpe.cfg file located on the remote host contains the commands that are needed to check the services on the remote host.

Example:
 command[check_users]=/usr/local/nagios/libexec/check_use rs -w 5 -c 10 command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

In all the check commands, the “-w” stands for “Warning” and “-c” stands for “Critical”. for e.g. in the check_disk command below, if the available disk space gets to 20% of less, nagios will send warning message. If it gets to 10% or less, nagios will send critical message. Change the value of “- c” and “-w” parameter below depending on your environment.

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

[remotehost]#/usr/local/nagios/libexec/check_disk -w 20% – c 10% -p /dev/hda1
DISK CRITICAL – free space: / 6420 MB (10% inode=98%);| /=55032MB;51792;58266;0;64741

Configuration steps on the Nagios monitoring server to monitor remote host:

Download NRPE Add-on

Download nrpe-2.12.tar.gz from Nagios.org

Install check_nrpe on the nagios-monitoring server

[nagios-server]# tar xvfz nrpe-2.12.tar.gz
[nagios-server]# cd nrpe-2.1.2
[nagios-server]# ./configure
[nagios-server]# make all
[nagios-server]# make install-plugin
Note: If you get error like the “checking for SSL headers... configure: error: Cannot find ssl headers” error message while performing ./configure. Install openssl-devel as shown below and run the ./configure again to fix the problem.
[nagios-server]# rpm -ivh openssl-devel-0.9.7a- 43.16.i386.rpm krb5-devel-1.3.4-47.i386.rpm zlib-devel- 1.2.1.2-1.2.i386.rpm e2fsprogs-devel-1.35-12.5.el4.i386.rpm

Verify whether nagios monitoring server can talk to the remotehost.

 [nagios-server]#/usr/local/nagios/libexec/check_nrpe -H 192.168.1.3 NRPE v2.12

Create host and service definition for remotehost

Create a new configuration file /usr/local/nagios/etc/objects/remotehost.cfg to define the host and service definition for this particular remotehost. It is good to take the localhost.cfg and copy it as remotehost.cfg and start modifying it according to your needs.

host definition sample:

define host {

use linux-server host_name remotehost alias Remote Host address 192.168.1.3 contact_groups admins

}

Service definition sample:

define service {

use generic-service service_description Root Partition contact_groups admins check_command check_nrpe!check_disk

}
Note: In all the above examples, replace remotehost with the corresponding hostname of your remotehost.

Restart the nagios service

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

[nagios-server]# service nagios reload

The services to be monitored on a box can vary like ssh, disk usage, load, ping, and marketcetra specific ports.

nagios-331-services-full

Leave a Reply

Your email address will not be published. Required fields are marked *