summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-06-15 08:38:18 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2006-06-15 08:38:18 (GMT)
commite736a3c2b0a62707f12cf66fbb65ef23eeb01dd6 (patch)
treef8e4dd361b74480752ff7dda173f1fd7ced1868b /lib
parent3e4062f33b9d0ab7c02053400281eb9a26d54003 (diff)
downloadmonitoring-plugin-perl-e736a3c2b0a62707f12cf66fbb65ef23eeb01dd6.tar.gz
Added rrdlabel method. Fixed parse_perfstring if value=0
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1428 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib')
-rw-r--r--lib/Nagios/Plugin.pm2
-rw-r--r--lib/Nagios/Plugin/Performance.pm24
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm
index ed2e6f5..2acc6ea 100644
--- a/lib/Nagios/Plugin.pm
+++ b/lib/Nagios/Plugin.pm
@@ -23,7 +23,7 @@ use Exporter;
23our @ISA = qw(Exporter Nagios::__::Plugin); 23our @ISA = qw(Exporter Nagios::__::Plugin);
24our @EXPORT_OK = qw(%ERRORS); 24our @EXPORT_OK = qw(%ERRORS);
25 25
26our $VERSION = '0.11'; 26our $VERSION = '0.12';
27 27
28sub add_perfdata { 28sub add_perfdata {
29 my ($self, %args) = @_; 29 my ($self, %args) = @_;
diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm
index 82c1a3b..45109ae 100644
--- a/lib/Nagios/Plugin/Performance.pm
+++ b/lib/Nagios/Plugin/Performance.pm
@@ -28,7 +28,7 @@ sub _parse {
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\.]+)?\s*//; 30 $string =~ s/^([^=]+)=([\d\.]+)(\w*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?\s*//;
31 return undef unless ($1 && $2); 31 return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne ""));
32 $p->label($1); 32 $p->label($1);
33 $p->value($2+0); 33 $p->value($2+0);
34 $p->uom($3); 34 $p->uom($3);
@@ -50,6 +50,21 @@ sub parse_perfstring {
50 return @perfs; 50 return @perfs;
51} 51}
52 52
53sub rrdlabel {
54 my $self = shift;
55 my $name = $self->label;
56 if ($name eq "/") {
57 $name = "root";
58 # If filesystem name, remove initial / and convert subsequent "/" to "_"
59 } elsif ($name =~ s/^\///) {
60 $name =~ s/\//_/g;
61 }
62 # Convert bad chars
63 $name =~ s/\W/_/g;
64 # Shorten
65 return substr( $name, 0, 19 );
66}
67
531; 681;
54__END__ 69__END__
55 70
@@ -94,6 +109,13 @@ If there is an error parsing the string, an empty array is returned.
94 109
95These all return scalars. min and max are not well supported yet. 110These all return scalars. min and max are not well supported yet.
96 111
112=item rrdlabel
113
114Returns a label that can be used for the dataset name of an RRD, ie, between 1-19
115characters long with characters [a-zA-Z0-9_].
116
117There is no guarantee that multiple N:P:Performance objects will have unique rrdlabels.
118
97=item threshold 119=item threshold
98 120
99This returns a Nagios::Plugin::Threshold object. 121This returns a Nagios::Plugin::Threshold object.