Page 2 of 4

Re: pnp4nagios 0.6.25 BULK Mode with NPCD

Posted: Thu Nov 12, 2015 10:33 pm
by Pikmin
Thank you very much!!!

Code: Select all

# 'check_local_mrtgtraf' command definition
define command{
        command_name    check_local_mrtgtraf
        command_line    $USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$
        }

Code: Select all

Usage check_mrtgtraf -F <log_file> -a <AVG | MAX> -w <warning_pair> -c <critical_pair> [-e expire_minutes]
./check_mrtgtraf --version
check_mrtgtraf v2.0.3 (nagios-plugins 2.0.3)
check_local_mrtgtraf!/var/www/mrtg/192.168.199.1_5.log!AVG!11250000,11250000!11875000,11875000!10

The value of 10 at the end might be the -e expires_minutes by looking at the check_mrtgtraf help, this service check actually came with nagios core when I installed it (it was in switch.cfg), I only modified the warning and critical pairs




Still not sure if this part is right, I am probably totally wrong:

Code: Select all

Found Performance Data for something-router / Tunnel0 (in=166.028320KB/s;11250000.000000;11875000.000000;0.000000 out=89.237305KB/s;11250000.000000;11875000.00$
166.028320 KB/s
11250000.000000 B/s
check_mrtgtraf uses Bytes per second while pnp4nagios is using KiloBytes per second, is it possible that pnp4nagios just thinks 11250000.000000 B/s are actually KB/s

Re: pnp4nagios 0.6.25 BULK Mode with NPCD

Posted: Thu Nov 12, 2015 11:02 pm
by Box293
You may just need to change these in your service definition:

Code: Select all

11250000,11250000!11875000,11875000

11250,11250!11875,11875
http://www.dr-lex.be/info-stuff/bytecalc.html

It is the plugin that is returning these values in your performance data.

Re: pnp4nagios 0.6.25 BULK Mode with NPCD

Posted: Thu Nov 12, 2015 11:14 pm
by Pikmin
Thanks for the suggestion, I've been playing with the values

However changing them to bytes gives me a critical when it shouldn't, should it? :D

Bytes

Code: Select all

./check_mrtgtraf -F /var/www/mrtg/192.168.199.1_5.log -w 11250000 11250000 -c 11875000 11875000 -e 10
Traffic OK - Avg. In = 245.1 KB/s, Avg. Out = 77.0 KB/s|in=245.115234KB/s;11250000.000000;11875000.000000;0.000000 out=77.003906KB/s;11250000.000000;11875000.000000;0.000000
KiloBytes

Code: Select all

[root@ndnagios libexec]# ./check_mrtgtraf -F /var/www/mrtg/192.168.199.1_5.log -w 11250 11250 -c 11875 11875 -e 10
Traffic CRITICAL - Avg. In = 245.1 KB/s, Avg. Out = 77.0 KB/s|in=245.115234KB/s;11250.000000;11875.000000;0.000000 out=77.003906KB/s;11250.000000;11875.000000;0.000000
Might try and upgrade the nagios-plugins
2.1.1 2015-06-31 Latest stable release Source Code nagios-plugins-2.1.1.tar.gz

Mine is nagios-plugins 2.0.3

Re: pnp4nagios 0.6.25 BULK Mode with NPCD

Posted: Fri Nov 13, 2015 3:12 pm
by tmcdonald
Try the upgrade and get back to us!

Re: pnp4nagios 0.6.25 BULK Mode with NPCD

Posted: Fri Nov 13, 2015 7:45 pm
by Pikmin
Upgraded the plugins, same thing :)
According to the documentation the units are definitely in Bytes/sec
https://www.monitoring-plugins.org/doc/ ... gtraf.html

So I'd say the plugin is doing what it should but pnp4nagios doesn't seem to recognise the warning and critical correctly :/

EDIT:
Found some more info by reading http://docs.pnp4nagios.org/pnp-0.6/tpl
My template for Tunnel0 is <TEMPLATE>check_local_mrtgtraf</TEMPLATE>
but that template does not exist, there is a default.php so I'm assuming it's using that template, my php knowledge is non existent so I'm not sure how to change the units but I might be on the right path here...
In pnp4nagios Latest, Max and Average values appear to be showing correctly, if the load is high the units automatically change from KB to MB, so it's just warning and critical that I'm having problems with

