Pnp4nagios – Graph Report Setup


It is an addon for the Nagios Network Monitoring System. PNP provides easy to use, easy to configure RRDTools based performance charts feeded by the performance data output of the Nagios Plugins.

Prerequsties:
rrdtool
php5
php-gd

Step 1: Installation of RRDTOOL

We can install RRDTool using two methods.

Method 1: Using Complie

[root@server.local ~]# cd /opt/
[root@server.local ~]# wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.3.1.tar.gz
[root@server.local ~]# tar -zxvf rrdtool-1.3.1.tar.gz
[root@server.local ~]# export PKG_CONFIG_PATH=/usr/lib/pkgconfig/
[root@server.local ~]# ./configure
Sample output:
config.status: executing default-1 commands
config.status: executing intltool commands
config.status: executing default commands
config.status: executing po/stamp-it commands
checking in... and out again
ordering CD from http://tobi.oetiker.ch/wish .... just kidding ;-)
----------------------------------------------------------------
Config is DONE!
With MMAP IO: yes
Static programs: no
Perl Modules: perl_piped perl_shared
Perl Binary: /usr/bin/perl
Perl Version: 5.8.8
Perl Options: PREFIX=/usr/local/rrdtool-1.3.1 LIB=/usr/local/rrdtool-1.3.1/lib/perl/5.8.8
Ruby Modules:
Ruby Binary: no
Ruby Options: sitedir=$(DESTDIR)NONE/lib/ruby
Build Tcl Bindings: no
Build Python Bindings: yes
Build rrdcgi: yes
Build librrd MT: yes
Link with libintl: yes
Libraries: -lxml2 -lcairo -lcairo -lcairo -lm -lcairo -lpng12 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0

-- Tobi Oetiker
----------------------------------------------------------------
Now compile and install RRDTool on RHEL:

[root@server.local ~]# make
[root@server.local ~]# make install
[root@server.local ~]# cd /usr/local/
[root@server.local ~]# ln -s rrdtool-1.3.1/ rrdtool/
[root@server.local ~]# cd rrdtool
[root@server.local ~]# ls -l

How do I verify my installation?

Now RRDtool is installed and ready to use. You can go to /usr/local/rrdtool/share/rrdtool/examples/ directory and run them to see if your installation has been successful or not:

[root@server.local ~]# cd /usr/local/rrdtool/share/rrdtool/examples/
[root@server.local ~]# ./stripes.pl
[root@server.local ~]# ls -l
[root@server.local ~]# cp stripes.png /var/www/html/

Fire a web browser and see a graph for yourself by typing the following url:

http://localhost/stripes.png

Method 2: Using Yum

[root@server.local ~]# vi /etc/yum.repos.d/dag.repo
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1

[root@server.local ~]# yum install rrdtool

Step 2: Installation of pnp4nagios

Ref: http://docs.pnp4nagios.org/pnp-0.6/config & http://docs.pnp4nagios.org/pnp-0.6/install

[root@server.local ~]# cd /tmp/
[root@server.local ~]# wget http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.19.tar.gz/download
[root@server.local ~]# cd pnp4nagios-0.6.19
[root@server.local ~]# ./configure --with-rrdtool=/usr/local/rrdtool-1.2.xx/bin/rrdtool
[root@server.local ~]# make all
[root@server.local ~]# make install
[root@server.local ~]# make install-config
[root@server.local ~]# make install-webconf
[root@server.local ~]# make install-init
[root@server.local ~]# ldconfig

Step 3: Configuration of pnp4nagios with NPCD method

[root@server.local ~]# vi /usr/local/nagios/etc/nagios.cfg

Change process performance data

process_performance_data=1

Add the below lines after process data

# service performance data
#
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$

service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file

#
# host performance data starting with Nagios 3.0
#
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file

[root@server.local ~]# vi /usr/local/nagios/etc/objects/commands.cfg

Add the below lines in EOF

define command{
command_name process-service-perfdata-file
command_line bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}
define command{
command_name process-host-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}

