Friday, June 3, 2011

PNP4Nagios with CentOS

PNP4Nagios with CentOS:

PNP is an addon to Nagios which analyzes performance data provided by plugins and stores them automatically into RRD-databases

Prerequisites

RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. Use it to write your custom monitoring shell scripts or create whole applications using its Perl, Python, Ruby, TCL or PHP bindings.
Our CentOS server needed a few devel libraries installed for RRDtool:

yum -y install cairo-devel glib2-devel pango-devel

Download the latest source for RRDtool

mkdir ~/downloads && cd ~/downloads
wget
http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.3.tar.gz
tar zxf rrdtool-1.4.3.tar.gz
cd rrdtool-1.4.3

Configure it with a few adjustments for our setup:

./configure --prefix=/usr/local/rrdtool

If everything is ok, then build and install it

make
make install


Zlib support for PHP -
--with-zlib

Installation
Download the
latest version of PNP4Nagios:

cd /extra/src
wget
http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.3.tar.gz/download
tar
zxf pnp4nagios-0.6.3.tar.gz
cd pnp4nagios-0.6.3

Configure it:

./configure \
--with-rrdtool=/usr/local/rrdtool/bin/rrdtool \
--with-httpd-conf=/usr/local/apache2/conf/extra \
--with-perl_lib_path=/usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi

Then build and install:

make all
make install

Copy the sample config files:

make install-config

Add pnp4nagios to your Apache configuration:

Install the Apache config file into /etc/httpd/conf.d/pnp4nagios.conf:

make install-webconf

Then edit /etc/httpd/conf/httpd.conf and add a line to load the PNP4Nagios conf file:

Include conf.d/pnp4nagios.conf

or can add the contents of httpd.conf to your Nagios VirtualHost directive:

Alias /pnp4nagios "/usr/local/pnp4nagios/share"


AllowOverride None
Order allow,deny
Allow from all
#
# Use the same value as defined in nagios.conf
#
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

# Turn on URL rewriting
RewriteEngine On
Options FollowSymLinks
# Installation directory
RewriteBase /pnp4nagios/
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

- It might show error related to php-5.2, if it shows such issue add CentOS-Test repository and add following configuration as:

vi /etc/yum.repos.d/CentOS-Test-repo

[CentOS-testing]

name=CentOS-5 Testing

baseurl=http://dev.centos.org/centos/5/testing/$basearch/

enabled=1

gpgcheck=1

gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing

update php:

yum update php


Restart httpd service:

service httpd restart


Access the PNP4Nagios Environment Tests by going to http://localhost/pnp4nagios. If it passes all the tests, remove the install.php file:

mv /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/old.install.php

NPCD Daemon

Copy the sample NPCD config file:

cp /usr/local/pnp4nagios/etc/npcd.cfg-sample /usr/local/pnp4nagios/etc/npcd.cfg

Data Collection :
Nagios needs to be
configured to trigger the data collector by editing /usr/local/nagios/etc/nagios.cfg and editing/uncommenting some lines:

process_performance_data=1
service_perfdata_command=process-service-perfdata
host_perfdata_command=process-host-perfdata

Edit /usr/local/nagios/etc/objects/commands.cfg and remove the existing process-service-perfdata and process-host-perfdatacommands. Then add the new PNP4Nagios commands for service and host performance data logging:

define command {
command_name process-service-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl
}

define command {
command_name process-host-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}

Nagios Web Front-End Integration :
In order to easily view the graphs from your Nagios server, we can take advantage of Nagios' external URL features in extended info configs. There are two ways of doing it - regular links or Javascript pop-ups:

Regular Links
Edit /usr/local/nagios/etc/objects/templates.cfg and add:

# PNP4Nagios host/service definitions
define host {
name host-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}

define service {
name srv-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}

OR

Javascript pop-ups :
Copy
status-header.ssi to your Nagios web files:

cp /downloads/pnp4nagios-0.6.3/contrib/ssi/status-header.ssi \
/usr/local/nagios/share/ssi/

Edit /usr/local/nagios/etc/objects/templates.cfg and add:

define host {
name host-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=_HOST_
register 0
}

define service {
name srv-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}

To use them, add them to your host/service definitions with something similiar to:

define host{
use linux-server,host-pnp ; Name of host templates to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name localhost
alias localhost
address 127.0.0.1
}

define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}

2 comments:

Anonymous said...

dude,,tell me something about groundwork.because i integrate my nagois with groundwork to moniter my my systems(locally connected).

Anonymous said...

I'm really enjoying the design and layout of your website. It's a very easy on the eyes which makes it much more pleasant for me to come here and visit more often.
Did you hire out a designer to create your theme? Superb work!
My weblog - free car check