From 673108c6cd8c84f72db0ddb2997b96cbe28ba5ea Mon Sep 17 00:00:00 2001 From: "tonvoon@users.sourceforge.net" Date: Fri, 5 Jun 2009 17:01:22 +0000 Subject: Fixed parsing when two = signs within the performance data portion diff --git a/Changes b/Changes index a751e2e..1679d1c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl module Nagios::Plugin. +0.33 5th June 2009 + - Fixed infinite loop when invalid performance data with multiple = were present + 0.32 3rd March 2009 - Handle performance data with quotes in the label (thanks to Kang) - Die if default config file is not available and --extra-opts is set diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index bd0d483..98c2896 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.32"; +our $VERSION = "0.33"; sub new { my $class = shift; diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index 165aafa..9a8272a 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.32"; +our $VERSION = "0.33"; our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm index 6b85dc0..9248fea 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Nagios/Plugin/Performance.pm @@ -87,7 +87,14 @@ sub parse_perfstring { # 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); + if (defined $1) { + $obj = $class->_parse($1); + } else { + # This could occur if perfdata was soemthing=value= + # Since this is invalid, we reset the string and continue + $perfstring = ""; + $obj = $class->_parse($perfstring); + } } else { $obj = $class->_parse($perfstring); $perfstring = ""; diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t index bbf0b20..6904f4c 100644 --- a/t/Nagios-Plugin-Performance.t +++ b/t/Nagios-Plugin-Performance.t @@ -1,4 +1,5 @@ +use warnings; use strict; use Test::More; use Nagios::Plugin::Functions; @@ -40,7 +41,7 @@ my @test = ( }, ); -plan tests => (11 * scalar @test) + 175; +plan tests => (11 * scalar @test) + 176; use_ok('Nagios::Plugin::Performance'); diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; @@ -349,4 +350,7 @@ is( $p[2]->min, undef, "min ok"); is( $p[2]->max, undef, "max ok"); +@p = Nagios::Plugin::Performance->parse_perfstring("processes=9;WKFLSV32.exe;9="); +is_deeply( \@p, [], "Fails parsing correctly"); + # add_perfdata tests in t/Nagios-Plugin-01.t -- cgit v0.10-9-g596f