[Nagiosplug-checkins] SF.net SVN: nagiosplug:[2108] Nagios-Plugin/trunk
dermoth at users.sourceforge.net
dermoth at users.sourceforge.net
Tue Dec 2 18:04:27 CET 2008
Revision: 2108
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2108&view=rev
Author: dermoth
Date: 2008-12-02 17:04:27 +0000 (Tue, 02 Dec 2008)
Log Message:
-----------
Added clean_label, like rrdlabel, but without truncation
Modified Paths:
--------------
Nagios-Plugin/trunk/Changes
Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm
Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm
Nagios-Plugin/trunk/lib/Nagios/Plugin.pm
Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t
Modified: Nagios-Plugin/trunk/Changes
===================================================================
--- Nagios-Plugin/trunk/Changes 2008-12-01 12:29:34 UTC (rev 2107)
+++ Nagios-Plugin/trunk/Changes 2008-12-02 17:04:27 UTC (rev 2108)
@@ -1,5 +1,8 @@
Revision history for Perl module Nagios::Plugin.
+0.29 2nd December 2008
+ - clean_label, for cleaning up a label for RRD, but without truncation
+
0.28 21st November 2008
- Fixed test problems when run against Test::More 0.86
- Added max_state_* wrappers
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm 2008-12-01 12:29:34 UTC (rev 2107)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm 2008-12-02 17:04:27 UTC (rev 2108)
@@ -12,7 +12,7 @@
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);
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm 2008-12-01 12:29:34 UTC (rev 2107)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm 2008-12-02 17:04:27 UTC (rev 2108)
@@ -70,18 +70,22 @@
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 @@
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.
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin.pm 2008-12-01 12:29:34 UTC (rev 2107)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin.pm 2008-12-02 17:04:27 UTC (rev 2108)
@@ -25,7 +25,7 @@
# 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;
Modified: Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t
===================================================================
--- Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t 2008-12-01 12:29:34 UTC (rev 2107)
+++ Nagios-Plugin/trunk/t/Nagios-Plugin-Performance.t 2008-12-02 17:04:27 UTC (rev 2108)
@@ -1,6 +1,6 @@
use strict;
-use Test::More tests => 123;
+use Test::More;
BEGIN { use_ok('Nagios::Plugin::Performance') };
diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
@@ -11,20 +11,20 @@
my (@p, $p);
my @test = (
{
- perfoutput => "/=382MB;15264;15269;0;32768", label => '/', rrdlabel => 'root', value => 382, uom => 'MB', warning => 15264, critical => 15269, min => 0, max => 32768,
+ perfoutput => "/=382MB;15264;15269;0;32768", label => '/', rrdlabel => 'root', value => 382, uom => 'MB', warning => 15264, critical => 15269, min => 0, max => 32768, clean_label => "root",
}, {
- perfoutput => "/var=218MB;9443;9448", label => '/var', rrdlabel => 'var', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef,
+ perfoutput => "/var=218MB;9443;9448", label => '/var', rrdlabel => 'var', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => "var",
+ }, {
+ perfoutput => '/var/long@:-/filesystem/name/and/bad/chars=218MB;9443;9448', label => '/var/long@:-/filesystem/name/and/bad/chars', rrdlabel => 'var_long____filesys', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => 'var_long____filesystem_name_and_bad_chars',
},
);
+plan tests => (8 * scalar @test) + 94;
+
# Round-trip tests
for my $t (@test) {
# Parse to components
($p) = Nagios::Plugin::Performance->parse_perfstring($t->{perfoutput});
- for (sort keys %$t) {
- next if m/^perfoutput$/;
- is($p->$_(), $t->{$_}, "$_ okay (" . (defined $t->{$_} ? $t->{$_} : 'undef') . ")");
- }
# Construct from components
my @construct = qw(label value uom warning critical min max);
@@ -33,6 +33,8 @@
# Check threshold accessor
is($p->threshold->warning->end, $t->{warning}, "threshold warning okay ($t->{warning})");
is($p->threshold->critical->end, $t->{critical}, "threshold critical okay ($t->{critical})");
+ is($p->rrdlabel, $t->{rrdlabel}, "rrdlabel okay");
+ is($p->clean_label, $t->{clean_label}, "clean_label okay" );
# Construct using threshold
@construct = qw(label value uom min max);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list