From e736a3c2b0a62707f12cf66fbb65ef23eeb01dd6 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Thu, 15 Jun 2006 08:38:18 +0000 Subject: 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 --- lib/Nagios/Plugin.pm | 2 +- lib/Nagios/Plugin/Performance.pm | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'lib') 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; our @ISA = qw(Exporter Nagios::__::Plugin); our @EXPORT_OK = qw(%ERRORS); -our $VERSION = '0.11'; +our $VERSION = '0.12'; sub add_perfdata { 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 { my $string = shift; my $p = $class->new; $string =~ s/^([^=]+)=([\d\.]+)(\w*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?\s*//; - return undef unless ($1 && $2); + return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne "")); $p->label($1); $p->value($2+0); $p->uom($3); @@ -50,6 +50,21 @@ sub parse_perfstring { return @perfs; } +sub rrdlabel { + my $self = shift; + my $name = $self->label; + if ($name eq "/") { + $name = "root"; + # If filesystem name, remove initial / and convert subsequent "/" to "_" + } elsif ($name =~ s/^\///) { + $name =~ s/\//_/g; + } + # Convert bad chars + $name =~ s/\W/_/g; + # Shorten + return substr( $name, 0, 19 ); +} + 1; __END__ @@ -94,6 +109,13 @@ If there is an error parsing the string, an empty array is returned. These all return scalars. min and max are not well supported yet. +=item rrdlabel + +Returns a label that can be used for the dataset name of an RRD, ie, between 1-19 +characters long with characters [a-zA-Z0-9_]. + +There is no guarantee that multiple N:P:Performance objects will have unique rrdlabels. + =item threshold This returns a Nagios::Plugin::Threshold object. -- cgit v1.2.3-74-g34f1