diff options
-rw-r--r-- | Changes | 5 | ||||
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | lib/Nagios/Plugin.pm | 2 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Performance.pm | 24 | ||||
-rw-r--r-- | t/Nagios-Plugin-Performance.t | 9 |
5 files changed, 39 insertions, 2 deletions
@@ -1,5 +1,10 @@ | |||
1 | Revision history for Perl module Nagios::Plugin. | 1 | Revision history for Perl module Nagios::Plugin. |
2 | 2 | ||
3 | 0.12 ?? | ||
4 | - rrdlabel method available to get a performance label, | ||
5 | converted to something rrd can use | ||
6 | - fixes to parse_perfstring routine if values are 0 | ||
7 | |||
3 | 0.11 14th June 2006 | 8 | 0.11 14th June 2006 |
4 | - Interface changed for parse_perfstring, returning empty | 9 | - Interface changed for parse_perfstring, returning empty |
5 | array if not parseable | 10 | array if not parseable |
@@ -11,3 +11,4 @@ lib/Nagios/Plugin/Performance.pm | |||
11 | lib/Nagios/Plugin/Range.pm | 11 | lib/Nagios/Plugin/Range.pm |
12 | lib/Nagios/Plugin/Threshold.pm | 12 | lib/Nagios/Plugin/Threshold.pm |
13 | lib/Nagios/Plugin/Base.pm | 13 | lib/Nagios/Plugin/Base.pm |
14 | META.yml Module meta-data (added by MakeMaker) | ||
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; | |||
23 | our @ISA = qw(Exporter Nagios::__::Plugin); | 23 | our @ISA = qw(Exporter Nagios::__::Plugin); |
24 | our @EXPORT_OK = qw(%ERRORS); | 24 | our @EXPORT_OK = qw(%ERRORS); |
25 | 25 | ||
26 | our $VERSION = '0.11'; | 26 | our $VERSION = '0.12'; |
27 | 27 | ||
28 | sub add_perfdata { | 28 | sub add_perfdata { |
29 | my ($self, %args) = @_; | 29 | 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 { | |||
28 | my $string = shift; | 28 | my $string = shift; |
29 | my $p = $class->new; | 29 | my $p = $class->new; |
30 | $string =~ s/^([^=]+)=([\d\.]+)(\w*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?\s*//; | 30 | $string =~ s/^([^=]+)=([\d\.]+)(\w*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?\s*//; |
31 | return undef unless ($1 && $2); | 31 | return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne "")); |
32 | $p->label($1); | 32 | $p->label($1); |
33 | $p->value($2+0); | 33 | $p->value($2+0); |
34 | $p->uom($3); | 34 | $p->uom($3); |
@@ -50,6 +50,21 @@ sub parse_perfstring { | |||
50 | return @perfs; | 50 | return @perfs; |
51 | } | 51 | } |
52 | 52 | ||
53 | sub rrdlabel { | ||
54 | my $self = shift; | ||
55 | my $name = $self->label; | ||
56 | if ($name eq "/") { | ||
57 | $name = "root"; | ||
58 | # If filesystem name, remove initial / and convert subsequent "/" to "_" | ||
59 | } elsif ($name =~ s/^\///) { | ||
60 | $name =~ s/\//_/g; | ||
61 | } | ||
62 | # Convert bad chars | ||
63 | $name =~ s/\W/_/g; | ||
64 | # Shorten | ||
65 | return substr( $name, 0, 19 ); | ||
66 | } | ||
67 | |||
53 | 1; | 68 | 1; |
54 | __END__ | 69 | __END__ |
55 | 70 | ||
@@ -94,6 +109,13 @@ If there is an error parsing the string, an empty array is returned. | |||
94 | 109 | ||
95 | These all return scalars. min and max are not well supported yet. | 110 | These all return scalars. min and max are not well supported yet. |
96 | 111 | ||
112 | =item rrdlabel | ||
113 | |||
114 | Returns a label that can be used for the dataset name of an RRD, ie, between 1-19 | ||
115 | characters long with characters [a-zA-Z0-9_]. | ||
116 | |||
117 | There is no guarantee that multiple N:P:Performance objects will have unique rrdlabels. | ||
118 | |||
97 | =item threshold | 119 | =item threshold |
98 | 120 | ||
99 | This returns a Nagios::Plugin::Threshold object. | 121 | This returns a Nagios::Plugin::Threshold object. |
diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t index a00b2db..aa0ab64 100644 --- a/t/Nagios-Plugin-Performance.t +++ b/t/Nagios-Plugin-Performance.t | |||
@@ -8,6 +8,7 @@ Nagios::Plugin::Base->exit_on_die(0); | |||
8 | 8 | ||
9 | my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); | 9 | my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); |
10 | cmp_ok( $p[0]->label, 'eq', "/", "label okay"); | 10 | cmp_ok( $p[0]->label, 'eq', "/", "label okay"); |
11 | cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay"); | ||
11 | cmp_ok( $p[0]->value, '==', 382, "value okay"); | 12 | cmp_ok( $p[0]->value, '==', 382, "value okay"); |
12 | cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay"); | 13 | cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay"); |
13 | cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay"); | 14 | cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay"); |
@@ -16,6 +17,7 @@ ok( ! defined $p[0]->min, "min okay"); | |||
16 | ok( ! defined $p[0]->max, "max okay"); | 17 | ok( ! defined $p[0]->max, "max okay"); |
17 | 18 | ||
18 | cmp_ok( $p[1]->label, 'eq', "/var", "label okay"); | 19 | cmp_ok( $p[1]->label, 'eq', "/var", "label okay"); |
20 | cmp_ok( $p[1]->rrdlabel, 'eq', "var", "rrd label okay"); | ||
19 | cmp_ok( $p[1]->value, '==', 218, "value okay"); | 21 | cmp_ok( $p[1]->value, '==', 218, "value okay"); |
20 | cmp_ok( $p[1]->uom, 'eq', "MB", "uom okay"); | 22 | cmp_ok( $p[1]->uom, 'eq', "MB", "uom okay"); |
21 | cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay"); | 23 | cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay"); |
@@ -65,3 +67,10 @@ cmp_ok( $p[1]->value, "==", 426, "value okay"); | |||
65 | cmp_ok( $p[1]->uom, "eq", "B", "uom okay"); | 67 | cmp_ok( $p[1]->uom, "eq", "B", "uom okay"); |
66 | ok( ! defined $p[1]->threshold->warning, "warn okay"); | 68 | ok( ! defined $p[1]->threshold->warning, "warn okay"); |
67 | ok( ! defined $p[1]->threshold->critical, "crit okay"); | 69 | ok( ! defined $p[1]->threshold->critical, "crit okay"); |
70 | |||
71 | # RRDlabel testing | ||
72 | @p = Nagios::Plugin::Performance->parse_perfstring("/home/a-m=0 shared-folder:big=20 12345678901234567890=20"); | ||
73 | cmp_ok( $p[0]->rrdlabel, "eq", "home_a_m", "changing / to _"); | ||
74 | cmp_ok( $p[1]->rrdlabel, "eq", "shared_folder_big", "replacing bad characters"); | ||
75 | cmp_ok( $p[2]->rrdlabel, "eq", "1234567890123456789", "shortening rrd label"); | ||
76 | |||