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

Ton Voon tonvoon at users.sourceforge.net
Thu Jun 15 10:38:20 CEST 2006


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

Modified Files:
	Performance.pm 
Log Message:
Added rrdlabel method. Fixed parse_perfstring if value=0


Index: Performance.pm
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/lib/Nagios/Plugin/Performance.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Performance.pm	9 Jun 2006 10:53:22 -0000	1.2
+++ Performance.pm	15 Jun 2006 08:38:18 -0000	1.3
@@ -28,7 +28,7 @@
 	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 @@
 	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 @@
 
 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.





More information about the Commits mailing list