[Nagiosplug-checkins] Nagios-Plugin/lib/Nagios/Plugin Performance.pm, 1.1.1.1, 1.2

Ton Voon tonvoon at users.sourceforge.net
Fri Jun 9 12:53:24 CEST 2006


Update of /cvsroot/nagiosplug/Nagios-Plugin/lib/Nagios/Plugin
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv19688/lib/Nagios/Plugin

Modified Files:
	Performance.pm 
Log Message:
Fixed problems parsing in nagiosgraph


Index: Performance.pm
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/lib/Nagios/Plugin/Performance.pm,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- Performance.pm	8 Jun 2006 12:27:44 -0000	1.1.1.1
+++ Performance.pm	9 Jun 2006 10:53:22 -0000	1.2
@@ -27,7 +27,7 @@
 	my $class = shift;
 	my $string = shift;
 	my $p = $class->new;
-	$string =~ s/^([^=]+)=([\d\.]+)(\w*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)? *//;
+	$string =~ s/^([^=]+)=([\d\.]+)(\w*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?\s*//;
 	return undef unless ($1 && $2);
 	$p->label($1);
 	$p->value($2+0);
@@ -44,10 +44,9 @@
 	my $obj;
 	while ($perfstring) {
 		($obj, $perfstring) = $class->_parse($perfstring);
-		return undef unless $obj;
+		return () unless $obj;
 		push @perfs, $obj;
 	}
-	return undef unless @perfs;
 	return @perfs;
 }
 
@@ -63,9 +62,13 @@
   use Nagios::Plugin::Performance;
 
   @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448");
-  print "1st label = ", $p[0]->label, $/;
-  print "1st uom   = ", $p[0]->uom, $/;
-  print "2nd crit  = ", $p[1]->threshold->critical, $/;
+  if (@p) {
+	print "1st label = ", $p[0]->label, $/;
+	print "1st uom   = ", $p[0]->uom, $/;
+	print "2nd crit  = ", $p[1]->threshold->critical, $/;
+  } else {
+	print "Cannot parse",$/;
+  }
 
 =head1 DESCRIPTION
 
@@ -83,7 +86,7 @@
 =item Nagios::Plugin::Performance->parse_perfstring($string)
 
 Returns an array of Nagios::Plugin::Performance objects based on the string entered. 
-If there is an error parsing the string, undef is returned.
+If there is an error parsing the string, an empty array is returned.
 
 =head1 OBJECT METHODS
 





More information about the Commits mailing list