Plugin Perfdata return not graphing correctly

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Brick
Posts: 26
Joined: Thu Aug 29, 2013 6:02 am

Plugin Perfdata return not graphing correctly

Post by Brick »

I have a custom made plugin that returns perfdata on multiple lines.

It is a powershell code that runs locally on the server using nrpe.

This is the return as Powershell sees it-

Code: Select all

Production Adapter - Primary : 2<BR>Cluster Adapter : 0<BR>|'ProductionAdapterPrimary'=2;1;2 'ClusterAdapter'=0;1;2
But when I run it through nagios I get the following-

Code: Select all

Production Adapter - Primary : 1<BR>Cluster Adapter : 0<BR>|'ProductionAdapterP
rimary'=1;1;2 'ClusterAdapter'=0;1;2
because there's too many letters to fit on the first line it splits the perfdata into two separate bits and doesn't graph properly.

The weird thing is that if I stick in a false perfdata entry at the start which pushes the rest onto a new line then it actually reads it all as one line and graphs perfectly fine-

Code: Select all

Production Adapter - Primary : 1<BR>Cluster Adapter : 0<BR>|'stupidnrpe123'=0;0;0 'ProductionAdapterPrimary'=1;1;2 'ClusterAdapter'=0;1;2
I read on the Plugin API that "You can return performance data only in subsequent lines (after the first)" so I guess this would be the best option for me- but I cant figure out how to do it, I've tried \n but it doesn't work...

here is the actualy code-

Code: Select all

$num = 0
$perfdata = "|stupidnrpe123=0;0;0 "
#$perfdata = "|"


#Check if any of them should alert and create perfdata
foreach ($adapter in $adaptercount) {

$adapter = [int]$adapter

#replace spaces in names with underscores just incase nrpe is having problems with spaces
$adaptername[$num] = $adaptername[$num] -replace " ",""
$adaptername[$num] = $adaptername[$num] -replace "-",""

#building the perfdata for graphing
$perfdata += "'" + $adaptername[$num] + "'=" + $adapter + ";" + $warn + ";" + $crit + " "

$num++

if ($warn) {
    if ($adapter -ge $warn) { $exitcode = 1 }
    }
if ($crit) {
    if ($adapter -ge $crit) { $exitcode = 2 }
    }
if (!$exitcode) { $exitcode = 0 }

}


#Add perfdata to the end of the return
$out += $perfdata

echo $out

exit $exitcode
Any thoughts?
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Plugin Perfdata return not graphing correctly

Post by tgriep »

Can you post an example of what the graph looks like?

One thing to note, if you are editing the performance data for your plugin while the XI system is running, it may corrupt the data in the graphs so you could delete the .xml and .rrd files associated with that check and see if the graphs start to function correctly.
Be sure to check out our Knowledgebase for helpful articles and solutions!
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Plugin Perfdata return not graphing correctly

Post by ssax »

Instead of \n try `r`n
Brick
Posts: 26
Joined: Thu Aug 29, 2013 6:02 am

Re: Plugin Perfdata return not graphing correctly

Post by Brick »

The graph looks fine with the stupidnrpe123 entry, but doesn't even display without it-

Image

I can see that the perf data is simply not returning correctly clearer in the thruk interface, this is what it gets as its return-

Image

As you can see its reading the graph data fine because it is all reading it on the same line...

here you can see where I have tried to add in the 'r'n... which breaks the perfdata because the first entry is not short enough to fit on the first line, this is what breaks it...

Image


the stupidnerp123=0;0;0 is just the exact correct length to read correctly as a perfdata entry but fit on the same line as the initial return

You can see it clearly in putty-

This is it working with the extra entry-

Image

This is it broken without-

Image

For some reason the initial perfdata entry gets split when its longer than 19 chars
Brick
Posts: 26
Joined: Thu Aug 29, 2013 6:02 am

Re: Plugin Perfdata return not graphing correctly

Post by Brick »

OK, I jusst fixed it by adding loads of spaces before the pipe in the return so it shunts everything to a new line.... no idea why this works but it works!
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Plugin Perfdata return not graphing correctly

Post by jdalrymple »

This is a less bad hack, albeit still a horrible hack.

OK to lock?
Brick
Posts: 26
Joined: Thu Aug 29, 2013 6:02 am

Re: Plugin Perfdata return not graphing correctly

Post by Brick »

Na, can you leave it open?

The hack you have highlighted doesnt work for me- I am already using an echo command to output...

As for the one I've found It really is a horrible hack and I've already found issues with it when it reports on servers with only one network adapter...

I really need to find a solution to this that works for all instances

Anyone have any thoughts?
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Plugin Perfdata return not graphing correctly

Post by jdalrymple »

Brick wrote:I am already using an echo command to output...
Are you pumping it through cmd.exe like the noted individual does? That's the hack.
User avatar
lgroschen
Posts: 384
Joined: Wed Nov 27, 2013 1:17 pm

Re: Plugin Perfdata return not graphing correctly

Post by lgroschen »

First I think we should step back and make sure the perfdata you created is being read correctly.

According the to Plugin Guidlines Nagios will read anything after a "|" as perfdata, Then it will treat the performance data according to this structure:

Code: Select all

'label'=value[UOM];[warn];[crit];[min];[max]
So I would try by adding a ';' for each that you haven't included- min and max like this:

stupidnerp123=0;0;0;;;

Then it will treat any new spaces after the pipe ("|") as a new set of performance data which will also need trailing semi-colons. Give this a try and see if the graphs change. I would suggest deleting (backup the old files!) the old .rrd and .xml files here: /usr/local/nagios/share/perfdata/ (looks for the folder with the corresponding host name) so the graphs are created fresh.
/Luke
Brick
Posts: 26
Joined: Thu Aug 29, 2013 6:02 am

Re: Plugin Perfdata return not graphing correctly

Post by Brick »

Thanks for your help


I did a bit of research following jdalrymple's suggestion- This is actually caused by a 80 character limit when powershell is used through nsclient

I found a fix here- http://serverfault.com/questions/298769 ... nsole-size

Basically this line increases the buffer length-

Code: Select all

$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (300, 25)
The "300" is the new 'width' from the default 80 but can be set to anything I think, I'm guessing the 25 is the number of lines but I didn't test that

You just need to stick this code at the start of the powershell script and it fixes everything onto one line

This can be closed, thanks all for your help
Locked