summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
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