Nagios/PNP4Nagios

From Segfault
Jump to navigation Jump to search

PNP is an addon to Nagios Core which analyzes performance data.

Installation

apt install automake autoconf gcc make libtool-bin libc6-dev rrdtool librrds-perl             # For Debian systems.

git clone https://github.com/pnp4nagios/pnp4nagios.git pnp4nagios-git
cd pnp4nagios-git

We'd like to install in /opt but with the performance data stored undeneath our already existing Nagios installation:

./configure --prefix=/opt/pnp4nagios --with-nagios-user=naemon --with-nagios-group=naemon --with-httpd-conf=/opt/pnp4nagios/etc
make all
sudo make fullinstall

Configuration

We also need to decide how performance data is collected. PNP4Nagios offers serveral modes how to do this. In short:

  • Synchronous Mode - process_perfdata.pl gets called for every Nagios check run.
  • Bulk Mode - Performance data is written to a temporary file, which will be processed by process_perfdata.pl later on.
  • Bulk Mode with NPCD - As with Bulk Mode, performance data is written to a temporary file. The temporary file is moved to a spool directory, which will then be processed by NPCD ("Nagios Performance C Daemon").
  • Bulk Mode with npcdmod - Same as Bulk Mode, but implemented with npcdmod.o, a NEB (Nagios Event Broker) module.
  • Gearman Mode - PNP4Nagios driven as a Gearman worker. A mod_gearman environment is required.

Bulk mode

For our installation Bulk mode will be sufficient. Modifications to nagios.cfg are needed to make this work:

process_performance_data   = 1

# host_perfdata_command    = process-host-perfdata           # Don't need to be set for bulk mode
# service_perfdata_command = process-service-perfdata        # Don't need to be set for bulk mode

host_perfdata_file         = /var/lib/nagios3/pnp4nagios/perfdata/host-perfdata
service_perfdata_file      = /var/lib/nagios3/pnp4nagios/perfdata/service-perfdata

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$

host_perfdata_file_mode        = a                          # append, write, pipe
service_perfdata_file_mode     = a

host_perfdata_file_processing_interval    = 15
service_perfdata_file_processing_interval = 15

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

These processing commands need to be registered with Nagios, in commands.cfg:

# process-service-perfdata-file
define command {
      command_name    process-service-perfdata-file
      command_line    /opt/pnp4nagios/libexec/process_perfdata.pl \
                      --bulk=/var/lib/nagios3/pnp4nagios/perfdata/service-perfdata
}
# process-host-perfdata-file 
define command {
      command_name    process-host-perfdata-file
      command_line    /opt/pnp4nagios/libexec/process_perfdata.pl \
                      --bulk=/var/lib/nagios3/pnp4nagios/perfdata/host-perfdata
}

With all that in place, Nagios can be restarted to activate performance data collection. We can verify our configuration with:

cd ~/pnp4nagios-git
sudo scripts/verify_pnp_config_v2.pl -c /etc/nagios3/nagios.cfg -p /opt/pnp4nagios/etc -m bulk

Nagios Integration

For PNP4Nagios to show up in the Nagios web frontend, we will create templates for both service and host performance graphs:

$ cat generic-pnp.cfg
define host {
       name            pnp-host
       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            pnp-service
       action_url      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
       action_url      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
       register        0
}

Now, in our generic-host.cfg template definition, we can add:

define host {
       [...]
       register          0         ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
       use               pnp-host
}

Note: in the action_url above we have already added the popup feature, so that a small preview of a graph is being overlayed during mouse-over. For this to work, we need to add some Javascript code to our Nagios installation. For a Debian installation, this might look like this:

cd ~/pnp4nagios-git
sudo cp contrib/ssi/status-header.ssi /usr/share/nagios3/htdocs/ssi/
sudo chmod 0644 /usr/share/nagios3/htdocs/ssi/status-header.ssi

With Thruk installed, these SSI files are already included, but have to be activated:

cd /etc/thruk/ssi/
ln -s extinfo-header.ssi{.example,}
ln -s status-header.ssi{.example,}

Restart Thruk and each check using the service-pnp or host-pnp template should display a small popup now during mouseover.

Bugs

For PNP4Nagios to work, some PHP settings needed to be modified:

  • Add the following paths to open_basedir
/opt/pnp4nagios/:/var/lib/nagios3/pnp4nagios/perfdata/:/usr/bin/rrdtool
  • Remove the following from disable_functions
; proc_open     - pnp4nagios: Undefined variable: pipes, 
                  application/models/rrdtool.php [36]
; proc_close    - pnp4nagios: proc_close() has been disabled for security reasons, 
                  application/models/rrdtool.php [52]