Page 1 of 1

PNP templates problem

Posted: Tue Jun 28, 2011 4:32 am
by pzusa
Tried on the global forum - but the topic seems to be dead ... So maybe here someone could help ?
Problem is about using PNP graph templates. For instance:

There are 2 services under localhost:

Code: Select all

define service {
host_name localhost
service_description FS1 Used
use template1
check_command check_disks! -p / -p /store!!!!!!!
register 1
}

define service {
host_name localhost
service_description FS2 Used
use template1
check_command check_disks! -p / -p /store -p /boot!!!!!!!
register 1
}
First one check 2 file-systems, while second one checks 3 file-systems.

The PNP template file looks like this:

Code: Select all

<?php
if(isset($DS[1])) {
$opt[1] = "--vertical-label \"MB\" -l0 --title \"$hostname - 1\" ";
$def[1] = "DEF:var1=$rrdfile:$DS[1]:AVERAGE " ;
$def[1] .= "AREA:var1#FF0000:\"Space used \" " ;
$def[1] .= "GPRINT:var1:LAST:\"%6.2lf last\" " ;
$def[1] .= "GPRINT:var1:AVERAGE:\"%6.2lf avg\" " ;
$def[1] .= "GPRINT:var1:MAX:\"%6.2lf max\\n\" " ;
}

if(isset($DS[2])) {
$opt[2] = "--vertical-label \"MB\" -l0 --title \"$hostname - 2\" ";
$def[2] = "DEF:var2=$rrdfile:$DS[2]:AVERAGE " ;
$def[2] .= "AREA:var2#00AA00:\"Space used \" " ;
$def[2] .= "GPRINT:var2:LAST:\"%6.2lf last\" " ;
$def[2] .= "GPRINT:var2:AVERAGE:\"%6.2lf avg\" " ;
$def[2] .= "GPRINT:var2:MAX:\"%6.2lf max\\n\" " ;
}

if(isset($DS[3])) {
$opt[3] = "--vertical-label \"MB\" -l0 --title \"$hostname - 3\" ";
$def[3] = "DEF:var3=$rrdfile:$DS[3]:AVERAGE " ;
$def[3] .= "AREA:var3#0000BB:\"Space used \" " ;
$def[3] .= "GPRINT:var3:LAST:\"%6.2lf last\" " ;
$def[3] .= "GPRINT:var3:AVERAGE:\"%6.2lf avg\" " ;
$def[3] .= "GPRINT:var3:MAX:\"%6.2lf max\\n\" " ;
}
?>
Than - looking at the service's FS1 Used Performance Graphs tab I get 2 graphs with one (last) empty placeholder. For FS2 Used - I get 3 performance graphs (as expected).
So the problem is this third empty placeholder for the first service - it shouldn't appear since there is no DS[3] defined.

Any ideas ?

Michalux

Re: PNP templates problem

Posted: Tue Jun 28, 2011 9:35 am
by mguthrie
I'll test out your template and see what I can find out.

Re: PNP templates problem

Posted: Tue Jun 28, 2011 10:13 am
by mguthrie
Ok, so I'm still digging on this, but it looks like if datasources are defined in a template, Nagios XI will make a call for that set of data even if there isn't one. I haven't quite pinned it down yet, but it looks like it's a minor bug. When I locate it I'll file a bug report and post the link so you can track it's progress.

Re: PNP templates problem

Posted: Tue Jun 28, 2011 3:26 pm
by mguthrie
Ok, there was a function in XI that checked for datasources in the template, and if it found them it would request graphs for them regardless of if there was data for it. I tested a fix using your template, and the issue should be resolved in the next release. If you want to test the patch out before then let me know and I'll send it to you.

Re: PNP templates problem

Posted: Wed Jun 29, 2011 5:03 am
by pzusa
Hi,

I'd appreciate if You could make this patch available to me :)

By the way - there is probably another thing that works somehow strange (maybe it is connected ?) - From what I've tested the default template (templates.dist/default.php) is treated differently that any other. What I mean is the default.php has an iterated form [ foreach ($DS as $i) ]. Trying to use the same form in any other template file does not work (NXI/PNP seems not to iterate through available DSs).

Michalux

Re: PNP templates problem

Posted: Wed Jun 29, 2011 9:35 am
by mguthrie
Make a backup of the file:
/usr/local/nagiosxi/html/includes/components/pnp/pnp.inc.php

then unzip and place this new file in that directory location.

As far as the other issue you mentioned, see if this patch fixes that, because I did change the behavior of XI a little in that it will not call for graphs based on what datasources are referenced in the xml file that's associated with the RRD. If the issue persists after this patch, see if you can figure out some steps to recreate it and I'll take a look at it.

Re: PNP templates problem

Posted: Thu Jun 30, 2011 2:09 am
by pzusa
I've implemented the patch.
Unfortunately now is even worse ... Now I can see empty placeholders for all datasources I have in particular rrd file (no matter what the template file defines).
So even when the template file defines, that i.e. 3 datasources should be printed all on one graph, I get the one graph (actually printed correctly) but additionally 2 empty placeholders with captions named exactly as datasources (example screenshot below).

Actually I've looked through the patch You've provided and the behavior mentioned above seems to be obvious. Patched pnp.inc.php version doesn't check for the datasources defined in the the template file anymore , but directly goes to the xml file for the DS list - so the result is as many placeholders/graphs as found in xml file.
On the other hand the pnp_read_service_sources_from_template function seems to be too simple to properly get required number of graphs since it doesn't correlate def[] definitions found in a template file with DSes in corresponding rrd or xml file. Checking if defined in a template number of graphs (def[] number) is more/less than the number of DSes found in rrd/xml file won't be enough either, since often there is more than one DS used on one graph (we can have i.e. 10 datasources and only 2 graphs). So I guess the solution could probably be to check the number of DS[] definitions for each def[] in a template file and then take only those def[] numbers for which we have DSes defined in rrd/xml file. But it's just a guess ... :D

And about the second bug I've mentioned lately - looking at the function pnp_read_service_sources_from_template_file I can understand why the iterated form doesn't work as expected. The function doesn't finds even one def[n] in the whole template file since all references look like def[$i], where $i is of course a variable. So the array of defined def[] numbers is empty - so no graph appears in the graph's tab. The question is why this works with default.php template ? (different processing with default template ?).

So ... any ideas ?

Michalux

Re: PNP templates problem

Posted: Thu Jun 30, 2011 9:25 am
by mguthrie
OK, I reverted the script back to what it was before. I'll file a bug a report and take another stab at it when I get the chance.
http://tracker.nagios.com/view.php?id=170

Re: PNP templates problem

Posted: Fri Jul 01, 2011 12:38 am
by pzusa
Looking forward to some solution ...

Michalux