summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Nagios/Plugin.pm2
-rw-r--r--lib/Nagios/Plugin/Functions.pm2
-rw-r--r--lib/Nagios/Plugin/Performance.pm37
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
28our $VERSION = "0.29"; 28our $VERSION = "0.30";
29 29
30sub new { 30sub 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);
12use Math::Calc::Units; 12use Math::Calc::Units;
13 13
14# Remember to update Nagios::Plugins as well 14# Remember to update Nagios::Plugins as well
15our $VERSION = "0.29"; 15our $VERSION = "0.30";
16 16
17our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); 17our @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
14use Nagios::Plugin::Functions qw($value_re); 14use Nagios::Plugin::Functions;
15use Nagios::Plugin::Threshold; 15use Nagios::Plugin::Threshold;
16use Nagios::Plugin::Range; 16use Nagios::Plugin::Range;
17our ($VERSION) = $Nagios::Plugin::Functions::VERSION; 17our ($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.
27my $value = qr/[-+]?[\d\.,]+/;
28my $value_re = qr/$value(?:e$value)?/;
25my $value_with_negative_infinity = qr/$value_re|~/; 29my $value_with_negative_infinity = qr/$value_re|~/;
26sub _parse { 30sub _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
59sub parse_perfstring { 66sub 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
195Returns an array of Nagios::Plugin::Performance objects based on the string 208Returns an array of Nagios::Plugin::Performance objects based on the string
196entered. If there is an error parsing the string, an empty array is returned. 209entered. If there is an error parsing the string - which may consists of several
210sets of data - will return an array with all the successfully parsed sets.
211
212If values are input with commas instead of periods, due to different locale settings,
213then it will still be parsed, but the commas will be converted to periods.
197 214
198=back 215=back
199 216