diff options
author | Ton Voon <tonvoon@macbook.local> | 2008-12-02 16:53:56 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@macbook.local> | 2008-12-02 16:53:56 +0000 |
commit | 0907cdbca2ebcb775a0bbcae639e378e440cd738 (patch) | |
tree | 558bbb79f3c83fb150f689e71a38b251b17d0ba9 /lib/Nagios | |
parent | c261abc4eacd49314ab18782ac8158bf9f2dbf5d (diff) | |
download | monitoring-plugin-perl-0907cdbca2ebcb775a0bbcae639e378e440cd738.tar.gz |
Added clean_label, like rrdlabel, but without truncation
Diffstat (limited to 'lib/Nagios')
-rw-r--r-- | lib/Nagios/Plugin.pm | 2 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 2 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Performance.pm | 25 |
3 files changed, 21 insertions, 8 deletions
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); | |||
25 | # CPAN stupidly won't index this module without a literal $VERSION here, | 25 | # CPAN stupidly won't index this module without a literal $VERSION here, |
26 | # so we're forced to duplicate it explicitly | 26 | # so we're forced to duplicate it explicitly |
27 | # Make sure you update $Nagios::Plugin::Functions::VERSION too | 27 | # Make sure you update $Nagios::Plugin::Functions::VERSION too |
28 | our $VERSION = "0.28"; | 28 | our $VERSION = "0.29"; |
29 | 29 | ||
30 | sub new { | 30 | sub new { |
31 | my $class = shift; | 31 | 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); | |||
12 | use Math::Calc::Units; | 12 | use Math::Calc::Units; |
13 | 13 | ||
14 | # Remember to update Nagios::Plugins as well | 14 | # Remember to update Nagios::Plugins as well |
15 | our $VERSION = "0.28"; | 15 | our $VERSION = "0.29"; |
16 | 16 | ||
17 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); | 17 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); |
18 | 18 | ||
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 | |||
@@ -70,18 +70,22 @@ sub parse_perfstring { | |||
70 | 70 | ||
71 | sub rrdlabel { | 71 | sub rrdlabel { |
72 | my $self = shift; | 72 | my $self = shift; |
73 | my $name = $self->clean_label; | ||
74 | # Shorten | ||
75 | return substr( $name, 0, 19 ); | ||
76 | } | ||
77 | |||
78 | sub clean_label { | ||
79 | my $self = shift; | ||
73 | my $name = $self->label; | 80 | my $name = $self->label; |
74 | if ($name eq "/") { | 81 | if ($name eq "/") { |
75 | $name = "root"; | 82 | $name = "root"; |
76 | } | 83 | } elsif ( $name =~ s/^\/// ) { |
77 | # If filesystem name, remove initial / and convert subsequent "/" to "_" | ||
78 | elsif ($name =~ s/^\///) { | ||
79 | $name =~ s/\//_/g; | 84 | $name =~ s/\//_/g; |
80 | } | 85 | } |
81 | # Convert bad chars | 86 | # Convert all other characters |
82 | $name =~ s/\W/_/g; | 87 | $name =~ s/\W/_/g; |
83 | # Shorten | 88 | return $name; |
84 | return substr( $name, 0, 19 ); | ||
85 | } | 89 | } |
86 | 90 | ||
87 | # Backward compatibility: create a threshold object on the fly as requested | 91 | # 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 | |||
212 | an RRD i.e. munges label to be 1-19 characters long with only characters | 216 | an RRD i.e. munges label to be 1-19 characters long with only characters |
213 | [a-zA-Z0-9_]. | 217 | [a-zA-Z0-9_]. |
214 | 218 | ||
219 | This calls $self->clean_label and then truncates to 19 characters. | ||
220 | |||
215 | There is no guarantee that multiple N:P:Performance objects will have unique | 221 | There is no guarantee that multiple N:P:Performance objects will have unique |
216 | rrdlabels. | 222 | rrdlabels. |
217 | 223 | ||
224 | =item clean_label | ||
225 | |||
226 | Returns a "clean" label for use as a dataset name in RRD, ie, it converts | ||
227 | characters that are not [a-zA-Z0-9_] to _. | ||
228 | |||
229 | It also converts "/" to "root" and "/{name}" to "{name}". | ||
230 | |||
218 | =item perfoutput | 231 | =item perfoutput |
219 | 232 | ||
220 | Outputs the data in Nagios::Plugin perfdata format i.e. | 233 | Outputs the data in Nagios::Plugin perfdata format i.e. |