Installation on Nagios Server:

sudo apt-get install apache2
sudo apt-get install libapache2-mod-php5
sudo apt-get install build-essential

Create a new nagios user account and give it a password.

useradd -s /bin/bash -m nagios
passwd nagios

If nagios group is not created by default, do

groupadd nagios
usermod -G nagios nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface.

groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data

Download Nagios and nagios plugins source files

Goto /usr/src/ direcotry and download Nagios core, and nagios plugins source files. http://www.nagios.org/download/

cd /usr/src
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz

Extract, Compile and Install Nagios

tar xzf nagios-3.2.3.tar.gz
cd nagios-3.2.3

Run the Nagios configure script, passing the name of the group :

./configure –with-command-group=nagcmd

Compile the Nagios source code.

make all

Install binaries, init script, sample config files and set permissions on the external command directory.

make install
make install-init
make install-config
make install-commandmode

Install the Nagios web config file in the Apache conf.d directory

make install-webconf

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

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
 
To change the password of nagiosadmin account
htpasswd /usr/local/nagios/etc/htpasswd.users nagiosadmin
 

Edit / Change the email address where to receive notifications, under contact definition

vi /usr/local/nagios/etc/objects/contacts.cfg
email myemail@domainname.com 

Restart Apache to make the new settings take effect.

/etc/init.d/apache2 reload

Compile and install Nagios Plugins

tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11

Compile and install the plugins.

./configure –with-nagios-user=nagios –with-nagios-group=nagios
make
make install

Verify the sample Nagios configuration files.

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

To Check / verify If Nagios Plugins are installed properly and working file. Goto Nagios Plugin directory and pass any webserver host to check_http plugin to verify it’s working

cd /usr/local/nagios/libexec/
./check_http -H ANYWEBSERVER

If there are no errors, start Nagios.

/etc/init.d/nagios start

Login to web-interface

http://%5BIP-ADDRESS]/nagios/

Configure Nagios to automatically start when the system bootup

update-rc.d nagios defaults

To receive email notifications, Nagios alerts, you need to install the mailx (Postfix) package

sudo apt-get install postfix mailutils
a. No configuration / Internet Site / Internet with smarthost / Satellite system / Local only ?
Select Internet Site
b. FQDN ?
nagiostest.com
c. Nagios Web Admin password ?
Add Password to be used by Nagios Admin Web Login

You’ll have to edit the Nagios email notification commands found in /usr/local/nagios/etc/objects/commands.cfg. Under ‘Notify-host-by-email’ and ‘notify-service-by-email’ definitions code block, change ‘/bin/mail’ to ‘/usr/bin/mail’

vi /usr/local/nagios/etc/objects/commands.cfg
/bin/mail –> /usr/bin/mail

Restart Nagios

/etc/init.d/nagios restart

————————————–Your Nagios instlallation is completed————————————-

Configuring NRPE (Nagios Remote Plugin Executor)

Nagios Remote Plugin Executor (NRPE) is a Nagios agent that allows remote systems monitoring using scripts that are hosted on the remote systems. it us used ONLY for those processes which we cannot see outside of the system , like processes, ram, disk, users etc etc. PING, SSH, HTTP services does not need NRPE service as they can be remotely monitored.

Installation of NRPE Plugin on Nagios Server
Install some required packages

apt-get install libssl-dev

Goto /usr/src/ direcotry and download Nagios NRPE plugin source files

cd /usr/src
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz

Extract Nagios NRPE

tar -zxf nrpe-2.13.tar.gz
cd nrpe-2.13

Run the Nagios NRPE configure script, compile the Nagios source code & Install binaries

./configure –enable-command-args
make all
make install-plugin

Now, edit /usr/local/nagios/etc/resource.cfg and declare another user , and assign it to the path of NRPE plugin, i,e

vi /usr/local/nagios/etc/resource.cfg
$USER2$=/usr/lib/nagios/plugins

