summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-06-09 10:53:22 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2006-06-09 10:53:22 +0000
commit4f0eadbd97ead5726b35843537dcce6d585b1164 (patch)
treec0d5e0f66f68e8996f2bbeddb7087103b1ff22ab /lib
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
Diffstat (limited to 'lib')
-rw-r--r--lib/Nagios/Plugin/Performance.pm17
1 files changed, 10 insertions, 7 deletions
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