From c47e1a9c28db2890f724ee57e59f3a3c30d7740c Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Wed, 14 May 2008 11:19:53 +0000 Subject: Fixed parsing of scientific notation git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1993 f882894a-f735-0410-b71e-b25c423dba1c --- lib/Nagios/Plugin/Functions.pm | 7 +++++-- lib/Nagios/Plugin/Performance.pm | 7 +++---- lib/Nagios/Plugin/Range.pm | 10 +++++----- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'lib/Nagios/Plugin') diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index 57c5b08..a37cdaf 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm @@ -12,14 +12,14 @@ use Params::Validate qw(:types validate); use Math::Calc::Units; # Remember to update Nagios::Plugins as well -our $VERSION = "0.26"; +our $VERSION = "0.27"; our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); require Exporter; our @ISA = qw(Exporter); our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); -our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state convert); +our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state convert $value_re); our %EXPORT_TAGS = ( all => [ @EXPORT, @EXPORT_OK ], codes => [ @STATUS_CODES ], @@ -42,6 +42,9 @@ our %ERRORS = ( our %STATUS_TEXT = reverse %ERRORS; +my $value = qr/[-+]?[\d\.]+/; +our $value_re = qr/$value(?:e$value)?/; + # _fake_exit flag and accessor/mutator, for testing my $_fake_exit = 0; sub _fake_exit { @_ ? $_fake_exit = shift : $_fake_exit }; diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm index 403492c..a7655fc 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Nagios/Plugin/Performance.pm @@ -11,7 +11,7 @@ __PACKAGE__->mk_ro_accessors( qw(label value uom warning critical min max) ); -use Nagios::Plugin::Functions; +use Nagios::Plugin::Functions qw($value_re); use Nagios::Plugin::Threshold; use Nagios::Plugin::Range; our ($VERSION) = $Nagios::Plugin::Functions::VERSION; @@ -22,12 +22,11 @@ sub import { Nagios::Plugin::Functions::_use_die($_); } -my $value_re = qr/[-+]?[\d\.]+/; -my $value_re_with_negative_infinity = qr/$value_re|~/; +my $value_with_negative_infinity = qr/$value_re|~/; sub _parse { my $class = shift; my $string = shift; - $string =~ s/^([^=]+)=($value_re)([\w%]*);?($value_re_with_negative_infinity\:?$value_re?)?;?($value_re_with_negative_infinity\:?$value_re?)?;?($value_re)?;?($value_re)?\s*//o; + $string =~ s/^([^=]+)=($value_re)([\w%]*);?($value_with_negative_infinity\:?$value_re?)?;?($value_with_negative_infinity\:?$value_re?)?;?($value_re)?;?($value_re)?\s*//o; return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne "")); my $p = $class->new( label => $1, value => $2+0, uom => $3, warning => $4, critical => $5, diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Nagios/Plugin/Range.pm index 3828d1a..32a0639 100644 --- a/lib/Nagios/Plugin/Range.pm +++ b/lib/Nagios/Plugin/Range.pm @@ -11,7 +11,7 @@ __PACKAGE__->mk_accessors( qw(start end start_infinity end_infinity alert_on) ); -use Nagios::Plugin::Functions; +use Nagios::Plugin::Functions qw(:DEFAULT $value_re); our ($VERSION) = $Nagios::Plugin::Functions::VERSION; use overload @@ -54,7 +54,7 @@ sub parse_range_string { $string =~ s/\s//g; # strip out any whitespace # check for valid range definition - unless ( $string =~ /[\d~]/ && $string =~ m/^\@?(-?[\d.]+|~)?(:(-?[\d.]+)?)?$/ ) { + unless ( $string =~ /[\d~]/ && $string =~ m/^\@?($value_re|~)?(:($value_re)?)?$/ ) { carp "invalid range definition '$string'"; return undef; } @@ -66,14 +66,14 @@ sub parse_range_string { if ($string =~ s/^~//) { # '~:x' $range->start_infinity(1); } - if ( $string =~ m/^([\d\.-]+)?:/ ) { # '10:' + if ( $string =~ m/^($value_re)?:/ ) { # '10:' my $start = $1; $range->_set_range_start($start) if defined $start; $range->end_infinity(1); # overridden below if there's an end specified - $string =~ s/^([-\d\.]+)?://; + $string =~ s/^($value_re)?://; $valid++; } - if ($string =~ /^([-\d\.]+)$/) { # 'x:10' or '10' + if ($string =~ /^($value_re)$/) { # 'x:10' or '10' $range->_set_range_end($string); $valid++; } -- cgit v1.2.3-74-g34f1