Now, edit /usr/local/nagios/etc/objects/commands.cfg file and add command definition for “check_nrpe”command. Add below lines at the end of file.
define command{
command_name check_nrpe
command_line $USER2$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
 

Restart Nagios to make changes to take effect

/etc/init.d/nagios restart

Install NRPE plugin on your remote host

apt-get install nagios-nrpe-plugin

Edit the NRPE configuration file in remote host to allow Nagios server to communicate

vi /etc/nagios/nrpe.cfg
allowed_hosts=192.168.2.15 (Nagios Server IP)
Make sure remote host listening on NRPE port 5666.
server_port=5666

Your plugin will be placed here: ‘/usr/lib/nagios/plugins/‘ and , file name is ‘check_nrpe’You can see NRPE command definitation in ‘/etc/nagios/nrpe.cfg‘ , The format of NRPE command definiation is :

command[<command_name>]=<command_line>
command[check_sda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1

Here You can define Warning (-w) % and Critical (-c) % of any check


Restart NRPE Server (remote host)

/etc/init.d/nagios-nrpe-server restart

After Installing NRPE Server on remote server, to check NRPE connection of Remote Server and Nagios Server, Goto Nagios Server and execute following commands, if successfull it will show NRPE version of remote host

cd /usr/local/nagios/libexec/

./check_nrpe -H 192.168.2.14 (remote host IP)

__________________________________________________________________________________

Adding a remote host and monitoring through NRPE

If Linux remote server is to be added, then copy of localhost.cfg will be used, otherwise copy of windows.cfg will be used and That file has to be mentioned in nagios.cfg

On Nagios Server , goto /usr/local/nagios/etc/objectsCreate a copy of “localhost.cfg” as “new_host.cfg”

cp localhost.cfg newhost.cfg

Edit /usr/local/nagios/etc/nagios.cfg file and add newhost.cfg path like localhost.cfg path is added

vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/newhost.cfg

Edit newhost.cfg file just created in /usr/local/nagios/etc/objects and add make following changes

vi /usr/local/nagios/etc/objects/newhost.cfg
a. Replace All ‘localhost’ Name with ‘newhost’ Name of new host
:% s/localhost/newhost
b. Replace the IP 127.0.0.1 of localhost to IP of new server to be monitored, under host defination
c. In all service definations, replace keyword ‘local-service’ with ‘generic-service’
:% s/local-service/generic-service
d. Replace ‘check_command’ values under all services definitions according to Service definitation of remote host file ‘/etc/nagios/nrpe.cfg’ Appending ‘check_nrpe’ before original command, this combination will fetch each command through NRPE plugin, like
In ‘CPU Load / Current Load’ check_command change value to ‘check_nrpe!check_load’
In ‘Root Partition’ check_command change value to ‘check_nrpe!check_hda1′
In ‘Check Users’ check_command change value to ‘check_nrpe!check_users’
In ‘Total Procs’ check_command change value to ‘check_nrpe!check_total_procs’
In ‘Zombie Procs’ check_command change value to ‘check_nrpe!check_zombie_procs’
In ‘Memory Usage’ check_command change value to ‘check_nrpe!check_memory’
SSH, PING, HTTP will remain same as they will be checked from outside the remote system
e. If you need to add this host to linux-systems (same group), then hash group definitaion in this .cfg file and add this host name in localhost.cfg file.
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members localhost, newhost ; Comma separated list of hosts that belong to this group
}

———————————————————————————————————————————————————–

Tunning Nagios Check Intervals

a. Check Main Nagios Configuraiton file ‘interval_length’ Value as it has great importance

vi /usr/local/nagios/etc/nagios.cfg
# This is the seconds per unit interval as used in the
# host/contact/service configuration files. Setting this to 60 means
# that each interval is one minute long (60 seconds). If 1 means that
# each interval is one second long.
interval_length=60

b. Active check are executed at regular intervals, as defined by the check_interval and retry_interval options in your host and service definitions

c. Depending on the template used in host / service definitions, Modify the definitions of templates according to your need.

d. Precidence here is the key to understand the definition hirerchy. Anything defined in host definition will take preceidence over, linux-server and linux-server will take precidence over generic-host

1-..Host Deifinition
2-……linux-server / windows-server
3-……………generic-host

1. Below mentioned settings can be overridden by adding then in host’s own definition. If your host definition is using ‘linux-server’ or ‘generic-host’ or ‘windows-server’ template, change following values in that template like shown

vi /usr/local/nagios/etc/objects/templates.cfg
check_interval 2 ; Actively check the host every 2 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 3 ; Check each Linux host 3 times (max)
notification_period 24×7 ; Send host notifications at any time
notification_interval 5 ; Resend notifications every 5 minute
notification_options d,u,r ; Only send notifications for down, up, and recovery host states

2. Below mentioned settings can be overridden by adding then in host’s own service definition. If your host service definition is using ‘local-service’ or ‘generic-service’ template, change following values in that template like shown

vi /usr/local/nagios/etc/objects/templates.cfg
max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
normal_check_interval 2 ; Check the service every 2 minutes under normal conditions
retry_check_interval 1 ; Schedule host check retries at 1 minute intervals
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 20 ; Re-notify about service problems every 20 minute
notification_period 24×7 ; Send notifications at any time

3. Restart Nagios

/etc/init.d/nagios restart

———————————————————————————————————————————————————–

Adding PNP4Nagios (Graphs) in Synchronous Mode

It depends on rrdtool, so install that and additional prerequisites first

apt-get install librrds-perl php5-gd rrdtool

Goto /usr/src/ direcotry and download PNP4Nagios plugin source files. http://docs.pnp4nagios.org/pnp-0.6/dwnld

cd /usr/src
wget http://downloads.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.17.tar.gz

Extract PNP4Nagios Plugin

tar -zxf pnp4nagios-0.6.17.tar.gz
cd pnp4nagios-0.6.17

Configure and compile PNP4Nagios plugin

./configure –with-nagios-user=nagios –with-nagios-group=nagios –prefix=/usr/local/nagios/pnp4nagios
make all

Install the main program, runlevel scripts, config and HTML files. ‘make fullinstall’ combines install, install-webconf, install-config, and install-init.

make fullinstall

Enable processing of performance data in nagios.cfg, additionally specify command to process performance data.

vi /usr/local/nagios/etc/nagios.cfg
process_performance_data=1
enable_environment_macros=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata

Nagios has to be notified about the referenced commands as well, modify the definitions in commands.cfg

vi /usr/local/nagios/etc/objects/commands.cfg
define command {
command_name process-service-perfdata
command_line /usr/bin/perl /usr/local/nagios/pnp4nagios/libexec/process_perfdata.pl
}
define command {
command_name process-host-perfdata
command_line /usr/bin/perl /usr/local/nagios/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}

Change default magic_quotes_gpc setting of PHP. Also enable mod_rewrite

vi /etc/php5/apache2/php.ini
magic_quotes_gpc = Off
a2enmod rewrite

Restart Apache for changes to take effect

/etc/init.d/apache2 restart

Visit http://%5BIP-ADDRESS%5D/pnp4nagios/ to ensure everything is set up correctly. Then delete the install.php to be able to use PNP

http://%5BIP-ADDRESS%5D/pnp4nagios/
rm /usr/local/nagios/pnp4nagios/share/install.php

Restart Nagios and Apache

/etc/init.d/nagios restart
/etc/init.d/apache2 restart

PNP4Nagios configured, Browse it through web

http://%5BIP-ADDRESS%5D/pnp4nagios/

The hosts and services for which you want to have graphs enabled need to have an action URL defined.
When this is done, you will have an icon next to the hosts & services for which you defined this, which will bring you to pnp4nagios

vi /usr/local/nagios/etc/objects/templates.cfg
a. Which ever template your host definitions are using, ‘linux-server’ or ‘generic-host’, Inside its definition add
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_’ class=’tips’ rel=’/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
b.Which ever template your host service definitions are using, ‘local-service’ or ‘generic-service’, Inside its definition add
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$’ class=’tips’ rel=’/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
vi /usr/local/nagios/etc/cgi.cfg
action_url_target=_self
notes_url_target=_self

To perfectly integrate PNP into Nagios and enable mouse-over popups of graphs, put status-header.ssi from source directory into Nagios and set up its permissions

cp /usr/src/pnp4nagios-0.6.17/contrib/ssi/status-header.ssi /usr/local/nagios/share/ssi
chown nagios:nagios /usr/local/nagios/share/ssi/status-header.ssi
chmod 644 /usr/local/nagios/share/ssi/status-header.ssi

Restart Nagios and Apache

/etc/init.d/nagios restart
/etc/init.d/apache2 restart
Advertisements