summaryrefslogtreecommitdiffstats
path: root/lib/Nagios
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2008-05-14 11:19:53 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2008-05-14 11:19:53 +0000
commitc47e1a9c28db2890f724ee57e59f3a3c30d7740c (patch)
tree5648f0b0ff1a1eb2478f75484a26e3fa42e1f455 /lib/Nagios
parent60a00b6e423bfeeca3508398556e180955355079 (diff)
downloadmonitoring-plugin-perl-c47e1a9c28db2890f724ee57e59f3a3c30d7740c.tar.gz
Fixed parsing of scientific notation
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1993 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/Nagios')
-rw-r--r--lib/Nagios/Plugin.pm2
-rw-r--r--lib/Nagios/Plugin/Functions.pm7
-rw-r--r--lib/Nagios/Plugin/Performance.pm7
-rw-r--r--lib/Nagios/Plugin/Range.pm10
4 files changed, 14 insertions, 12 deletions
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm
index 8f3a652..06f313d 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.26"; 28our $VERSION = "0.27";
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 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);
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.26"; 15our $VERSION = "0.27";
16 16
17our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); 17our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT);
18 18
19require Exporter; 19require Exporter;
20our @ISA = qw(Exporter); 20our @ISA = qw(Exporter);
21our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); 21our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages));
22our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state convert); 22our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state convert $value_re);
23our %EXPORT_TAGS = ( 23our %EXPORT_TAGS = (
24 all => [ @EXPORT, @EXPORT_OK ], 24 all => [ @EXPORT, @EXPORT_OK ],
25 codes => [ @STATUS_CODES ], 25 codes => [ @STATUS_CODES ],
@@ -42,6 +42,9 @@ our %ERRORS = (
42 42
43our %STATUS_TEXT = reverse %ERRORS; 43our %STATUS_TEXT = reverse %ERRORS;
44 44
45my $value = qr/[-+]?[\d\.]+/;
46our $value_re = qr/$value(?:e$value)?/;
47
45# _fake_exit flag and accessor/mutator, for testing 48# _fake_exit flag and accessor/mutator, for testing
46my $_fake_exit = 0; 49my $_fake_exit = 0;
47sub _fake_exit { @_ ? $_fake_exit = shift : $_fake_exit }; 50sub _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(
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; 14use Nagios::Plugin::Functions qw($value_re);
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,12 +22,11 @@ sub import {
22 Nagios::Plugin::Functions::_use_die($_); 22 Nagios::Plugin::Functions::_use_die($_);
23} 23}
24 24
25my $value_re = qr/[-+]?[\d\.]+/; 25my $value_with_negative_infinity = qr/$value_re|~/;
26my $value_re_with_negative_infinity = qr/$value_re|~/;
27sub _parse { 26sub _parse {
28 my $class = shift; 27 my $class = shift;
29 my $string = shift; 28 my $string = shift;
30 $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; 29 $string =~ s/^([^=]+)=($value_re)([\w%]*);?($value_with_negative_infinity\:?$value_re?)?;?($value_with_negative_infinity\:?$value_re?)?;?($value_re)?;?($value_re)?\s*//o;
31 return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne "")); 30 return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne ""));
32 my $p = $class->new( 31 my $p = $class->new(
33 label => $1, value => $2+0, uom => $3, warning => $4, critical => $5, 32 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(
11 qw(start end start_infinity end_infinity alert_on) 11 qw(start end start_infinity end_infinity alert_on)
12); 12);
13 13
14use Nagios::Plugin::Functions; 14use Nagios::Plugin::Functions qw(:DEFAULT $value_re);
15our ($VERSION) = $Nagios::Plugin::Functions::VERSION; 15our ($VERSION) = $Nagios::Plugin::Functions::VERSION;
16 16
17use overload 17use overload
@@ -54,7 +54,7 @@ sub parse_range_string {
54 54
55 $string =~ s/\s//g; # strip out any whitespace 55 $string =~ s/\s//g; # strip out any whitespace
56 # check for valid range definition 56 # check for valid range definition
57 unless ( $string =~ /[\d~]/ && $string =~ m/^\@?(-?[\d.]+|~)?(:(-?[\d.]+)?)?$/ ) { 57 unless ( $string =~ /[\d~]/ && $string =~ m/^\@?($value_re|~)?(:($value_re)?)?$/ ) {
58 carp "invalid range definition '$string'"; 58 carp "invalid range definition '$string'";
59 return undef; 59 return undef;
60 } 60 }
@@ -66,14 +66,14 @@ sub parse_range_string {
66 if ($string =~ s/^~//) { # '~:x' 66 if ($string =~ s/^~//) { # '~:x'
67 $range->start_infinity(1); 67 $range->start_infinity(1);
68 } 68 }
69 if ( $string =~ m/^([\d\.-]+)?:/ ) { # '10:' 69 if ( $string =~ m/^($value_re)?:/ ) { # '10:'
70 my $start = $1; 70 my $start = $1;
71 $range->_set_range_start($start) if defined $start; 71 $range->_set_range_start($start) if defined $start;
72 $range->end_infinity(1); # overridden below if there's an end specified 72 $range->end_infinity(1); # overridden below if there's an end specified
73 $string =~ s/^([-\d\.]+)?://; 73 $string =~ s/^($value_re)?://;
74 $valid++; 74 $valid++;
75 } 75 }
76 if ($string =~ /^([-\d\.]+)$/) { # 'x:10' or '10' 76 if ($string =~ /^($value_re)$/) { # 'x:10' or '10'
77 $range->_set_range_end($string); 77 $range->_set_range_end($string);
78 $valid++; 78 $valid++;
79 } 79 }