1. Nagios is ready

Make sure nagios is ready; nagios plugins and nrpe are installed.

2. Install rrdtool

rrdtool is necessary for storing nagios data, and used to draw graph be pnp4nagios.Current version of rrdtool is 1.4.7, but installs it by yum only get 1.3.8. So, have to manually install 1.4.7. Download the required RPMS and install it [root@nagios~]# wget http://pkgs.repoforge.org/rrdtool/perl-rrdtool-1.4.7-1.el6.rfx.i686.rpm [root@nagios~]# wget http://pkgs.repoforge.org/rrdtool/rrdtool-1.4.7-1.el6.rfx.i686.rpm [root@nagios~]# rpm -ivh rrdtool-1.4.7-1.el6.rfx.i686.rpm perl-rrdtool-1.4.7-1.el6.rfx.i686.rpm

2.1 Install related libs

[root@nagios~]# yum install libdbi 1 [root@nagios~]# yum install ruby xorg-x11-fonts-Type1 3

2.3 Test rrdtool

rrdtool is ready to use, but have to verify that if it is functioning properly. [root@nagios~]# rrdtool -v 4 It shows rrdtool version is 1.4.7. Go to examples folder. [root@nagios~]# cd /usr/share/rrdtool/examples Run the perl script to create a demo png. [root@nagios~]# ./stripes.pl [root@nagios~]#cp stripes.png /var/www/html View the png in browser:  http://ip/stripes.png

stripes

3. Install pnp4nagios

3.1 Download the latest version

# wget http://downloads.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.21.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fpnp4nagios%2F&ts=1372937581&use_mirror=jaist [root@nagios~]#tar -zxvf pnp4nagios-0.6.21.tar.gz [root@nagios~]# cd  pnp4nagios-0.6.21 [root@nagios~]#./configure –prefix=/usr/share/pnp4nagios –with-rrdtool=/usr/bin/rrdtool –with-nagios-user=nagios –with-nagios-group=nagios 5

3.2 Compile and install

[root@nagios~]# make all && make install && make install-webconf && make install-config && make install-init Make sure no errors shown up. 3.3 Rename cfg files

[root@nagios~]# cd   /usr/share/pnp4nagios/etc 
[root@nagios~]# mv misccommands.cfg-sample  misccommands.cfg 
[root@nagios~]# mv nagios.cfg-sample nagios.cfg 
[root@nagios~]# mv rra.cfg-sample rra.cfg 
[root@nagios~]# cd /usr/share/pnp4nagios/etc/pages/ 
[root@nagios~]# mv web_traffic.cfg-sample web_traffic.cfg 
[root@nagios~]# cd ../check_commands 
[root@nagios~]# mv check_all_local_disks.cfg-sample  check_all_local_disks.cfg 
[root@nagios~]# mv check_nrpe.cfg-sample  check_nrpe.cfg 
[root@nagios~]# mv check_nwstat.cfg-sample  check_nwstat.cfg

3.4 Set up npcd service
Set npcd service to automatically start when system boot.

[root@nagios~]# chkconfig --add npcd
[root@nagios~]# chkconfig npcd on
[root@nagios~]# service npcd start

3.5 Test pnp4nagios

Type in http://server-ip/pnp4nagios to test result.
6

And then remove the install file as:
[root@nagios~]# rm /usr/share/pnp4nagios/share/install.php

3.6 Set up bulk+npcd for pnp4nagios

 The mode of bulk+npcd is working for a good performance of nagios.
 [root@nagios~]# vi /usr/local/nagios/etc/nagios.cfg

Add or UN-comment below lines:
process_performance_data=1
#
# service performance data
#
service_perfdata_file=/usr/share/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/share/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

3.7 Modify commands.cfg

 
A command is unique, a duplicated command would cause a nagios syntax error.
[root@nagios~]# vi /etc/nagios/objects/misccommands.cfg
 Change the command_line as below:
define command{
command_name    process-service-perfdata-file
command_line    /bin/mv /usr/share/pnp4nagios/var/service-perfdata /usr/share/pnp4nagios/var/spool/service-perfdata.$TIMET$
}

