From b0ff1e4262fa7f09c9cdb91206b6d2a2a1aa06a7 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Tue, 3 Mar 2009 10:36:02 +0000 Subject: Added parsing of labels with spaces (thanks to Kang) --- lib/Nagios/Plugin.pm | 2 +- lib/Nagios/Plugin/Functions.pm | 2 +- lib/Nagios/Plugin/Performance.pm | 14 ++++++++++---- lib/Nagios/Plugin/Threshold.pm | 3 +++ 4 files changed, 15 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index b0b053d..bd0d483 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.31"; +our $VERSION = "0.32"; sub new { my $class = shift; diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index c7e899c..165aafa 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.31"; +our $VERSION = "0.32"; our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm index c35653e..6b85dc0 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Nagios/Plugin/Performance.pm @@ -30,7 +30,7 @@ my $value_with_negative_infinity = qr/$value_re|~/; sub _parse { my $class = shift; my $string = shift; - $string =~ /^([^=]+)=($value_re)([\w%]*);?($value_with_negative_infinity\:?$value_re?)?;?($value_with_negative_infinity\:?$value_re?)?;?($value_re)?;?($value_re)?/o; + $string =~ /^'?([^'=]+)'?=($value_re)([\w%]*);?($value_with_negative_infinity\:?$value_re?)?;?($value_with_negative_infinity\:?$value_re?)?;?($value_re)?;?($value_re)?/o; return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne "")); my @info = ($1, $2, $3, $4, $5, $6, $7); # We convert any commas to periods, in the value fields @@ -60,8 +60,13 @@ sub _nvl { sub perfoutput { my $self = shift; + # Add quotes if label contains a space character + my $label = $self->label; + if ($label =~ / /) { + $label = "'$label'"; + } my $out = sprintf "%s=%s%s;%s;%s;%s;%s", - $self->label, + $label, $self->value, $self->_nvl($self->uom), $self->_nvl($self->warning), @@ -79,8 +84,9 @@ sub parse_perfstring { my $obj; while ($perfstring) { $perfstring =~ s/^\s*//; - if ($perfstring =~ /\s/) { - $perfstring =~ s/^(.*?)\s//; + # If there is more than 1 equals sign, split it out and parse individually + if (@{[$perfstring =~ /=/g]} > 1) { + $perfstring =~ s/^(.*?=.*?)\s//; $obj = $class->_parse($1); } else { $obj = $class->_parse($perfstring); diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm index 145b89f..73fce53 100644 --- a/lib/Nagios/Plugin/Threshold.pm +++ b/lib/Nagios/Plugin/Threshold.pm @@ -39,6 +39,9 @@ sub _inflate return $value; } + # Another quick exit if $value is an empty string + return Nagios::Plugin::Range->new if $value eq ""; + # Otherwise parse $value my $range = Nagios::Plugin::Range->parse_range_string($value); nagios_die("Cannot parse $key range: '$value'") unless(defined($range)); -- cgit v1.2.3-74-g34f1