Icinga2, icingaweb2, director and pnp4nagios on ubuntu 20.04 howto

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

2 Likes

Excellent - thank you for sharing your learning process with us.

I have one question regarding the functionality of PNP4Nagios (which I have
used for meany years in various versions, and with various versions of
Icinga).

When you have a graph displayed in the right-hand pane of an Icinga page, can
you click into the graph and select a narrower timescale (ie: basically, zoom
in to the data to see more detail for a smaller portion of the time axis)?

This used to work in icinga 2.9.1 with icingaweb 2.4.2, php 5.4.45 and
pnp4nagios 0.6.19.

Once you get to icinga 2.10.7 with icingaweb 2.8.2, php 5.6.33 and pnp4nagios
0.6.24, the graphs are still displayed but there’s no “click to zoom in”
function any more, and I miss that :frowning:

Does your solution support this feature?

Thanks,

Antony.

Yes zoom works - can you hit http://ip/pnp4nagios
It should return a page without errors

Good news that zoom works for you.

If I visit that URL I do indeed get a page without errors (it shows me every
pnp4nagios graph for the alphabetically first hostname in my monitoring setup)
but there is no zoom capability.

Antony.

If I click on the thumbnail graph on say a service - then a window appears to the right in which I can zoom by dragging an area - I am using google chrome (if that makes a difference)

Added 2 pictures - 1st where I zoom, second the result

Ok the order of the pictures are wrong - but shows zoom capabilities

Yes, that is what happens on my older setup (using Firefox as it happens).
The slightly more updated one doesn’t do that - clicking on a graph and then
dragging just shows the graph sliding across the browser window, and then
snapping back again when you release the mouse button.

Antony.

My versions are:
icinga2web: 2.8.2
php: 7.4.3
icinga2:2.12.3-1
pnp4nagios: 0.6.26
So I am on a newer pnp4nagios, php and icinga2

Welcome to the community and wow!
Thank you for sharing and contributing :slight_smile: