summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-06-09 10:53:22 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2006-06-09 10:53:22 (GMT)
commit4f0eadbd97ead5726b35843537dcce6d585b1164 (patch)
treec0d5e0f66f68e8996f2bbeddb7087103b1ff22ab
parent2c6651034f76e2bccb549a867485f8fabbf07cb1 (diff)
downloadmonitoring-plugin-perl-4f0eadbd97ead5726b35843537dcce6d585b1164.tar.gz
Fixed problems parsing in nagiosgraph
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1423 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--Changes8
-rw-r--r--lib/Nagios/Plugin/Performance.pm17
-rw-r--r--t/Nagios-Plugin-Performance.t10
3 files changed, 24 insertions, 11 deletions
diff --git a/Changes b/Changes
index 9095567..6779851 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,10 @@
1Revision history for Perl extension Nagios::Plugin. 1Revision history for Perl module Nagios::Plugin.
2
30.11 ???
4 - Interface changed for parse_perfstring, returning empty
5 array if not parseable
6 - Fixed problem when parsing nagiosgraph data (linefeed at end
7 of perfdata)
2 8
30.10 8th June 2006 90.10 8th June 2006
4 First release to CPAN 10 First release to CPAN
diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm
index eee1bee..82c1a3b 100644
--- a/lib/Nagios/Plugin/Performance.pm
+++ b/lib/Nagios/Plugin/Performance.pm
@@ -27,7 +27,7 @@ sub _parse {
27 my $class = shift; 27 my $class = shift;
28 my $string = shift; 28 my $string = shift;
29 my $p = $class->new; 29 my $p = $class->new;
30 $string =~ s/^([^=]+)=([\d\.]+)(\w*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)? *//; 30 $string =~ s/^([^=]+)=([\d\.]+)(\w*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?\s*//;
31 return undef unless ($1 && $2); 31 return undef unless ($1 && $2);
32 $p->label($1); 32 $p->label($1);
33 $p->value($2+0); 33 $p->value($2+0);
@@ -44,10 +44,9 @@ sub parse_perfstring {
44 my $obj; 44 my $obj;
45 while ($perfstring) { 45 while ($perfstring) {
46 ($obj, $perfstring) = $class->_parse($perfstring); 46 ($obj, $perfstring) = $class->_parse($perfstring);
47 return undef unless $obj; 47 return () unless $obj;
48 push @perfs, $obj; 48 push @perfs, $obj;
49 } 49 }
50 return undef unless @perfs;
51 return @perfs; 50 return @perfs;
52} 51}
53 52
@@ -63,9 +62,13 @@ Nagios::Plugin::Performance - Performance information in a perl object
63 use Nagios::Plugin::Performance; 62 use Nagios::Plugin::Performance;
64 63
65 @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); 64 @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448");
66 print "1st label = ", $p[0]->label, $/; 65 if (@p) {
67 print "1st uom = ", $p[0]->uom, $/; 66 print "1st label = ", $p[0]->label, $/;
68 print "2nd crit = ", $p[1]->threshold->critical, $/; 67 print "1st uom = ", $p[0]->uom, $/;
68 print "2nd crit = ", $p[1]->threshold->critical, $/;
69 } else {
70 print "Cannot parse",$/;
71 }
69 72
70=head1 DESCRIPTION 73=head1 DESCRIPTION
71 74
@@ -83,7 +86,7 @@ Once the performance string has been parsed, you can query the label, value, uom
83=item Nagios::Plugin::Performance->parse_perfstring($string) 86=item Nagios::Plugin::Performance->parse_perfstring($string)
84 87
85Returns an array of Nagios::Plugin::Performance objects based on the string entered. 88Returns an array of Nagios::Plugin::Performance objects based on the string entered.
86If there is an error parsing the string, undef is returned. 89If there is an error parsing the string, an empty array is returned.
87 90
88=head1 OBJECT METHODS 91=head1 OBJECT METHODS
89 92
diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t
index 2fe2326..a00b2db 100644
--- a/t/Nagios-Plugin-Performance.t
+++ b/t/Nagios-Plugin-Performance.t
@@ -1,6 +1,6 @@
1 1
2use strict; 2use strict;
3use Test::More tests => 42; 3use Test::More tests => 43;
4BEGIN { use_ok('Nagios::Plugin::Performance') }; 4BEGIN { use_ok('Nagios::Plugin::Performance') };
5 5
6use Nagios::Plugin::Base; 6use Nagios::Plugin::Base;
@@ -21,8 +21,9 @@ cmp_ok( $p[1]->uom, 'eq', "MB", "uom okay");
21cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay"); 21cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay");
22cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay"); 22cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay");
23 23
24ok( ! defined Nagios::Plugin::Performance->parse_perfstring("rubbish"), "Errors correctly"); 24@p = Nagios::Plugin::Performance->parse_perfstring("rubbish");
25ok( ! defined Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); 25ok( ! @p, "Errors correctly");
26ok( ! Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string");
26 27
27@p = Nagios::Plugin::Performance->parse_perfstring( 28@p = Nagios::Plugin::Performance->parse_perfstring(
28 "time=0.001229s;0.000000;0.000000;0.000000;10.000000"); 29 "time=0.001229s;0.000000;0.000000;0.000000;10.000000");
@@ -49,6 +50,9 @@ cmp_ok( $p[0]->uom, "eq", "", "uom empty");
49cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay"); 50cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay");
50cmp_ok( $p[0]->threshold->critical, 'eq', "50", "crit okay"); 51cmp_ok( $p[0]->threshold->critical, 'eq', "50", "crit okay");
51 52
53@p = Nagios::Plugin::Performance->parse_perfstring( "users=4;20;50;0\n" );
54 ok( @p, "parse correctly with linefeed at end (nagiosgraph)");
55
52@p = Nagios::Plugin::Performance->parse_perfstring( 56@p = Nagios::Plugin::Performance->parse_perfstring(
53 "time=0.215300s;5.000000;10.000000;0.000000 size=426B;;;0" ); 57 "time=0.215300s;5.000000;10.000000;0.000000 size=426B;;;0" );
54cmp_ok( $p[0]->label, "eq", "time", "label okay"); 58cmp_ok( $p[0]->label, "eq", "time", "label okay");