Code: Select all

<?php
#
# Copyright (c) 2006-2010 Joerg Linge (http://www.pnp4nagios.org)
# Default Template used if no other template is found.
# Don`t delete this file !
#
# Define some colors ..
#
$_WARNRULE = '#FFFF00';
$_CRITRULE = '#FF0000';
$_AREA     = '#256aef';
$_LINE     = '#000000';
#
# Initial Logic ...
#

foreach ($this->DS as $KEY=>$VAL) {

        $maximum  = "";
        $minimum  = "";
        $critical = "";
        $crit_min = "";
        $crit_max = "";
        $warning  = "";
        $warn_max = "";
        $warn_min = "";
        $vlabel   = " ";
        $lower    = "";
        $upper    = "";

        if ($VAL['WARN'] != "" && is_numeric($VAL['WARN']) ){
                $warning = $VAL['WARN'];
        }
        if ($VAL['WARN_MAX'] != "" && is_numeric($VAL['WARN_MAX']) ) {
                $warn_max = $VAL['WARN_MAX'];
        }
        if ( $VAL['WARN_MIN'] != "" && is_numeric($VAL['WARN_MIN']) ) {
                $warn_min = $VAL['WARN_MIN'];
        }
        if ( $VAL['CRIT'] != "" && is_numeric($VAL['CRIT']) ) {
                $critical = $VAL['CRIT'];
        }
        if ( $VAL['CRIT_MAX'] != "" && is_numeric($VAL['CRIT_MAX']) ) {
                $crit_max = $VAL['CRIT_MAX'];
        }
        if ( $VAL['CRIT_MIN'] != "" && is_numeric($VAL['CRIT_MIN']) ) {
                $crit_min = $VAL['CRIT_MIN'];
        }
        if ( $VAL['MIN'] != "" && is_numeric($VAL['MIN']) ) {
                $lower = " --lower=" . $VAL['MIN'];
                $minimum = $VAL['MIN'];
        }
        if ( $VAL['MAX'] != "" && is_numeric($VAL['MAX']) ) {
                $maximum = $VAL['MAX'];
 }
        if ( $VAL['CRIT'] != "" && is_numeric($VAL['CRIT']) ) {
                $critical = $VAL['CRIT'];
        }
        if ( $VAL['CRIT_MAX'] != "" && is_numeric($VAL['CRIT_MAX']) ) {
                $crit_max = $VAL['CRIT_MAX'];
        }
        if ( $VAL['CRIT_MIN'] != "" && is_numeric($VAL['CRIT_MIN']) ) {
                $crit_min = $VAL['CRIT_MIN'];
        }
        if ( $VAL['MIN'] != "" && is_numeric($VAL['MIN']) ) {
                $lower = " --lower=" . $VAL['MIN'];
                $minimum = $VAL['MIN'];
        }
        if ( $VAL['MAX'] != "" && is_numeric($VAL['MAX']) ) {
                $maximum = $VAL['MAX'];
        }
        if ($VAL['UNIT'] == "%%") {
                $vlabel = "%";
                $upper = " --upper=101 ";
                $lower = " --lower=0 ";
        }
        else {
                $vlabel = $VAL['UNIT'];
        }

        $opt[$KEY] = '--vertical-label "' . $vlabel . '" --title "' . $this->MACRO['DISP_HOSTNAME'] . ' / ' . $this->MACRO['DISP_SERVICEDESC'] . '"' . $upper . $lower;
        $ds_name[$KEY] = $VAL['LABEL'];
        $def[$KEY]  = rrd::def     ("var1", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
        $def[$KEY] .= rrd::gradient("var1", "3152A5", "BDC6DE", rrd::cut($VAL['NAME'],16), 20);
        $def[$KEY] .= rrd::line1   ("var1", $_LINE );
        $def[$KEY] .= rrd::gprint  ("var1", array("LAST","MAX","AVERAGE"), "%3.4lf %S".$VAL['UNIT']);
        if ($warning != "") {
                $def[$KEY] .= rrd::hrule($warning, $_WARNRULE, "Warning  $warning \\n");
        }
        if ($warn_min != "") {
                $def[$KEY] .= rrd::hrule($warn_min, $_WARNRULE, "Warning  (min)  $warn_min \\n");
        }
        if ($warn_max != "") {
                $def[$KEY] .= rrd::hrule($warn_max, $_WARNRULE, "Warning  (max)  $warn_max \\n");
        }
        if ($critical != "") {
                $def[$KEY] .= rrd::hrule($critical, $_CRITRULE, "Critical $critical \\n");
        }
        if ($crit_min != "") {
                $def[$KEY] .= rrd::hrule($crit_min, $_CRITRULE, "Critical (min)  $crit_min \\n");
        }
        if ($crit_max != "") {
                $def[$KEY] .= rrd::hrule($crit_max, $_CRITRULE, "Critical (max)  $crit_max \\n");
        }
        $def[$KEY] .= rrd::comment("Default Template\\r");
        $def[$KEY] .= rrd::comment("Command " . $VAL['TEMPLATE'] . "\\r");
}
?>

Re: pnp4nagios 0.6.25 BULK Mode with NPCD

Posted: Sat Nov 14, 2015 11:37 am
by jrdalrymple
Pikmin wrote: is it possible that pnp4nagios just thinks 11250000.000000 B/s are actually KB/s
pnp4nagios knows what a kilo, mega, and a giga are. pnp4nagios (and nagios/nagios plugins) have non idea what a byte, a hertz, a second, a degree, a widget, etc are.

https://nagios-plugins.org/doc/guidelines.html#AEN200
'label'=value[UOM];[warn];[crit];[min];[max]
For example:

'my measurement'=123456furlongs/fortnight;234567;345678;456789;567890

When pnp4nagios graphs that using the default template, "my measurement" will be in the legend, time will be on the x-axis, furlongs/fortnight will be the y-axis title, the value will be 123k.

If instead I'd done this:

'my measurement'=123kilofurlongs/fortnight;235;346;457;568

When pnp4nagios graphs this output using the default template, "my measurement" will still be in the legend, time will still be on the x-axis, kilofurlongs/fortnight will be the y-axis title, the value will be 123.

It is best to leave units out of your plugin. Let it output the bare scalar without multipliers in the perfdata specifically; the status output is irrelevant and should be prettied up for your eyes.

It looks like check_mrtgtraf has no options to make the output perfdata barren of multipliers as I suggested, honestly as I read the check_mrtgtraf published on the exchange I don't even see where perfdata is assembled. It looks like about 80% of that plugin is code specifically intent on doing exactly what I'm suggesting it NOT do :)