[root@server.local ~]# cd /usr/local/pnp4nagios/etc/
[root@server.local ~]# mv process_perdata.cfg-sample process_perdata.cfg
[root@server.local ~]# mv npcd.cfg-sample npcd.cfg

Restart the Apache/httpd server

[root@server.local ~]#/etc/init.d/httpd restart

Step 4: Check pnp4nagios

http://IP/pnp4nagios “use nagiosadmin account”

Note: At bottom of the page, if you get no error message and status in green then everything should be fine.

Step 5: Rename the Php installation file

[root@server.local ~]# cd /usr/local/pnp4nagios/share
[root@server.local ~]# mv install.php install.php_bak20121124

Step 6: Start the NPCD service

[root@server.local ~]# /usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg
[root@server.local ~]# /etc/init.d/npcd status

Add the script in /etc/rc.local

[root@server.local ~]# vi /etc/rc.local

Add the below line in EOF

/usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg

Step 7: Integrate Nagios with pnp4nagios

[root@server.local ~]# vi /usr/local/nagios/etc/objects/templates.cfg

Add the below lines in EOF

define host {
name host-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$
}

define service {
name srv-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
}

[root@server.local ~]# vi /usr/local/nagios/etc/objects/localhost.cfg # Not needed

define host{
use linux-server,host-pnp
host_name localhost
alias localhost
address 127.0.0.1
}

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

Like that you can add other peripherals also. ie.,linux servers, windows servers, switches, printers

Creating Custom Template in pnp4nagios

Some time need to create custom template in pnp4nagios for some command which behave differently when execute on remote host as the appearance of graphs depends on the check command used. eg check_nrpe

Example:

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

This would lead to a call of the check_nrpe.php template even when the monitored host would use a completely different plugin which is called via NRPE, eg

In service definition

define service{
use local-service,srv-pnp
host_name SomeHost
service_description Current Load
check_command check_nrpe!check_load
}

This will lead to call to check_nrpe command and it will use the default.php PNP template which may or may not give the graph as required.

Solution: Custom Template

1. Define new command in nagios/commands.cfg

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

2. Modify the service command for the host to use the new command

define service{
use local-service,srv-pnp
host_name SomeHost
service_description Current Load
check_command check_nrpe_load!check_load
}

Reload Nagios so that it start using the new check command.

At this point everything will be working just as before,

Pnp4nagios configuration

1. Define a check command /usr/local/pnp4nagios/etc/check_commands/check_nrpe_load.cfg (with the same name as the check command in above example)

Tip: Just copy the sample command definition /usr/local/pnp4nagios/etc/check_commands/check_nwstat.cfg-sample eg

[root@server.local ~]# cd /usr/local/pnp4nagios/etc/check_commands

[root@server.local ~]# cp check_nwstat.cfg-sample check_nrpe_load.cfg

For more detail on custom command refer to http://docs.pnp4nagios.org/pnp-0.6/tpl_custom

2. Define a customer template for check_nrpe_load

In the above example if check_nrpe_load.cfg have

CUSTOM_TEMPLATE = 0,1 the it will results in ? “check_nrpe_load_check_load.php”

Create a custom template in /usr/local/pnp4nagios/share/templates (pnp4nagios first look for template in this direcotry then fallback to other directories http://docs.pnp4nagios.org/pnp-0.6/tpl)

Note: Or you can just create a symbolic link to existing template that come with pnp4nagios installation eg …

[root@server.local ~]# ln -s ../templates.dist/check_load.php check_nrpe_load_check_load.php

Here is the sample template for check_load on remote hosts that will plot graph of 1M and 15 minute graph for a host,

[root@server.local ~]# cd /usr/local/pnp4nagios/share/templates

[root@server.local ~]# vi check_nrpe_load_check_load.php (template name should match with the custom command definition in our example check_nrpe_load_check_load.php)

Note: For more template use /usr/local/pnp4nagios/share/template.dist/