PNP templates problem

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Michalux
Posts: 10
Joined: Wed Jun 01, 2011 3:36 am

PNP templates problem

Post by Michalux »

Hi,

I've tried to make a PNP template that would iterate through available datasources. That kind of approach has been used in default template (/usr/local/nagios/share/pnp/templates.dist/default.php).
Now it looks like the regular PNP templates behave somehow different that default one. What I get is only one graph from such a template. It looks like it doesn't iterate through all of available datasources (DS) :?:
The problem I want to solve is to define a PNP template to make specialized graphs, but no matter how much datasources there is on particular RRD.

Does anyone knows how to workaround this ?

Regards

Michalux
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: PNP templates problem

Post by mguthrie »

You might have to do a little digging on PNP's documentation to find exactly what you need.

http://docs.pnp4nagios.org/pnp-0.6/tpl
Michalux
Posts: 10
Joined: Wed Jun 01, 2011 3:36 am

Re: PNP templates problem

Post by Michalux »

I'm fairly sure there is no answer to my problem on PNP page :( Actually I'm confident which template is used when - but this is not the case.
The problem is, I don't know why the default template gets special treatment - such as ability to iterate through the datasources, while other templates seem to be treated differently. Cannot force NXI to show the correct graphs using "foreach ($DS as $i) ..." . It works only when I use references like DS[1] DS[2] etc.

Any suggestions ?

Michalux
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: PNP templates problem

Post by mguthrie »

Not sure if this is the issue or not, but templates are associated with the check command being used.

The PNP templates are a little bit weird in the formatting, because all of the indexes start at 1 for some reason, but you could try messing with something like:

if(isset($DS[2]))
{
//add additional rrd formatting
}

It should probably be noted that we as of Nagios XI 2011R1.3, we created our own api for rrdtool that uses the PNP templates and generates the graphs. It bypasses PNP altogether but retains the template formatting. If you're experimenting with the templates and the graph fails to generate, you can look at the /usr/local/nagios/var/graphapi.log file to see the full command that was passed to rrd tool.
Michalux
Posts: 10
Joined: Wed Jun 01, 2011 3:36 am

Re: PNP templates problem

Post by Michalux »

I'm aware about the new API :) and this in not a problem with the check_command. My check_command corresponds to the name of the template, so I'm pretty sure NagiosXI parses the template file I've intended it to parse.
I've also tried the solutions You've mentioned - it actually works as kinda workaround right now for me ;)
But it also has another deficiency or even problem. For instance: if I have 2 data sources in rrd file, and define def[1], def[2] and def[3] in a template file (of course in a manner You've mentioned - so checking out each time if the DS[x] is actually available) each time NagiosXI will print 2 graphs and third empty placeholder for the DS that actually does not exist. So you never know if you see all the available graphs or have a problem with on or more of them (that show only empty placeholders) - i.e. due to some data corruption or something else.
It looks to me, that when a particular def[x] appears somewhere in the template file - even in a section, that is surrounded by a condition (for instance an if { }), than even if that condition hasn't been met, the graphs tab shows an empty placeholder for such a def[x]. For instance, when the template file looks like this:
if(isset($DS[1])) {
$opt[1] = "--vertical-label \"[sec]\" -l0 -u $CRIT[1] --title \"graph1\" ";
$def[1] = "DEF:var1=$rrdfile:$DS[1]:AVERAGE " ;
$def[1] .= "AREA:var1#00AA00:\"Test1\" " ;
...
}
if(isset($DS[2])) {
$opt[2] = "--vertical-label \"[sec]\" -l0 -u $CRIT[1] --title \"graph2\" ";
$def[2] = "DEF:var1=$rrdfile:$DS[2]:AVERAGE " ;
$def[2] .= "AREA:var1#AA0000:\"Test2\" " ;
.....
}

and I have only one DS defined in RRD, the performance graphs tab shows one graph and another empty placeholder (with datasource caption above) for the not existing one.

Any suggestions about this behavior :?:

Michalux
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: PNP templates problem

Post by mguthrie »

So bear with me, I'm having a little bit of trouble following you on this. Can you send me a few examples of performance data that this template will use, as well as the template that you're working on?
Michalux
Posts: 10
Joined: Wed Jun 01, 2011 3:36 am

Re: PNP templates problem

Post by Michalux »

Ok, so I have something like this:
NXI service running on two separate hosts and monitoring the usage of all local filesystems.
The first host has one local filesystem (i.e. /) and second one has two such filesystems (i.e. /, /opt).
Since both hosts use the same service - and the same check command, they use the same template file.
The performance data from the service no 1 looks like this: /=XXXXXMB;;;;
The performance data from the service no 1 looks like this: /=XXXXXMB;;;;/opt=YYYYYMB;;;;

The template file looks as follows:
if(isset($DS[1])) {
$opt[1] = "--vertical-label \"[sec]\" -l0 -u $CRIT[1] --title \"graph1\" ";
$def[1] = "DEF:var1=$rrdfile:$DS[1]:AVERAGE " ;
$def[1] .= "AREA:var1#00AA00:\"FS1 Used\" " ;
}
if(isset($DS[2])) {
$opt[2] = "--vertical-label \"[sec]\" -l0 -u $CRIT[1] --title \"graph2\" ";
$def[2] = "DEF:var1=$rrdfile:$DS[2]:AVERAGE " ;
$def[2] .= "AREA:var1#AA0000:\"FS2 Used\" " ;
}

So the problem is that looking at the graphs tab for the server's no 1 service monitoring its filesystems, I can see one graph and one empty placeholder.
On the host no. 2, I can see two graphs (as expected).
So when the numer of datasources is less than 2, I get one empty placeholder in graphs tab - that is really anoying :(

Hope that clarified the case :)

Michalux
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: PNP templates problem

Post by mguthrie »

So it's generating a blank graph for that service even though there's no data for it?
Michalux
Posts: 10
Joined: Wed Jun 01, 2011 3:36 am

Re: PNP templates problem

Post by Michalux »

It's actually not an empty graph but only a caption with ds number and and empty placeholder (with an icon that shows, when the web server cannot find a picture).
So as I've mentioned before it looks like, that when you input some def[x] anywhere in the template file, than even if it shouldn't be used (because the conditions has not been met), NXI can somehow see it and looks for a pircture/graph for it - doesn't find it so shows this epmpty placeholder (so if a service provides i.e. 1 performance data value, and there are def[1], def[2], def[3], def[4] defined in a template file- all under some conditions, you'll get one graph and 3 empty placeholders on graphs tab).

What about that ?

Michalux
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: PNP templates problem

Post by mguthrie »

Ok, if you're using Nagios XI 1.3 then there's a log file at /usr/local/nagios/var/graphapi.log that should log the rrd call that was run and failed. If you can post that, I might be able to help you narrow it down, or otherwise if you want to either post or PM me with the template I can take a look at that as well. ( I wrote the new graph api), so I'd be interested to know if there's a bug in the PNP template integration.