diff options
-rw-r--r-- | Changes | 3 | ||||
-rw-r--r-- | lib/Nagios/Plugin.pm | 2 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 2 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Performance.pm | 4 | ||||
-rw-r--r-- | t/Nagios-Plugin-Performance.t | 31 |
5 files changed, 38 insertions, 4 deletions
@@ -1,5 +1,8 @@ | |||
1 | Revision history for Perl module Nagios::Plugin. | 1 | Revision history for Perl module Nagios::Plugin. |
2 | 2 | ||
3 | 0.25 17th March 2008 | ||
4 | - Fixed parsing of performance data with negative values and full range definitions | ||
5 | |||
3 | 0.24 1st February 2008 | 6 | 0.24 1st February 2008 |
4 | - Fixed a test failure which highlighted a precision rounding within hashes | 7 | - Fixed a test failure which highlighted a precision rounding within hashes |
5 | 8 | ||
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index b395b68..edcb2c3 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 |
28 | our $VERSION = "0.24"; | 28 | our $VERSION = "0.25"; |
29 | 29 | ||
30 | sub new { | 30 | sub new { |
31 | my $class = shift; | 31 | my $class = shift; |
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index 2638b8d..0f33121 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm | |||
@@ -12,7 +12,7 @@ use Params::Validate qw(:types validate); | |||
12 | use Math::Calc::Units; | 12 | use Math::Calc::Units; |
13 | 13 | ||
14 | # Remember to update Nagios::Plugins as well | 14 | # Remember to update Nagios::Plugins as well |
15 | our $VERSION = "0.24"; | 15 | our $VERSION = "0.25"; |
16 | 16 | ||
17 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); | 17 | our @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 55e3ddc..403492c 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Nagios/Plugin/Performance.pm | |||
@@ -22,10 +22,12 @@ sub import { | |||
22 | Nagios::Plugin::Functions::_use_die($_); | 22 | Nagios::Plugin::Functions::_use_die($_); |
23 | } | 23 | } |
24 | 24 | ||
25 | my $value_re = qr/[-+]?[\d\.]+/; | ||
26 | my $value_re_with_negative_infinity = qr/$value_re|~/; | ||
25 | sub _parse { | 27 | sub _parse { |
26 | my $class = shift; | 28 | my $class = shift; |
27 | my $string = shift; | 29 | my $string = shift; |
28 | $string =~ s/^([^=]+)=([\d\.]+)([\w%]*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?\s*//; | 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 | return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne "")); | 31 | return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne "")); |
30 | my $p = $class->new( | 32 | my $p = $class->new( |
31 | label => $1, value => $2+0, uom => $3, warning => $4, critical => $5, | 33 | label => $1, value => $2+0, uom => $3, warning => $4, critical => $5, |
diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t index 0574ea0..7a28546 100644 --- a/t/Nagios-Plugin-Performance.t +++ b/t/Nagios-Plugin-Performance.t | |||
@@ -1,6 +1,6 @@ | |||
1 | 1 | ||
2 | use strict; | 2 | use strict; |
3 | use Test::More tests => 91; | 3 | use Test::More tests => 111; |
4 | BEGIN { use_ok('Nagios::Plugin::Performance') }; | 4 | BEGIN { use_ok('Nagios::Plugin::Performance') }; |
5 | 5 | ||
6 | diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; | 6 | diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; |
@@ -142,4 +142,33 @@ cmp_ok( $p[0]->uom, "eq", "%", "uom okay"); | |||
142 | cmp_ok( $p[0]->threshold->warning, 'eq', "90", "warn okay"); | 142 | cmp_ok( $p[0]->threshold->warning, 'eq', "90", "warn okay"); |
143 | cmp_ok( $p[0]->threshold->critical, 'eq', "95", "crit okay"); | 143 | cmp_ok( $p[0]->threshold->critical, 'eq', "95", "crit okay"); |
144 | 144 | ||
145 | # Check ranges are parsed correctly | ||
146 | @p = Nagios::Plugin::Performance->parse_perfstring("availability=93.8%;90:99;"); | ||
147 | is( $p[0]->label, "availability", "label okay"); | ||
148 | is( $p[0]->value, "93.8", "value okay"); | ||
149 | is( $p[0]->uom, "%", "uom okay"); | ||
150 | ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set"); | ||
151 | is( $p[0]->threshold->critical->is_set, 0, "Critical range has not been set"); | ||
152 | is( $p[0]->threshold->warning, "90:99", "warn okay"); | ||
153 | |||
154 | # Check that negative values are parsed correctly in value and ranges | ||
155 | @p = Nagios::Plugin::Performance->parse_perfstring("offset=-0.004476s;-60.000000:-5;-120.000000:-3;"); | ||
156 | is( $p[0]->label, "offset", "label okay"); | ||
157 | is( $p[0]->value, "-0.004476", "value okay"); | ||
158 | is( $p[0]->uom, "s", "uom okay"); | ||
159 | ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set"); | ||
160 | ok( defined eval { $p[0]->threshold->critical->is_set }, "Critical range has been set"); | ||
161 | is( $p[0]->threshold->warning, "-60:-5", "warn okay"); | ||
162 | is( $p[0]->threshold->critical, "-120:-3", "crit okay"); | ||
163 | |||
164 | # Check infinity values are okay | ||
165 | @p = Nagios::Plugin::Performance->parse_perfstring("salary=52GBP;~:23;45:"); | ||
166 | is( $p[0]->label, "salary", "label okay"); | ||
167 | is( $p[0]->value, "52", "value okay"); | ||
168 | is( $p[0]->uom, "GBP", "uom okay"); | ||
169 | ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set"); | ||
170 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
171 | is( $p[0]->threshold->warning, "~:23", "warn okay"); | ||
172 | is( $p[0]->threshold->critical, "45:", "warn okay"); | ||
173 | |||
145 | # add_perfdata tests in t/Nagios-Plugin-01.t | 174 | # add_perfdata tests in t/Nagios-Plugin-01.t |