The command_name is defined in both of nagios.cfg and commands.cfg, the command_name have to be matched in the two files. And then reload nagios: [root@nagios~]#service nagios reload

3.8 Verify pnp4nagios configuration

It is hard to identify if the settings of pnp4nagios are all correct, the messages in log
file usually are not easy to understand. Fortunately, a verify script is available to 
complete this task. 

Download the perl script "verify_pnp_config" to verify configuration.
# wget http://verify.pnp4nagios.org/verify_pnp_config

Run the script to verify.
# perl verify_pnp_config –mode bulk+npcd –config=/usr/local/nagios/etc/nagios.cfg –pnpcfg=/usr/share/pnp4nagios/etc
7

The verification is passed, and performance data is shown as well, it means all settings are correct. Otherwise, have to fix any critical errors before go forward. Go to http://server-ip/pnp4nagios again, it shows some graphs 8

3.9 Integrated with Nagios

Since nagios 3.0, the action_url-directive has be moved to the host or service definition. Only need to modify the definition of action URLs to show PNP-interface. Two nagios templates are defined to create hosts and services, host-templates.cfg and service-templates.cfg, which will use action-url. Create a new host-pnp in host-templates.cfg: define host { name       host-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_ register   0 } And create a new srv-pnp in service-templates.cfg: define service { name                srv-pnp action_url      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$ register   0 } These two templates can now be included via “use srv-pnp” or “use host-pnp” for services and hosts respectively. In the hosts.cfg and services.cfg, add “use host-pnp” and “use srv-png as below.

define host{
use         linux-server,host-pnp          ; Name of host templates to use
                                           ; host definition will inherit all variables that are defined
                                           ; in (or inherited by) the linux-server host template 

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%
}

Restart nagios, the links to the correct URLs are created automatically. 9 The action icon is shown in the nagios pane, but the icon should indicate that is a pnp graph. Change the image of the icon for better showing. # cd /usr/local/nagios/share/images # cp trends.gif action.gif The icon looks nice after the browser reload. Clicking at the icon would show up pnp graphs. 10 By default, pnp graphs would be opened in a new window, but if it is shown in the main frame would be a better feeling for users. This could be changed in cgi.cfg file. # vim /usr/local/nagios/etc/cgi.cfg Change “action_url_target = main”, save and reload nagios, the result is shown as below. 11

3.10 Popups pnp graphs

When move over the mouse on the icon, a pnp graph is popup, it is a very cool feeling for users. Some changes should be applied to action_url. First, need to copy ssi( server side include) from pnp4nagios install folder to nagios folder. # cp download/php4nagios-head/contrib/ssi/* /usr/local/nagios/share/ssi Second, modify the action_url in host-pnp and srv-pnp as below.

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

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

12
The installation and configuration of pnp4nagios are completed.
Posted in: Linux.
Last Modified: January 12, 2017

5 thoughts on “Installing PNP4Nagios on CentOS

  1. GregW

    big shout out for this – thanks very much – helped me troubleshoot my install big time.

    in 3.8 you call out
    # perl verify_pnp_config –mode bulk+npcd –config=/usr/local/nagios/nagios/nagios.cfg –pnpcfg=/usr/share/pnp4nagios/etc

    should be
    # perl verify_pnp_config –mode bulk+npcd –config=/usr/local/nagios/etc/nagios.cfg –pnpcfg=/usr/share/pnp4nagios/etc

    1. Alex Hunt Post author

      yes you are right. It is a typing mistake from my side. Thanks for pointing out though.

  2. sharing

    Undeniably consider that which you said. Your favourite reason appeared to be on the net the
    easiest thing to take note of. I say to you, I certainly
    get annoyed even as people consider worries that they
    just do not know about. You managed to hit the nail
    upon the highest as neatly as defined out the whole thing without having side effect , people can take a signal.

    Will likely be again to get more. Thank you

    1. Alex Hunt Post author

      It gives me an immense pleasure when these solutions posted here works for people.

Leave a reply