diff options
author | Ton Voon <tonvoon@macbook.local> | 2008-12-13 14:05:22 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@macbook.local> | 2008-12-13 14:05:22 +0000 |
commit | 7f33b6abe3b5e9ee14de2683f9412ac6641a2fcd (patch) | |
tree | 3fb9fad68782a1ecdf7ce1814a6b36ffa035145a /lib | |
parent | 0907cdbca2ebcb775a0bbcae639e378e440cd738 (diff) | |
download | monitoring-plugin-perl-7f33b6abe3b5e9ee14de2683f9412ac6641a2fcd.tar.gz |
Fixed parsing of numeric values with commas instead of periods. Fixed test plan
for CPAN test failures of 0.29. Change to parse_perfstring to return back
successfully parsed fields, rather than an empty field, when errors seen
Diffstat (limited to 'lib')
-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 | 37 |
3 files changed, 29 insertions, 12 deletions
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index eb3ccdc..2c9099f 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.29"; | 28 | our $VERSION = "0.30"; |
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 ffa23f0..b7348f3 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.29"; | 15 | our $VERSION = "0.30"; |
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 a9f9198..df591fb 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Nagios/Plugin/Performance.pm | |||
@@ -11,7 +11,7 @@ __PACKAGE__->mk_ro_accessors( | |||
11 | qw(label value uom warning critical min max) | 11 | qw(label value uom warning critical min max) |
12 | ); | 12 | ); |
13 | 13 | ||
14 | use Nagios::Plugin::Functions qw($value_re); | 14 | use Nagios::Plugin::Functions; |
15 | use Nagios::Plugin::Threshold; | 15 | use Nagios::Plugin::Threshold; |
16 | use Nagios::Plugin::Range; | 16 | use Nagios::Plugin::Range; |
17 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; | 17 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; |
@@ -22,17 +22,24 @@ sub import { | |||
22 | Nagios::Plugin::Functions::_use_die($_); | 22 | Nagios::Plugin::Functions::_use_die($_); |
23 | } | 23 | } |
24 | 24 | ||
25 | # This is NOT the same as N::P::Functions::value_re. We leave that to be the strict | ||
26 | # version. This one allows commas to be part of the numeric value. | ||
27 | my $value = qr/[-+]?[\d\.,]+/; | ||
28 | my $value_re = qr/$value(?:e$value)?/; | ||
25 | my $value_with_negative_infinity = qr/$value_re|~/; | 29 | my $value_with_negative_infinity = qr/$value_re|~/; |
26 | sub _parse { | 30 | sub _parse { |
27 | my $class = shift; | 31 | my $class = shift; |
28 | my $string = shift; | 32 | my $string = shift; |
29 | $string =~ s/^([^=]+)=($value_re)([\w%]*);?($value_with_negative_infinity\:?$value_re?)?;?($value_with_negative_infinity\:?$value_re?)?;?($value_re)?;?($value_re)?\s*//o; | 33 | $string =~ /^([^=]+)=($value_re)([\w%]*);?($value_with_negative_infinity\:?$value_re?)?;?($value_with_negative_infinity\:?$value_re?)?;?($value_re)?;?($value_re)?/o; |
30 | return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne "")); | 34 | return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne "")); |
35 | my @info = ($1, $2, $3, $4, $5, $6, $7); | ||
36 | # We convert any commas to periods, in the value fields | ||
37 | map { defined $info[$_] && $info[$_] =~ s/,/./go } (1, 3, 4, 5, 6); | ||
31 | my $p = $class->new( | 38 | my $p = $class->new( |
32 | label => $1, value => $2+0, uom => $3, warning => $4, critical => $5, | 39 | label => $info[0], value => $info[1]+0, uom => $info[2], warning => $info[3], critical => $info[4], |
33 | min => $6, max => $7 | 40 | min => $info[5], max => $info[6] |
34 | ); | 41 | ); |
35 | return ($p, $string); | 42 | return $p; |
36 | } | 43 | } |
37 | 44 | ||
38 | # Map undef to '' | 45 | # Map undef to '' |
@@ -58,12 +65,18 @@ sub perfoutput { | |||
58 | 65 | ||
59 | sub parse_perfstring { | 66 | sub parse_perfstring { |
60 | my ($class, $perfstring) = @_; | 67 | my ($class, $perfstring) = @_; |
61 | my @perfs; | 68 | my @perfs = (); |
62 | my $obj; | 69 | my $obj; |
63 | while ($perfstring) { | 70 | while ($perfstring) { |
64 | ($obj, $perfstring) = $class->_parse($perfstring); | 71 | $perfstring =~ s/^\s*//; |
65 | return () unless $obj; | 72 | if ($perfstring =~ /\s/) { |
66 | push @perfs, $obj; | 73 | $perfstring =~ s/^(.*?)\s//; |
74 | $obj = $class->_parse($1); | ||
75 | } else { | ||
76 | $obj = $class->_parse($perfstring); | ||
77 | $perfstring = ""; | ||
78 | } | ||
79 | push @perfs, $obj if $obj; | ||
67 | } | 80 | } |
68 | return @perfs; | 81 | return @perfs; |
69 | } | 82 | } |
@@ -193,7 +206,11 @@ attributes. | |||
193 | =item Nagios::Plugin::Performance->parse_perfstring($string) | 206 | =item Nagios::Plugin::Performance->parse_perfstring($string) |
194 | 207 | ||
195 | Returns an array of Nagios::Plugin::Performance objects based on the string | 208 | Returns an array of Nagios::Plugin::Performance objects based on the string |
196 | entered. If there is an error parsing the string, an empty array is returned. | 209 | entered. If there is an error parsing the string - which may consists of several |
210 | sets of data - will return an array with all the successfully parsed sets. | ||
211 | |||
212 | If values are input with commas instead of periods, due to different locale settings, | ||
213 | then it will still be parsed, but the commas will be converted to periods. | ||
197 | 214 | ||
198 | =back | 215 | =back |
199 | 216 | ||