Category Archives: pnp4nagios

Pnp4nagios Pi – Integrate With Nagios Web Interface

Pnp4nagios Pi – Integrate With Nagios Web Interface

Define pnp4nagios host and service definitions

Pnp4nagios can be integrated in to Nagios using the action_url directive in host and service definitions to add an icon / link to graphs.

The first step to integrate pnp4nagios with the Nagios web interface is to define host and service definitions by performing the following steps:

  • Logon to the Raspberry Pi and execute the following command to become root:
sudo -i
  • Backup the existing  /usr/local/nagios/etc/objects/template.cfg file (Optional step)
cp /usr/local/nagios/etc/objects/templates.cfg /usr/local/nagios/etc/objects/templates.cfg-beforepnp4nagios
  • Next edit /usr/local/nagios/etc/objects/templates.cfg using the editor of your choice
  • Go to the end of the file and add the host and services definitions below:
define host {
   name host-pnp
   action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=HOST
   register 0
}

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

Update the Nagios generic definitions

  • Next locate the generic-host definition and add in the line shown below in bold:
define host{
        name            generic-host ; The name of this host template
        use             host-pnp
  • FInally locate the generic-service definition and add in the line shown below in bold:
define service{
    name                generic-service ; The 'name' of this service template
    use                 service-pnp
  • Save and exit the file
  • Following the modifications to the templates.cfg file Nagios needs to be restarted by executing the following command:
systemctl restart nagios

PHP 7 Modification

Following the installation and configuration of pnp4nagios I encountered the error shown in the screen shot below:

A quick google turned up the following article https://github.com/lingej/pnp4nagios/issues/148 which gave the solution below for me as my Pi is running PHP 7:

  • Edit the /usr/local/pnp4nagios/share/application/models/data.php file
  • Go to line 979 and change if(sizeof($pages) > 0 ){ to if(is_arrary($pages) && sizeof($pages) > 0 ){
  • Save and exit the file

Pnp4nagios Pi – Configuring Nagios Commands

Pnp4nagios Pi – Configuring Nagios Commands

Configure Nagios to process performance data

Following the successful installation of pnp4nagios the next step is to configure Nagios to process performance data as well as send the data to pnp4nagios. The configuration for this piece is performed by editing the main nagios.cfg file to first enable processing of performance data, then configure the performance data file settings for hosts and services.

To modify configure Nagios to process performance data and configure the performance data file settings for hosts and services perform the following steps:

  • Logon to the Raspberry Pi and execute the following command to become root:
sudo -i
  • Backup the existing /usr/local/nagios/etc/nagios.cfg file (Optional step)
cp /usr/local/nagios/etc/nagios.cfg /usr/local/nagios/etc/nagios.cfg-beforepnp4nagios
  • Edit /usr/local/nagios/etc/nagios.cfg using the editor of your choice
  • Locate the line process_performance_date=0 to process_performance_date=1 as shown below:
# PROCESS PERFORMANCE DATA OPTION
# This determines whether or not Nagios will process performance
# data returned from service and host checks. If this option is
# enabled, host performance data will be processed using the
# host_perfdata_command (defined below) and service performance
# data will be processed using the service_perfdata_command (also
#defined below). Read the HTML docs for more information on
#performance data.
#Values: 1 = process performance data, 0 = do not process performance data

process_performance_data=1
  • Next locate the line starting with #host_perfdata_file= and add in the two lines in bold as shown below to set the performance data file locations to pnp4nagios:
# HOST AND SERVICE PERFORMANCE DATA FILES
# These files are used to store host and service performance data.
# Performance data is only written to these files if the
# enable_performance_data option (above) is set to 1.

#host_perfdata_file=/usr/local/nagios/var/host-perfdata
#service_perfdata_file=/usr/local/nagios/var/service-perfdata

host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
  • Next locate the line starting with #host_perfdata_file_template= and add in the two lines in bold as shown below to set the data file templates:
# HOST AND SERVICE PERFORMANCE DATA FILE TEMPLATES
# These options determine what data is written (and how) to the
# performance data files. The templates may contain macros, special
# characters (\t for tab, \r for carriage return, \n for newline)
# and plain text. A newline is automatically added after each write
# to the performance data file. Some examples of what you can do are
# shown below.

#host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
#service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$

host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
  • Next locate the line starting with #host_perfdata_file_mode=a and add the two lines in bold as shown below:
# HOST AND SERVICE PERFORMANCE DATA FILE MODES
# This option determines whether or not the host and service
# performance data files are opened in write ("w") or append ("a")
# mode. If you want to use named pipes, you should use the special
# pipe ("p") mode which avoid blocking at startup, otherwise you will
# likely want the default append ("a") mode.

#host_perfdata_file_mode=a
#service_perfdata_file_mode=a

host_perfdata_file_mode=a
service_perfdata_file_mode=a
  • Next locate the line starting with #host_perfdata_file_processing_interval= and add the two lines in bold as shown below:
# HOST AND SERVICE PERFORMANCE DATA FILE PROCESSING INTERVAL
# These options determine how often (in seconds) the host and service
# performance data files are processed using the commands defined
# below. A value of 0 indicates the files should not be periodically
# processed.

#host_perfdata_file_processing_interval=0
#service_perfdata_file_processing_interval=0

host_perfdata_file_processing_interval=15
service_perfdata_file_processing_interval=15
  • Next locate the line starting with #host_perfdata_file_processing_command= and add the two lines in bold as shown below:
# HOST AND SERVICE PERFORMANCE DATA FILE PROCESSING COMMANDS
# These commands are used to periodically process the host and
# service performance data files. The interval at which the
# processing occurs is determined by the options above.

#host_perfdata_file_processing_command=process-host-perfdata-file
#service_perfdata_file_processing_command=process-service-perfdata-file

host_perfdata_file_processing_command=process-host-perfdata-file-bulk-npcd
service_perfdata_file_processing_command=process-service-perfdata-file-bulk-npcd
  • Save and exit the file

Configure the Nagios commands

The next step in the process is to add the commands to Nagios which will be used to process the performance data with pnp4nagios by performing the following steps:

  • Backup the existing /usr/local/nagios/etc/objects/commands.cfg file (Optional step)
cp /usr/local/nagios/etc/objects/commands.cfg /usr/local/nagios/etc/objects/commands.cfg-beforepnp4nagios
  • Edit /usr/local/nagios/etc/objects/commands.cfg using the editor of your choice
  • Go to the end of the file and add the command definitions below:
define command {
    command_name    process-service-perfdata-file-bulk-npcd
    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-bulk-npcd
    command_line    /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
    }
  • Save and exit the file

Validate the Nagios config and restart Nagios

Once the configuration has been applied to Nagios it needs to be validated and restarted by performing the following steps:

  • Validate the Nagios configuration by executing the following command:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  • Next restart Nagios by executing the following command:
systemctl restart nagios

Next, proceed on to the next article in the series to integrate with the Nagios Core Web Interface.

Pnp4nagios Pi – Installing pnp4nagios

Pnp4nagios Pi – Installing pnp4nagios

Introduction

This article explains how to implement pnp4nagios on a Raspberry Pu running Raspian Buster Lite and Nagios Core 4.4.5.

pnp4nagios is an add-on for Nagios Core which analyzes performance data provided by plugins and stores them automatically into RRD-databases. This data can then be displayed as graphs for host and service checks.

Prerequisites

In order to implement pnp4nagios on a Raspberry Pi running Raspian Buster Lite and Nagios 4.4.5 the following pre-requisites must be met:

  • Nagios Core installed

Preparing to install pnp4nagios

Before installing pnp4nagios the prerequisite packages need to be installed and the software downloaded

To prepare for the installation of pnp4nagios perform the following steps:

  • Logon to the Raspberry Pi and execute the following command to become root:
sudo -i
  • The next step is to install the pre-requisite packages by executing the following commands:
apt-get update
apt-get -y install rrdtool librrds-perl php-gd php-xml
  • Once the prerequisite packages have been installed download and unpack the source code by executing the following commands:
cd /tmp
wget -O pnp4nagios-0.6.26.tar.gz https://sourceforge.net/projects/pnp4nagios/files/latest
tar -zxf pnp4nagios-0.6.26.tar.gz

Compiling and installing pnp4nagios

Once the system has been prepared and the software downloaded, perform the following steps to compile and install pnp4nagios:

  • To configure pnp4nagios execute the following commands:
cd pnp4nagios-0.6.26/
./configure --with-httpd-conf=/etc/apache2/sites-enabled
make all
  • To install pnp4nagios once it has been compiled execute the following commands:
make install
make install-webconf
make install-config
make install-init

Configure and start / restart daemons

The last part of the installation process for pnp4nagios is to configure and start / restart daemons on the server by performing the following steps:

  • To configure and start the npcd daemon execute the following commands:
systemctl daemon-reload
systemctl enable npcd.service
systemctl start npcd
  • The final step is to restart Apache on the server by executing the following command:
systemctl restart Apache

Next, proceed on to the next article in the series to configure Nagios commands.