From 0907cdbca2ebcb775a0bbcae639e378e440cd738 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Tue, 2 Dec 2008 16:53:56 +0000 Subject: Added clean_label, like rrdlabel, but without truncation --- lib/Nagios/Plugin.pm | 2 +- lib/Nagios/Plugin/Functions.pm | 2 +- lib/Nagios/Plugin/Performance.pm | 25 +++++++++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index 7299929..eb3ccdc 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm @@ -25,7 +25,7 @@ our @EXPORT_OK = qw(%ERRORS); # CPAN stupidly won't index this module without a literal $VERSION here, # so we're forced to duplicate it explicitly # Make sure you update $Nagios::Plugin::Functions::VERSION too -our $VERSION = "0.28"; +our $VERSION = "0.29"; sub new { my $class = shift; diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index 74a7c6b..ffa23f0 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm @@ -12,7 +12,7 @@ use Params::Validate qw(:types validate); use Math::Calc::Units; # Remember to update Nagios::Plugins as well -our $VERSION = "0.28"; +our $VERSION = "0.29"; our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm index a7655fc..a9f9198 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Nagios/Plugin/Performance.pm @@ -69,19 +69,23 @@ sub parse_perfstring { } sub rrdlabel { + my $self = shift; + my $name = $self->clean_label; + # Shorten + return substr( $name, 0, 19 ); +} + +sub clean_label { my $self = shift; my $name = $self->label; if ($name eq "/") { $name = "root"; - } - # If filesystem name, remove initial / and convert subsequent "/" to "_" - elsif ($name =~ s/^\///) { + } elsif ( $name =~ s/^\/// ) { $name =~ s/\//_/g; } - # Convert bad chars + # Convert all other characters $name =~ s/\W/_/g; - # Shorten - return substr( $name, 0, 19 ); + return $name; } # Backward compatibility: create a threshold object on the fly as requested @@ -212,9 +216,18 @@ Returns a string based on 'label' that is suitable for use as dataset name of an RRD i.e. munges label to be 1-19 characters long with only characters [a-zA-Z0-9_]. +This calls $self->clean_label and then truncates to 19 characters. + There is no guarantee that multiple N:P:Performance objects will have unique rrdlabels. +=item clean_label + +Returns a "clean" label for use as a dataset name in RRD, ie, it converts +characters that are not [a-zA-Z0-9_] to _. + +It also converts "/" to "root" and "/{name}" to "{name}". + =item perfoutput Outputs the data in Nagios::Plugin perfdata format i.e. -- cgit v1.2.3-74-g34f1