Wednesday, September 20, 2017

Steps how to install and configure Pnp4Nagios Bulk+NPCD Mode with Nagios4.x Ubuntu-16.04

Part 1 of Setting up and configuring Nagios4.x and PNP4Nagios.
Part 2 of Setting up and configuring Nagios4.x and PNP4Nagios. 
Part 3 of enable E-mail notification Nagios4.x and PNP4Nagios

PNP4NAGIOS:-
Pnp4Nagios works with Nagios to generate the graph of services that are being monitored by Nagios server. With the help of Pnp4Nagios, we can see the graph anytime whenever needed, It record graph for all the configured services, We can view usage like CPU, RAM, Disk Space etc.
Prerequisites
1- rrdtool
2- librrds-perl
3- Perl
4- Php-gd

Image result for pnp4nagios
Installation:
Step 1-  Install prerequisites run below command
1A- Install rrdtool and librrds-Perl use command below
apt install rrdtool librrds-perl
1B-Download latest Pnp4Nagios from the following link
wget https://versaweb.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.26.tar.gz
1C- Extract Pnp4 package and go to the extracted directory
tar -xvf pnp4nagios-0.6.26.tar.gz && cd pnp4nagios-0.6.26
Step 2- Configure and Install Pnp4Nagios.
We need to configure Pnp4Nagios with Nagios user and with Apache configuration path.
root@U16:~/nagios/pnp4nagios-0.6.26# ./configure --with-command-user=nagios --with-command-group=nagcmd --with-httpd-conf=/etc/apache2/sites-available
root@U16:~/nagios/pnp4nagios-0.6.26# make all
root@U16:~/nagios/pnp4nagios-0.6.26# make fullinstall
Step 3- Configure and enable Pnp4Nagios configuration fiel.
3A- Enable configuration file.
root@U16:~/nagios/pnp4nagios-0.6.26# a2ensite pnp4nagios.conf
3B- Reload apache service.
root@U16:~/nagios/pnp4nagios-0.6.26# systemctl restart apache2
Step 4- Let's modify Nagios configuration file to integrate Pnp4Nagios.
4A-Let's modigy nagios.cfg file.
In the directory / usr / local / pnp4nagios / etc there is nagios.cfg-sample file take Bulk / NPCD mode configuration and change into /usr/local/nagios/etc/nagios.cfg file.
Match the changes as follow
root@U16:~/nagios/pnp4nagios-0.6.26# vi /usr/local/nagios/etc/nagios.cfg


process_performance_data=1

# *** the template definition differs from the one in the original nagios.cfg

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

# *** the template definition differs from the one in the original nagios.cfg

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
4B- Let's modify command.cfg file
We took the below configuration from the following path:
config file path:-   /usr/local/pnp4nagios/etc/misccommands.cfg-sample
root@U16:~/nagios/pnp4nagios-0.6.26# vi /usr/local/nagios/etc/commands.cfg
Go to end of commad.cfg file and append following lines.
# Bulk with NPCD mode

#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$
}


4C- Let's modify template.cfg file
 Edit file using vim editor

root@U16:~/nagios/pnp4nagios-0.6.26#  vi /usr/local/nagios/etc/objects/templates.cfg
Append following line into the end of file.


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 ='/pnp4nagio/index.php/popup?host=$HOSTNAME$&srv=$SERVEDESC$
 register 0
}


4D- Modify host config file.
root@U16:~/nagios/pnp4nagios-0.6.26# vi /usr/local/nagios/etc/objects/localhost.cfg
Made the changes as follow

define host{
        use                     linux-server,host-pnp                                                ; Name of host template 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             Root Partition
        check_command                 check_local_disk!20%!10%!/
        }


4E- Let's copy status-header.ssi file to the nagios directory
root@U16:~/nagios/pnp4nagios-0.6.26# cp contrib/ssi/status-header.ssi /usr/local/nagios/share/ssi/
All the configuration changes have completed.
Step 5- Validate PNP4Nagios installation.  http://ServerIp/pnp4nagios
Open url below to validate pnp4Nagios installation, if everything goes well you will all green check as follow in picture.

Step 6- Rename install.php file & Restart services to apply changes:
file move

mv /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/install.php-bak
For Nagios
root@U16:~/nagios/pnp4nagios-0.6.26# systemctl restart nagios
For Apache

root@U16:~/nagios/pnp4nagios-0.6.26# systemctl restart apache2
For NPCD
root@U16:~/nagios/pnp4nagios-0.6.26# systemctl restart npcd

Let's check Graph for the host:



























PNP4Nagios has been configured successfully with Nagios.


4 comments:

  1. systemctl restart npcd
    Failed to restart npcd.service: Unit npcd.service not found.
    please look into this problem

    ReplyDelete
  2. Con la guia de nagios(instalar pnp4nagios) y la tuya logre hacerlo funcionar , thanks()

    ReplyDelete
  3. systemctl restart npcd
    Failed to restart npcd.service: Unit npcd.service not found.
    please look into this problem

    ReplyDelete