Not a solution, but hopefully you're better able to understand the problem? The solution lies in getting your plugin to stop trying to be so smart for you.

Re: pnp4nagios 0.6.25 BULK Mode with NPCD

Posted: Sun Nov 15, 2015 8:09 pm
by Box293
I cover templates in my talk at the Nagios World Conference:

https://www.youtube.com/watch?v=kqA2KcpUFg4
http://www.slideshare.net/nagiosinc/tro ... and-graphs

The warning and critical values are going to be coming from the XML file (it has the same name as the RRD file).

Re: pnp4nagios 0.6.25 BULK Mode with NPCD

Posted: Mon Nov 16, 2015 3:42 pm
by Pikmin
I have watched your video Box293 and it has helped me understand the theory up to a point.

mrtg runs based on the cron job I've set, it will log to /var/www/mrtg.log, my WorkDir is /var/www/mrtg so host/device logs, png and html will be generated there
I read this page to understand the mrtg log format
http://oss.oetiker.ch/mrtg/doc/mrtg-logfile.en.html

I am using check_mrtgtraf nagios plugin, as that's the one I should be using for bandwidth

Usage check_mrtgtraf -F <log_file> -a <AVG | MAX> -w <warning_pair> -c <critical_pair> [-e expire_minutes]

The -a option above gives me the choice of using AVG or MAX

