diff options
-rw-r--r-- | Changes | 1 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Range.pm | 8 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Threshold.pm | 6 | ||||
-rw-r--r-- | t/Nagios-Plugin-Performance.t | 11 | ||||
-rw-r--r-- | t/Nagios-Plugin-Threshold.t | 8 |
5 files changed, 21 insertions, 13 deletions
@@ -4,6 +4,7 @@ Revision history for Perl module Nagios::Plugin. | |||
4 | - rrdlabel method available to get a performance label, | 4 | - rrdlabel method available to get a performance label, |
5 | converted to something rrd can use | 5 | converted to something rrd can use |
6 | - fixes to parse_perfstring routine if values are 0 | 6 | - fixes to parse_perfstring routine if values are 0 |
7 | - is_set method for range object to see if warning/critical range is set | ||
7 | 8 | ||
8 | 0.11 14th June 2006 | 9 | 0.11 14th June 2006 |
9 | - Interface changed for parse_perfstring, returning empty | 10 | - Interface changed for parse_perfstring, returning empty |
diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Nagios/Plugin/Range.pm index 3d6f613..c03001a 100644 --- a/lib/Nagios/Plugin/Range.pm +++ b/lib/Nagios/Plugin/Range.pm | |||
@@ -14,7 +14,7 @@ struct "Nagios::Plugin::Range" => { | |||
14 | end => '$', | 14 | end => '$', |
15 | start_infinity => '$', # TRUE / FALSE | 15 | start_infinity => '$', # TRUE / FALSE |
16 | end_infinity => '$', # TRUE / FALSE | 16 | end_infinity => '$', # TRUE / FALSE |
17 | alert_on => '$', # OUTSIDE 0, INSIDE 1 | 17 | alert_on => '$', # OUTSIDE 0, INSIDE 1, not defined == range not set |
18 | }; | 18 | }; |
19 | 19 | ||
20 | my $outside = 0; | 20 | my $outside = 0; |
@@ -22,11 +22,17 @@ my $inside = 1; | |||
22 | 22 | ||
23 | sub stringify { | 23 | sub stringify { |
24 | my $self = shift; | 24 | my $self = shift; |
25 | return "" unless $self->is_set; | ||
25 | return (($self->alert_on) ? "@" : "") . | 26 | return (($self->alert_on) ? "@" : "") . |
26 | (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) . | 27 | (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) . |
27 | (($self->end_infinity == 1) ? "" : $self->end); | 28 | (($self->end_infinity == 1) ? "" : $self->end); |
28 | } | 29 | } |
29 | 30 | ||
31 | sub is_set { | ||
32 | my $self = shift; | ||
33 | (! defined $self->alert_on) ? 0 : 1; | ||
34 | } | ||
35 | |||
30 | sub set_range_start { | 36 | sub set_range_start { |
31 | my ($self, $value) = @_; | 37 | my ($self, $value) = @_; |
32 | $self->start($value+0); # Force scalar into number | 38 | $self->start($value+0); # Force scalar into number |
diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm index 9c5d042..1b332b9 100644 --- a/lib/Nagios/Plugin/Threshold.pm +++ b/lib/Nagios/Plugin/Threshold.pm | |||
@@ -16,7 +16,7 @@ struct "Nagios::Plugin::Threshold" => { | |||
16 | 16 | ||
17 | sub set_thresholds { | 17 | sub set_thresholds { |
18 | my ($class, %args) = @_; | 18 | my ($class, %args) = @_; |
19 | my $t = $class->new; | 19 | my $t = $class->new( warning => Nagios::Plugin::Range->new, critical => Nagios::Plugin::Range->new ); |
20 | if (defined $args{warning}) { | 20 | if (defined $args{warning}) { |
21 | my $r = Nagios::Plugin::Range->parse_range_string($args{warning}); | 21 | my $r = Nagios::Plugin::Range->parse_range_string($args{warning}); |
22 | if (defined $r) { | 22 | if (defined $r) { |
@@ -44,12 +44,12 @@ sub set_thresholds { | |||
44 | 44 | ||
45 | sub get_status { | 45 | sub get_status { |
46 | my ($self, $value) = @_; | 46 | my ($self, $value) = @_; |
47 | if ($self->critical) { | 47 | if ($self->critical->is_set) { |
48 | if ($self->critical->check_range($value) == 1) { | 48 | if ($self->critical->check_range($value) == 1) { |
49 | return $ERRORS{CRITICAL}; | 49 | return $ERRORS{CRITICAL}; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | if ($self->warning) { | 52 | if ($self->warning->is_set) { |
53 | if ($self->warning->check_range($value) == 1) { | 53 | if ($self->warning->check_range($value) == 1) { |
54 | return $ERRORS{WARNING}; | 54 | return $ERRORS{WARNING}; |
55 | } | 55 | } |
diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t index aa0ab64..b10a988 100644 --- a/t/Nagios-Plugin-Performance.t +++ b/t/Nagios-Plugin-Performance.t | |||
@@ -1,6 +1,6 @@ | |||
1 | 1 | ||
2 | use strict; | 2 | use strict; |
3 | use Test::More tests => 43; | 3 | use Test::More tests => 49; |
4 | BEGIN { use_ok('Nagios::Plugin::Performance') }; | 4 | BEGIN { use_ok('Nagios::Plugin::Performance') }; |
5 | 5 | ||
6 | use Nagios::Plugin::Base; | 6 | use Nagios::Plugin::Base; |
@@ -65,12 +65,13 @@ cmp_ok( $p[0]->threshold->critical, 'eq', "10", "crit okay"); | |||
65 | cmp_ok( $p[1]->label, "eq", "size", "label okay"); | 65 | cmp_ok( $p[1]->label, "eq", "size", "label okay"); |
66 | cmp_ok( $p[1]->value, "==", 426, "value okay"); | 66 | cmp_ok( $p[1]->value, "==", 426, "value okay"); |
67 | cmp_ok( $p[1]->uom, "eq", "B", "uom okay"); | 67 | cmp_ok( $p[1]->uom, "eq", "B", "uom okay"); |
68 | ok( ! defined $p[1]->threshold->warning, "warn okay"); | 68 | ok( ! $p[1]->threshold->warning->is_set, "warn okay"); |
69 | ok( ! defined $p[1]->threshold->critical, "crit okay"); | 69 | ok( ! $p[1]->threshold->critical->is_set, "crit okay"); |
70 | 70 | ||
71 | # RRDlabel testing | 71 | # Edge cases |
72 | @p = Nagios::Plugin::Performance->parse_perfstring("/home/a-m=0 shared-folder:big=20 12345678901234567890=20"); | 72 | @p = Nagios::Plugin::Performance->parse_perfstring("/home/a-m=0;0;0 shared-folder:big=20 12345678901234567890=20"); |
73 | cmp_ok( $p[0]->rrdlabel, "eq", "home_a_m", "changing / to _"); | 73 | cmp_ok( $p[0]->rrdlabel, "eq", "home_a_m", "changing / to _"); |
74 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); | ||
74 | cmp_ok( $p[1]->rrdlabel, "eq", "shared_folder_big", "replacing bad characters"); | 75 | cmp_ok( $p[1]->rrdlabel, "eq", "shared_folder_big", "replacing bad characters"); |
75 | cmp_ok( $p[2]->rrdlabel, "eq", "1234567890123456789", "shortening rrd label"); | 76 | cmp_ok( $p[2]->rrdlabel, "eq", "1234567890123456789", "shortening rrd label"); |
76 | 77 | ||
diff --git a/t/Nagios-Plugin-Threshold.t b/t/Nagios-Plugin-Threshold.t index 764f7b0..97d4fcc 100644 --- a/t/Nagios-Plugin-Threshold.t +++ b/t/Nagios-Plugin-Threshold.t | |||
@@ -8,14 +8,14 @@ Nagios::Plugin::Base->print_on_die(0); | |||
8 | 8 | ||
9 | my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80"); | 9 | my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80"); |
10 | ok( defined $t, "Threshold ('', '80') set"); | 10 | ok( defined $t, "Threshold ('', '80') set"); |
11 | ok( ! defined $t->warning, "Warning not set"); | 11 | ok( ! $t->warning->is_set, "Warning not set"); |
12 | cmp_ok( $t->critical->end, '==', 80, "Critical set correctly"); | 12 | cmp_ok( $t->critical->end, '==', 80, "Critical set correctly"); |
13 | 13 | ||
14 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => ""); | 14 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => ""); |
15 | ok( defined $t, "Threshold ('5:33', '') set"); | 15 | ok( defined $t, "Threshold ('5:33', '') set"); |
16 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); | 16 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); |
17 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); | 17 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); |
18 | ok( ! defined $t->critical, "Critical not set"); | 18 | ok( ! $t->critical->is_set, "Critical not set"); |
19 | 19 | ||
20 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "30", critical => "60"); | 20 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "30", critical => "60"); |
21 | ok( defined $t, "Threshold ('30', '60') set"); | 21 | ok( defined $t, "Threshold ('30', '60') set"); |
@@ -27,6 +27,6 @@ cmp_ok( $t->get_status(69), '==', $ERRORS{CRITICAL}, "69 - critical"); | |||
27 | 27 | ||
28 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "total", critical => "rubbish"); | 28 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "total", critical => "rubbish"); |
29 | ok( defined $t, "Threshold object created although ..."); | 29 | ok( defined $t, "Threshold object created although ..."); |
30 | ok( ! defined $t->warning, "Warning not set"); | 30 | ok( ! $t->warning->is_set, "Warning not set"); |
31 | ok( ! defined $t->critical, "Critical not set"); | 31 | ok( ! $t->critical->is_set, "Critical not set"); |
32 | 32 | ||