[Nagiosplug-checkins] SF.net SVN: nagiosplug: [1952] Nagios-Plugin/trunk
tonvoon at users.sourceforge.net
tonvoon at users.sourceforge.net
Mon Mar 17 21:32:11 CET 2008
Revision: 1952
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1952&view=rev
Author: tonvoon
Date: 2008-03-17 13:32:11 -0700 (Mon, 17 Mar 2008)
Log Message:
-----------
Fixed parsing of negative values and support full range definitions
Modified Paths:
--------------
Nagios-Plugin/trunk/Changes
Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm
Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm
Nagios-Plugin/trunk/lib/Nagios/Plugin.pm
Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t
Modified: Nagios-Plugin/trunk/Changes
===================================================================
--- Nagios-Plugin/trunk/Changes 2008-03-16 18:10:47 UTC (rev 1951)
+++ Nagios-Plugin/trunk/Changes 2008-03-17 20:32:11 UTC (rev 1952)
@@ -1,5 +1,8 @@
Revision history for Perl module Nagios::Plugin.
+0.25 17th March 2008
+ - Fixed parsing of performance data with negative values and full range definitions
+
0.24 1st February 2008
- Fixed a test failure which highlighted a precision rounding within hashes
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm 2008-03-16 18:10:47 UTC (rev 1951)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm 2008-03-17 20:32:11 UTC (rev 1952)
@@ -12,7 +12,7 @@
use Math::Calc::Units;
# Remember to update Nagios::Plugins as well
-our $VERSION = "0.24";
+our $VERSION = "0.25";
our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT);
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm 2008-03-16 18:10:47 UTC (rev 1951)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm 2008-03-17 20:32:11 UTC (rev 1952)
@@ -22,10 +22,12 @@
Nagios::Plugin::Functions::_use_die($_);
}
+my $value_re = qr/[-+]?[\d\.]+/;
+my $value_re_with_negative_infinity = qr/$value_re|~/;
sub _parse {
my $class = shift;
my $string = shift;
- $string =~ s/^([^=]+)=([\d\.]+)([\w%]*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?\s*//;
+ $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;
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,
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin.pm 2008-03-16 18:10:47 UTC (rev 1951)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin.pm 2008-03-17 20:32:11 UTC (rev 1952)
@@ -25,7 +25,7 @@
# 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.24";
+our $VERSION = "0.25";
sub new {
my $class = shift;
Modified: Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t
===================================================================
--- Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t 2008-03-16 18:10:47 UTC (rev 1951)
+++ Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t 2008-03-17 20:32:11 UTC (rev 1952)
@@ -1,6 +1,6 @@
use strict;
-use Test::More tests => 91;
+use Test::More tests => 111;
BEGIN { use_ok('Nagios::Plugin::Performance') };
diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
@@ -142,4 +142,33 @@
cmp_ok( $p[0]->threshold->warning, 'eq', "90", "warn okay");
cmp_ok( $p[0]->threshold->critical, 'eq', "95", "crit okay");
+# Check ranges are parsed correctly
+ at p = Nagios::Plugin::Performance->parse_perfstring("availability=93.8%;90:99;");
+is( $p[0]->label, "availability", "label okay");
+is( $p[0]->value, "93.8", "value okay");
+is( $p[0]->uom, "%", "uom okay");
+ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set");
+is( $p[0]->threshold->critical->is_set, 0, "Critical range has not been set");
+is( $p[0]->threshold->warning, "90:99", "warn okay");
+
+# Check that negative values are parsed correctly in value and ranges
+ at p = Nagios::Plugin::Performance->parse_perfstring("offset=-0.004476s;-60.000000:-5;-120.000000:-3;");
+is( $p[0]->label, "offset", "label okay");
+is( $p[0]->value, "-0.004476", "value okay");
+is( $p[0]->uom, "s", "uom okay");
+ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set");
+ok( defined eval { $p[0]->threshold->critical->is_set }, "Critical range has been set");
+is( $p[0]->threshold->warning, "-60:-5", "warn okay");
+is( $p[0]->threshold->critical, "-120:-3", "crit okay");
+
+# Check infinity values are okay
+ at p = Nagios::Plugin::Performance->parse_perfstring("salary=52GBP;~:23;45:");
+is( $p[0]->label, "salary", "label okay");
+is( $p[0]->value, "52", "value okay");
+is( $p[0]->uom, "GBP", "uom okay");
+ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set");
+is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set");
+is( $p[0]->threshold->warning, "~:23", "warn okay");
+is( $p[0]->threshold->critical, "45:", "warn okay");
+
# add_perfdata tests in t/Nagios-Plugin-01.t
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list