process_perfdata.pl will process the mrtg device logs from /var/www/mrtg/* and create the xml and rrd files in /usr/local/pnp4nagios/var/perfdata/host/*

pnp4nagios will use /usr/local/pnp4nagios/share/templates.dist/default.php to graph the data

jrdalrymple this is where I get lost:

'label'=value[UOM];[warn];[crit];[min];[max]

Can I actually specify the line above somewhere in templates or is that something that pnp4nagios expects the nagios plugin to actually output?

I am pretty sure that the warning and critical values defined in check_mrtgtraf do actually work in nagios, they will trigger when bandwidth goes over the values

Don't know if I should try and find another plugin to graph the data, remove the warning critical from pnp4nagios or somehow adjust the template so these values are read properly but the thing is Box293 said these critical and warning pairs are stored in the xml file which then gets converted to an rrd. process_perfdata.pl is what creates the xml so maybe that's what I should try and modify. My head is going to explode trying to understand it all

Thank you for your help

Re: pnp4nagios 0.6.25 BULK Mode with NPCD

Posted: Mon Nov 16, 2015 6:23 pm
by Box293
Pikmin wrote:jrdalrymple this is where I get lost:

'label'=value[UOM];[warn];[crit];[min];[max]

Can I actually specify the line above somewhere in templates or is that something that pnp4nagios expects the nagios plugin to actually output?
check_mrtgtraf is outputting the data in that format, for example here it is:

Code: Select all

in=166.028320KB/s;11250000.000000;11875000.000000;0.000000 out=89.237305KB/s;11250000.000000;11875000.00
So there are two datasources here: in (ds1) and out (ds2).

So your check_command is called check_local_mrtgtraf and you need to have a php file called check_local_mrtgtraf.php which will allow pnp4nagios to use this as a template.

Looking at a default template:

Code: Select all

foreach ($DS as $i) {

        $maximum = "";
        $minimum = "";
        $critical = "";
        $warning = "";
        $vlabel = "";

        if ($WARN[$i] != "") {
                $warning = $WARN[$i];
        }
        if ($CRIT[$i] != "") {
                $critical = $CRIT[$i];
        }
        if ($MIN[$i] != "") {
                $lower = " --lower=" . $MIN[$i];
                $minimum = $MIN[$i];
        }
        if ($MAX[$i] != "") {
                $upper = " --upper=" . $MAX[$i];
                $maximum = $MAX[$i];
        }
This line: foreach ($DS as $i) { is looping though each datasource in the xml/rrd files.

This $WARN[$i] is how the warning value is referenced from the XML file.

I'll leave it there for now and see if that has helped. It can get complicated.

Re: pnp4nagios 0.6.25 BULK Mode with NPCD

Posted: Mon Nov 16, 2015 8:43 pm
by Pikmin
Thank you,
What you said all makes sense and I already copied default.php to check_local_mrtgtraf.php
I don't have much of a programming background so php stuff is scary to me. I'm going to have to do a lot of reading to understand it properly. Thanks for pointing out the for statement

My template is a bit different

Code: Select all

<?php
#
# Copyright (c) 2006-2010 Joerg Linge (http://www.pnp4nagios.org)
# Default Template used if no other template is found.
# Don`t delete this file ! 
#
# Define some colors ..
#
$_WARNRULE = '#FFFF00';
$_CRITRULE = '#FF0000';
$_AREA     = '#256aef';
$_LINE     = '#000000';
#
# Initial Logic ...
#

foreach ($this->DS as $KEY=>$VAL) {

	$maximum  = "";
	$minimum  = "";
	$critical = "";
	$crit_min = "";
	$crit_max = "";
	$warning  = "";
	$warn_max = "";
	$warn_min = "";
	$vlabel   = " ";
	$lower    = "";
	$upper    = "";
	
	if ($VAL['WARN'] != "" && is_numeric($VAL['WARN']) ){
		$warning = $VAL['WARN'];
	}
	if ($VAL['WARN_MAX'] != "" && is_numeric($VAL['WARN_MAX']) ) {
		$warn_max = $VAL['WARN_MAX'];
	}
	if ( $VAL['WARN_MIN'] != "" && is_numeric($VAL['WARN_MIN']) ) {
		$warn_min = $VAL['WARN_MIN'];
	}
	if ( $VAL['CRIT'] != "" && is_numeric($VAL['CRIT']) ) {
		$critical = $VAL['CRIT'];
	}
	if ( $VAL['CRIT_MAX'] != "" && is_numeric($VAL['CRIT_MAX']) ) {
		$crit_max = $VAL['CRIT_MAX'];
	}
	if ( $VAL['CRIT_MIN'] != "" && is_numeric($VAL['CRIT_MIN']) ) {
		$crit_min = $VAL['CRIT_MIN'];
	}
	if ( $VAL['MIN'] != "" && is_numeric($VAL['MIN']) ) {
		$lower = " --lower=" . $VAL['MIN'];
		$minimum = $VAL['MIN'];
	}
	if ( $VAL['MAX'] != "" && is_numeric($VAL['MAX']) ) {
if ( $VAL['CRIT'] != "" && is_numeric($VAL['CRIT']) ) {
		$critical = $VAL['CRIT'];
	}
	if ( $VAL['CRIT_MAX'] != "" && is_numeric($VAL['CRIT_MAX']) ) {
		$crit_max = $VAL['CRIT_MAX'];
	}
	if ( $VAL['CRIT_MIN'] != "" && is_numeric($VAL['CRIT_MIN']) ) {
		$crit_min = $VAL['CRIT_MIN'];
	}
	if ( $VAL['MIN'] != "" && is_numeric($VAL['MIN']) ) {
		$lower = " --lower=" . $VAL['MIN'];
		$minimum = $VAL['MIN'];
	}
	if ( $VAL['MAX'] != "" && is_numeric($VAL['MAX']) ) {
		$maximum = $VAL['MAX'];
	}
	if ($VAL['UNIT'] == "%%") {
		$vlabel = "%";
		$upper = " --upper=101 ";
		$lower = " --lower=0 ";
	}
	else {
		$vlabel = $VAL['UNIT'];
	}

	$opt[$KEY] = '--vertical-label "' . $vlabel . '" --title "' . $this->MACRO['DISP_HOSTNAME'] . ' / ' . $this->MACRO['DISP_SERVICEDESC'] . '"' . $upper . $lower;
	$ds_name[$KEY] = $VAL['LABEL'];
	$def[$KEY]  = rrd::def     ("var1", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
	$def[$KEY] .= rrd::gradient("var1", "3152A5", "BDC6DE", rrd::cut($VAL['NAME'],16), 20);
	$def[$KEY] .= rrd::line1   ("var1", $_LINE );
	$def[$KEY] .= rrd::gprint  ("var1", array("LAST","MAX","AVERAGE"), "%3.4lf %S".$VAL['UNIT']);
	if ($warning != "") {
		$def[$KEY] .= rrd::hrule($warning, $_WARNRULE, "Warning  $warning \\n");
	}
	if ($warn_min != "") {
		$def[$KEY] .= rrd::hrule($warn_min, $_WARNRULE, "Warning  (min)  $warn_min \\n");
	}
	if ($warn_max != "") {
		$def[$KEY] .= rrd::hrule($warn_max, $_WARNRULE, "Warning  (max)  $warn_max \\n");
	}
	if ($critical != "") {
		$def[$KEY] .= rrd::hrule($critical, $_CRITRULE, "Critical $critical \\n");
	}
	if ($crit_min != "") {
		$def[$KEY] .= rrd::hrule($crit_min, $_CRITRULE, "Critical (min)  $crit_min \\n");
	}
	if ($crit_max != "") {
		$def[$KEY] .= rrd::hrule($crit_max, $_CRITRULE, "Critical (max)  $crit_max \\n");
	}
	$def[$KEY] .= rrd::comment("Default Template\\r");
	$def[$KEY] .= rrd::comment("Command " . $VAL['TEMPLATE'] . "\\r");
}
?>
I think I am getting somewhere, basically I've edited the following two lines:

Code: Select all

if ($VAL['WARN'] != "" && is_numeric($VAL['WARN']) ){
                $warning = $VAL['WARN'] / 1000;
        }
	
	if ( $VAL['CRIT'] != "" && is_numeric($VAL['CRIT']) ) {
                $critical = $VAL['CRIT'] / 1000;
Also added KB to

Code: Select all

if ($warning != "") {
                $def[$KEY] .= rrd::hrule($warning, $_WARNRULE, "Warning  $warning KB \\n");
if ($critical != "") {
                $def[$KEY] .= rrd::hrule($critical , $_CRITRULE, "Critical $critical KB\\n");
        }
Appears to be working okay, if I change the critical to divide by 100000 for testing purposes, which equals 118.75 KB I finally see the critical red line. Thank you all for your help, much appreciated