Revision: 2114
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2114&view=rev
Author: dermoth
Date: 2009-01-05 22:26:56 +0000 (Mon, 05 Jan 2009)
Log Message:
-----------
Check for valid numerical value before returning perfdata object
Modified Paths:
--------------
Nagios-Plugin/trunk/Changes
Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm
Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm
Nagios-Plugin/trunk/lib/Nagios/Plugin.pm
Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t
Modified: Nagios-Plugin/trunk/Changes
===================================================================
--- Nagios-Plugin/trunk/Changes 2009-01-05 22:26:23 UTC (rev 2113)
+++ Nagios-Plugin/trunk/Changes 2009-01-05 22:26:56 UTC (rev 2114)
@@ -1,5 +1,8 @@
Revision history for Perl module Nagios::Plugin.
+0.31 5th January 2009
+ - Check for valid numerical value before returning perfdata object
+
0.30 13th December 2008
- Fixed performance parsing when numeric fields had commas instead of periods due to locale settings
- If a performance set is not parseable, instead of returning an empty array, will return all the successfully
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm 2009-01-05 22:26:23 UTC (rev 2113)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm 2009-01-05 22:26:56 UTC (rev 2114)
@@ -12,7 +12,7 @@
use Math::Calc::Units;
# Remember to update Nagios::Plugins as well
-our $VERSION = "0.30";
+our $VERSION = "0.31";
our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT);
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm 2009-01-05 22:26:23 UTC (rev 2113)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm 2009-01-05 22:26:56 UTC (rev 2114)
@@ -35,8 +35,18 @@
my @info = ($1, $2, $3, $4, $5, $6, $7);
# We convert any commas to periods, in the value fields
map { defined $info[$_] && $info[$_] =~ s/,/./go } (1, 3, 4, 5, 6);
+
+ # Check that $info[1] is an actual value
+ # We do this by returning undef if a warning appears
+ my $performance_value;
+ {
+ my $not_value;
+ local $SIG{__WARN__} = sub { $not_value++ };
+ $performance_value = $info[1]+0;
+ return undef if $not_value;
+ }
my $p = $class->new(
- label => $info[0], value => $info[1]+0, uom => $info[2], warning => $info[3], critical => $info[4],
+ label => $info[0], value => $performance_value, uom => $info[2], warning => $info[3], critical => $info[4],
min => $info[5], max => $info[6]
);
return $p;
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin.pm 2009-01-05 22:26:23 UTC (rev 2113)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin.pm 2009-01-05 22:26:56 UTC (rev 2114)
@@ -25,7 +25,7 @@
# CPAN stupidly won't index this module without a literal $VERSION here,
# so we're forced to duplicate it explicitly
# Make sure you update $Nagios::Plugin::Functions::VERSION too
-our $VERSION = "0.30";
+our $VERSION = "0.31";
sub new {
my $class = shift;
Modified: Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t
===================================================================
--- Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t 2009-01-05 22:26:23 UTC (rev 2113)
+++ Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t 2009-01-05 22:26:56 UTC (rev 2114)
@@ -16,7 +16,7 @@
},
);
-plan tests => (8 * scalar @test) + 132;
+plan tests => (8 * scalar @test) + 135;
use_ok('Nagios::Plugin::Performance');
diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
@@ -250,4 +250,10 @@
is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set");
is( $p[0]->threshold->critical, 120, "warn okay");
+# Some values with funny commas
+@p = Nagios::Plugin::Performance->parse_perfstring("time=1800,600,300,0,3600 other=45.6");
+is( $p[0]->label, "other", "Ignored time=1800,600,300,0,3600, but allowed other=45.6");
+is( $p[0]->value, 45.6, "value okay");
+is( $p[0]->uom, "", "uom okay");
+
# add_perfdata tests in t/Nagios-Plugin-01.t
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
------------------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.