diff options
-rw-r--r-- | Changes | 3 | ||||
-rw-r--r-- | lib/Nagios/Plugin.pm | 2 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 2 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Performance.pm | 12 | ||||
-rw-r--r-- | t/Nagios-Plugin-Performance.t | 8 |
5 files changed, 23 insertions, 4 deletions
@@ -1,5 +1,8 @@ | |||
1 | Revision history for Perl module Nagios::Plugin. | 1 | Revision history for Perl module Nagios::Plugin. |
2 | 2 | ||
3 | 0.31 5th January 2009 | ||
4 | - Check for valid numerical value before returning perfdata object | ||
5 | |||
3 | 0.30 13th December 2008 | 6 | 0.30 13th December 2008 |
4 | - Fixed performance parsing when numeric fields had commas instead of periods due to locale settings | 7 | - Fixed performance parsing when numeric fields had commas instead of periods due to locale settings |
5 | - If a performance set is not parseable, instead of returning an empty array, will return all the successfully | 8 | - If a performance set is not parseable, instead of returning an empty array, will return all the successfully |
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); | |||
25 | # CPAN stupidly won't index this module without a literal $VERSION here, | 25 | # CPAN stupidly won't index this module without a literal $VERSION here, |
26 | # so we're forced to duplicate it explicitly | 26 | # so we're forced to duplicate it explicitly |
27 | # Make sure you update $Nagios::Plugin::Functions::VERSION too | 27 | # Make sure you update $Nagios::Plugin::Functions::VERSION too |
28 | our $VERSION = "0.30"; | 28 | our $VERSION = "0.31"; |
29 | 29 | ||
30 | sub new { | 30 | sub new { |
31 | my $class = shift; | 31 | 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); | |||
12 | use Math::Calc::Units; | 12 | use Math::Calc::Units; |
13 | 13 | ||
14 | # Remember to update Nagios::Plugins as well | 14 | # Remember to update Nagios::Plugins as well |
15 | our $VERSION = "0.30"; | 15 | our $VERSION = "0.31"; |
16 | 16 | ||
17 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); | 17 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); |
18 | 18 | ||
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 { | |||
35 | my @info = ($1, $2, $3, $4, $5, $6, $7); | 35 | my @info = ($1, $2, $3, $4, $5, $6, $7); |
36 | # We convert any commas to periods, in the value fields | 36 | # We convert any commas to periods, in the value fields |
37 | map { defined $info[$_] && $info[$_] =~ s/,/./go } (1, 3, 4, 5, 6); | 37 | map { defined $info[$_] && $info[$_] =~ s/,/./go } (1, 3, 4, 5, 6); |
38 | |||
39 | # Check that $info[1] is an actual value | ||
40 | # We do this by returning undef if a warning appears | ||
41 | my $performance_value; | ||
42 | { | ||
43 | my $not_value; | ||
44 | local $SIG{__WARN__} = sub { $not_value++ }; | ||
45 | $performance_value = $info[1]+0; | ||
46 | return undef if $not_value; | ||
47 | } | ||
38 | my $p = $class->new( | 48 | my $p = $class->new( |
39 | label => $info[0], value => $info[1]+0, uom => $info[2], warning => $info[3], critical => $info[4], | 49 | label => $info[0], value => $performance_value, uom => $info[2], warning => $info[3], critical => $info[4], |
40 | min => $info[5], max => $info[6] | 50 | min => $info[5], max => $info[6] |
41 | ); | 51 | ); |
42 | return $p; | 52 | return $p; |
diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t index e3fac07..8426828 100644 --- a/t/Nagios-Plugin-Performance.t +++ b/t/Nagios-Plugin-Performance.t | |||
@@ -16,7 +16,7 @@ my @test = ( | |||
16 | }, | 16 | }, |
17 | ); | 17 | ); |
18 | 18 | ||
19 | plan tests => (8 * scalar @test) + 132; | 19 | plan tests => (8 * scalar @test) + 135; |
20 | 20 | ||
21 | use_ok('Nagios::Plugin::Performance'); | 21 | use_ok('Nagios::Plugin::Performance'); |
22 | diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; | 22 | diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; |
@@ -250,4 +250,10 @@ is( $p[0]->threshold->warning, 60, "warn okay"); | |||
250 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | 250 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); |
251 | is( $p[0]->threshold->critical, 120, "warn okay"); | 251 | is( $p[0]->threshold->critical, 120, "warn okay"); |
252 | 252 | ||
253 | # Some values with funny commas | ||
254 | @p = Nagios::Plugin::Performance->parse_perfstring("time=1800,600,300,0,3600 other=45.6"); | ||
255 | is( $p[0]->label, "other", "Ignored time=1800,600,300,0,3600, but allowed other=45.6"); | ||
256 | is( $p[0]->value, 45.6, "value okay"); | ||
257 | is( $p[0]->uom, "", "uom okay"); | ||
258 | |||
253 | # add_perfdata tests in t/Nagios-Plugin-01.t | 259 | # add_perfdata tests in t/Nagios-Plugin-01.t |