I’ve had hell on earth getting a working setup of icinga2, icingaweb, director and PNP graphing up and running.
I finally succeeded and thought I wanted to share the knowledge as a lot of ppl seems struggling to get especially the graph part to work (regardless whether its graphite, grafana or PNP).
I made a writeup of it all here: Install Icinga2, Icingaweb2, director and PNP on ubuntu 20.04 – Home of Skau
I am only sharing this because I was unable to find a good writeup on a modern OS
The icinga part is more or less just doing what the documentation sais so no need to touch on it in here - but the PNP part might be of interest.
Hence a quick howto on that part.
install the graphing modules
apt-get install icingaweb2-module-pnp
apt-get install rrdtool librrd-dev librrds-perl librrdp-perl php-xml php-rrd gcc make
mkdir -p /files/pnp
cd /files/pnp
wget -O pnp4nagios.tar.gz https://github.com/lingej/pnp4nagios/archive/0.6.26.tar.gz
tar xzf pnp4nagios.tar.gz
cd pnp4nagios-0.6.26
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/bin/rrdtool --with-perfdata-dir=/var/spool/icinga2/perfdata --with-httpd-conf=/etc/apache2/sites-available
make all
make full-install
Remove login to pnp4nagios (by changing apache conf file (all chages before mod_rewrite section)
vi /etc/apache2/sites-available/pnp4nagios.conf
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
Alias /pnp4nagios "/usr/local/pnp4nagios/share"
<Directory "/usr/local/pnp4nagios/share">
AllowOverride None
# Order allow,deny
# Allow from all
require all granted
#
# Use the same value as defined in nagios.conf
#
# AuthName "Nagios Access"
# AuthType Basic
# AuthUserFile /usr/local/nagios/etc/htpasswd.users
# Require valid-user
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
Options symLinksIfOwnerMatch
# Installation directory
RewriteBase /pnp4nagios/
# Protect application and system files from being viewed
RewriteRule "^(?:application|modules|system)/" - [F]
# Allow any files or directories that exist to be displayed directly
RewriteCond "%{REQUEST_FILENAME}" !-f
RewriteCond "%{REQUEST_FILENAME}" !-d
# Rewrite all other URLs to index.php/URL
RewriteRule "^.*$" "index.php/$0" [PT]
</IfModule>
</Directory>
Enable the config and reload apache
a2ensite pnp4nagios.conf
systemctl reload apache2
Add www-data to nagios group so it can read data
vi /etc/group add to the existing nagios line
nagios:x:118:www-data
Enable pnp module and start creating perfdata
icingacli module enable pnp
icinga2 feature enable perfdata
systemctl restart icinga2
mv /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/install.php.orig
cd /usr/local/pnp4nagios/etc
mv misccommands.cfg-sample misccommands.cfg
mv nagios.cfg-sample nagios.cfg
systemctl enable npcd
systemctl start npcd
Pnp4nagios is build for PHP5, as we are using PHP7 there is 1 deprecated function in Input.php that needs to be bypassed – I’ve done it by encapsulating it in an if statement like this (remember to close out the if at the end with } (so add the first and last line where it’s applicable):
vi /usr/local/pnp4nagios/lib/kohana/system/libraries/drivers/Input.php
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
// magic_quotes_runtime is enabled
if (get_magic_quotes_runtime())
{
set_magic_quotes_runtime(0);
Kohana::log('debug', 'Disable magic_quotes_runtime! It is evil and deprecated: http://php.net/magic_quotes');
}
// magic_quotes_gpc is enabled
if (get_magic_quotes_gpc())
{
$this->magic_quotes_gpc = TRUE;
Kohana::log('debug', 'Disable magic_quotes_gpc! It is evil and deprecated: http://php.net/magic_quotes');
}
}
Then you need to change line 979 in the file: /usr/local/pnp4nagios/share/application/models/data.php
(use :979 to jump to that line)
vi /usr/local/pnp4nagios/share/application/models/data.php
From:
if(sizeof($pages) > 0 ){
To:
if(is_array($pages) && sizeof($pages) > 0 ){
Correct perfdata_spool_dir line in npcd config
vi /usr/local/pnp4nagios/etc/npcd.cfg
perfdata_spool_dir = /var/spool/icinga2/perfdata
Last go in icinga2 webpage and configure pnp to the correct config dir:
Log into icinga2 and goto configuration → modules → pnp → configuration
set pnp4nagios configuration to: /usr/local/pnp4nagios/etc
At this point I like to reboot to ensure everything works after reboot