From 67a45638154221708da7f92451143475bdc229ac Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Mon, 5 Jan 2009 22:24:44 +0000 Subject: Check for valid numerical value before returning perfdata object --- lib/Nagios/Plugin.pm | 2 +- lib/Nagios/Plugin/Functions.pm | 2 +- lib/Nagios/Plugin/Performance.pm | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index 2c9099f..b0b053d 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm @@ -25,7 +25,7 @@ our @EXPORT_OK = qw(%ERRORS); # 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; diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index b7348f3..c7e899c 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm @@ -12,7 +12,7 @@ use Params::Validate qw(:types validate); 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); diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm index df591fb..c35653e 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Nagios/Plugin/Performance.pm @@ -35,8 +35,18 @@ sub _parse { 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; -- cgit v1.2.3-74-g34f1