diff options
-rw-r--r-- | Changes | 10 | ||||
-rw-r--r-- | Makefile.PL | 2 | ||||
-rw-r--r-- | lib/Nagios/Plugin.pm | 3 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 18 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Performance.pm | 2 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Range.pm | 24 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Threshold.pm | 90 | ||||
-rw-r--r-- | t/Nagios-Plugin-04.t | 13 | ||||
-rw-r--r-- | t/Nagios-Plugin-Threshold.t | 61 |
9 files changed, 154 insertions, 69 deletions
@@ -1,8 +1,12 @@ | |||
1 | Revision history for Perl module Nagios::Plugin. | 1 | Revision history for Perl module Nagios::Plugin. |
2 | 2 | ||
3 | ??? ?? | 3 | 0.16 ?? |
4 | - fixed warnings when no uom specified for add_perfdata | 4 | - perldoc updates to Performance, Threshold, and Range (Gavin) |
5 | - added max_state function in N::P::Functions | 5 | - remove default use of Threshold from N::P::Performance (Gavin) |
6 | - remove remaining Class::Struct usages from Threshold + Range (Gavin) | ||
7 | - remove remaining Class::Struct usages from Performance (Gavin) | ||
8 | - fixed warnings when no uom specified for add_perfdata (Ton) | ||
9 | - added max_state function in N::P::Functions (Ton) | ||
6 | 10 | ||
7 | 0.15 19th December 2006 | 11 | 0.15 19th December 2006 |
8 | - exposed Getopt and Threshold functionality from top level Nagios::Plugin | 12 | - exposed Getopt and Threshold functionality from top level Nagios::Plugin |
diff --git a/Makefile.PL b/Makefile.PL index 63b36da..c043edb 100644 --- a/Makefile.PL +++ b/Makefile.PL | |||
@@ -10,11 +10,11 @@ WriteMakefile( | |||
10 | Class::Accessor => 0, | 10 | Class::Accessor => 0, |
11 | Test::More => 0.62, | 11 | Test::More => 0.62, |
12 | Carp => 0, | 12 | Carp => 0, |
13 | Test::Exception => 0, | ||
14 | Config::Tiny => 0, | 13 | Config::Tiny => 0, |
15 | File::Spec => 0, | 14 | File::Spec => 0, |
16 | File::Basename => 0, | 15 | File::Basename => 0, |
17 | IO::File => 0, | 16 | IO::File => 0, |
17 | Math::Calc::Units => 0, # used in N::P::Performance | ||
18 | }, # e.g., Module::Name => 1.1 | 18 | }, # e.g., Module::Name => 1.1 |
19 | ($] >= 5.005 ? ## Add these new keywords supported since 5.005 | 19 | ($] >= 5.005 ? ## Add these new keywords supported since 5.005 |
20 | (ABSTRACT_FROM => 'lib/Nagios/Plugin.pm', # retrieve abstract from module | 20 | (ABSTRACT_FROM => 'lib/Nagios/Plugin.pm', # retrieve abstract from module |
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index 576322b..b063e4c 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm | |||
@@ -22,8 +22,7 @@ our @ISA = qw(Exporter); | |||
22 | our @EXPORT = (@STATUS_CODES); | 22 | our @EXPORT = (@STATUS_CODES); |
23 | our @EXPORT_OK = qw(%ERRORS); | 23 | our @EXPORT_OK = qw(%ERRORS); |
24 | 24 | ||
25 | # Remember to update Nagios::Plugin::Functions as well! | 25 | our $VERSION = $Nagios::Plugin::Functions::VERSION; |
26 | our $VERSION = "0.15"; | ||
27 | 26 | ||
28 | sub new { | 27 | sub new { |
29 | my $class = shift; | 28 | my $class = shift; |
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index 513501b..526dbed 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm | |||
@@ -9,20 +9,21 @@ use strict; | |||
9 | use warnings; | 9 | use warnings; |
10 | use File::Basename; | 10 | use File::Basename; |
11 | use Params::Validate qw(validate :types); | 11 | use Params::Validate qw(validate :types); |
12 | use Math::Calc::Units; | ||
12 | 13 | ||
13 | # Remember to update Nagios::Plugins as well | 14 | # Remember to update Nagios::Plugins as well |
14 | our $VERSION = "0.15"; | 15 | our $VERSION = "0.16"; |
15 | 16 | ||
16 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); | 17 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); |
17 | 18 | ||
18 | require Exporter; | 19 | require Exporter; |
19 | our @ISA = qw(Exporter); | 20 | our @ISA = qw(Exporter); |
20 | our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); | 21 | our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); |
21 | our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state); | 22 | our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state convert); |
22 | our %EXPORT_TAGS = ( | 23 | our %EXPORT_TAGS = ( |
23 | all => [ @EXPORT, @EXPORT_OK ], | 24 | all => [ @EXPORT, @EXPORT_OK ], |
24 | codes => [ @STATUS_CODES ], | 25 | codes => [ @STATUS_CODES ], |
25 | functions => [ qw(nagios_exit nagios_die check_messages max_state) ], | 26 | functions => [ qw(nagios_exit nagios_die check_messages max_state convert) ], |
26 | ); | 27 | ); |
27 | 28 | ||
28 | use constant OK => 0; | 29 | use constant OK => 0; |
@@ -150,6 +151,17 @@ sub die { nagios_die(@_); } | |||
150 | 151 | ||
151 | 152 | ||
152 | # ------------------------------------------------------------------------ | 153 | # ------------------------------------------------------------------------ |
154 | # Utility functions | ||
155 | |||
156 | # Simple wrapper around Math::Calc::Units::convert | ||
157 | sub convert | ||
158 | { | ||
159 | my ($value, $from, $to) = @_; | ||
160 | my ($newval) = Math::Calc::Units::convert("$value $from", $to, 'exact'); | ||
161 | return $newval; | ||
162 | } | ||
163 | |||
164 | # ------------------------------------------------------------------------ | ||
153 | # check_messages - return a status and/or message based on a set of | 165 | # check_messages - return a status and/or message based on a set of |
154 | # message arrays. | 166 | # message arrays. |
155 | # Returns a nagios status code in scalar context. | 167 | # Returns a nagios status code in scalar context. |
diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm index 1f036f2..63727c0 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Nagios/Plugin/Performance.pm | |||
@@ -7,7 +7,7 @@ use warnings; | |||
7 | 7 | ||
8 | use Carp; | 8 | use Carp; |
9 | use base qw(Class::Accessor::Fast); | 9 | use base qw(Class::Accessor::Fast); |
10 | Nagios::Plugin::Performance->mk_ro_accessors( | 10 | __PACKAGE__->mk_ro_accessors( |
11 | qw(label value uom warning critical min max) | 11 | qw(label value uom warning critical min max) |
12 | ); | 12 | ); |
13 | 13 | ||
diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Nagios/Plugin/Range.pm index dbb637c..3828d1a 100644 --- a/lib/Nagios/Plugin/Range.pm +++ b/lib/Nagios/Plugin/Range.pm | |||
@@ -4,7 +4,12 @@ use 5.006; | |||
4 | 4 | ||
5 | use strict; | 5 | use strict; |
6 | use warnings; | 6 | use warnings; |
7 | |||
7 | use Carp; | 8 | use Carp; |
9 | use base qw(Class::Accessor::Fast); | ||
10 | __PACKAGE__->mk_accessors( | ||
11 | qw(start end start_infinity end_infinity alert_on) | ||
12 | ); | ||
8 | 13 | ||
9 | use Nagios::Plugin::Functions; | 14 | use Nagios::Plugin::Functions; |
10 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; | 15 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; |
@@ -12,15 +17,7 @@ our ($VERSION) = $Nagios::Plugin::Functions::VERSION; | |||
12 | use overload | 17 | use overload |
13 | '""' => sub { shift->_stringify }; | 18 | '""' => sub { shift->_stringify }; |
14 | 19 | ||
15 | use Class::Struct; | 20 | # alert_on constants (undef == range not set) |
16 | struct "Nagios::Plugin::Range" => { | ||
17 | start => '$', | ||
18 | end => '$', | ||
19 | start_infinity => '$', # TRUE / FALSE | ||
20 | end_infinity => '$', # TRUE / FALSE | ||
21 | alert_on => '$', # OUTSIDE 0, INSIDE 1, not defined == range not set | ||
22 | }; | ||
23 | |||
24 | use constant OUTSIDE => 0; | 21 | use constant OUTSIDE => 0; |
25 | use constant INSIDE => 1; | 22 | use constant INSIDE => 1; |
26 | 23 | ||
@@ -119,7 +116,14 @@ sub check_range { | |||
119 | } | 116 | } |
120 | } | 117 | } |
121 | 118 | ||
119 | # Constructor - map args to hashref for SUPER | ||
120 | sub new | ||
121 | { | ||
122 | shift->SUPER::new({ @_ }); | ||
123 | } | ||
124 | |||
122 | 1; | 125 | 1; |
126 | |||
123 | __END__ | 127 | __END__ |
124 | 128 | ||
125 | =head1 NAME | 129 | =head1 NAME |
@@ -135,7 +139,7 @@ Nagios::Plugin::Range - class for handling Nagios::Plugin range data. | |||
135 | $r = Nagios::Plugin::Range->new; | 139 | $r = Nagios::Plugin::Range->new; |
136 | 140 | ||
137 | # Instantiate by parsing a standard nagios range string | 141 | # Instantiate by parsing a standard nagios range string |
138 | $r = Nagios::Plugin::Range->parse_range_string; | 142 | $r = Nagios::Plugin::Range->parse_range_string( $range_str ); |
139 | 143 | ||
140 | # Returns true if the range is defined/non-empty | 144 | # Returns true if the range is defined/non-empty |
141 | $r->is_set; | 145 | $r->is_set; |
diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm index 0c4805a..ad58134 100644 --- a/lib/Nagios/Plugin/Threshold.pm +++ b/lib/Nagios/Plugin/Threshold.pm | |||
@@ -5,55 +5,75 @@ use 5.006; | |||
5 | use strict; | 5 | use strict; |
6 | use warnings; | 6 | use warnings; |
7 | 7 | ||
8 | use base qw(Class::Accessor::Fast); | ||
9 | __PACKAGE__->mk_accessors(qw(warning critical)); | ||
10 | |||
8 | use Nagios::Plugin::Range; | 11 | use Nagios::Plugin::Range; |
9 | use Nagios::Plugin::Functions qw(:codes nagios_die); | 12 | use Nagios::Plugin::Functions qw(:codes nagios_die); |
10 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; | 13 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; |
11 | 14 | ||
12 | use Class::Struct; | 15 | sub get_status |
13 | struct "Nagios::Plugin::Threshold" => { | 16 | { |
14 | warning => 'Nagios::Plugin::Range', | ||
15 | critical => 'Nagios::Plugin::Range', | ||
16 | }; | ||
17 | |||
18 | sub set_thresholds { | ||
19 | my ($class, %args) = @_; | ||
20 | my $t = $class->new( warning => Nagios::Plugin::Range->new, critical => Nagios::Plugin::Range->new ); | ||
21 | if (defined $args{warning}) { | ||
22 | my $r = Nagios::Plugin::Range->parse_range_string($args{warning}); | ||
23 | if (defined $r) { | ||
24 | $t->warning($r); | ||
25 | } else { | ||
26 | nagios_die( "Warning range incorrect: '$args{warning}'" ); | ||
27 | } | ||
28 | } | ||
29 | if (defined $args{critical}) { | ||
30 | my $r = Nagios::Plugin::Range->parse_range_string($args{critical}); | ||
31 | if (defined $r) { | ||
32 | $t->critical($r); | ||
33 | } else { | ||
34 | nagios_die( "Critical range incorrect: '$args{critical}'" ); | ||
35 | } | ||
36 | } | ||
37 | return $t; | ||
38 | } | ||
39 | |||
40 | sub get_status { | ||
41 | my ($self, $value) = @_; | 17 | my ($self, $value) = @_; |
42 | 18 | ||
43 | if ($self->critical->is_set) { | 19 | if ($self->critical->is_set) { |
44 | if ($self->critical->check_range($value) == 1) { | 20 | return CRITICAL if $self->critical->check_range($value); |
45 | return CRITICAL; | ||
46 | } | ||
47 | } | 21 | } |
48 | if ($self->warning->is_set) { | 22 | if ($self->warning->is_set) { |
49 | if ($self->warning->check_range($value) == 1) { | 23 | return WARNING if $self->warning->check_range($value); |
50 | return WARNING; | ||
51 | } | ||
52 | } | 24 | } |
53 | return OK; | 25 | return OK; |
54 | } | 26 | } |
27 | |||
28 | sub _inflate | ||
29 | { | ||
30 | my ($self, $value, $key) = @_; | ||
31 | |||
32 | # Return an undefined range if $value is undef | ||
33 | return Nagios::Plugin::Range->new if ! defined $value; | ||
34 | |||
35 | # For refs, check isa N::P::Range | ||
36 | if (ref $value) { | ||
37 | nagios_die("Invalid $key object: type " . ref $value) | ||
38 | unless $value->isa("Nagios::Plugin::Range"); | ||
39 | return $value; | ||
40 | } | ||
41 | |||
42 | # Otherwise parse $value | ||
43 | my $range = Nagios::Plugin::Range->parse_range_string($value) | ||
44 | or nagios_die("Cannot parse $key range: '$value'"); | ||
45 | return $range; | ||
46 | } | ||
47 | |||
48 | sub set_thresholds | ||
49 | { | ||
50 | my ($self, %arg) = @_; | ||
51 | |||
52 | # Equals new() as a class method | ||
53 | return $self->new(%arg) unless ref $self; | ||
54 | |||
55 | # On an object, just acts as special mutator | ||
56 | $self->set($_, $arg{$_}) foreach qw(warning critical); | ||
57 | } | ||
58 | |||
59 | sub set | ||
60 | { | ||
61 | my $self = shift; | ||
62 | my ($key, $value) = @_; | ||
63 | $self->SUPER::set($key, $self->_inflate($value, $key)); | ||
64 | } | ||
55 | 65 | ||
66 | # Constructor - inflate scalars to N::P::Range objects | ||
67 | sub new | ||
68 | { | ||
69 | my ($self, %arg) = @_; | ||
70 | $self->SUPER::new({ | ||
71 | map { $_ => $self->_inflate($arg{$_}, $_) } qw(warning critical) | ||
72 | }); | ||
73 | } | ||
74 | |||
56 | 1; | 75 | 1; |
76 | |||
57 | __END__ | 77 | __END__ |
58 | 78 | ||
59 | =head1 NAME | 79 | =head1 NAME |
diff --git a/t/Nagios-Plugin-04.t b/t/Nagios-Plugin-04.t index a110b4c..6f31b56 100644 --- a/t/Nagios-Plugin-04.t +++ b/t/Nagios-Plugin-04.t | |||
@@ -5,18 +5,20 @@ | |||
5 | use strict; | 5 | use strict; |
6 | #use Test::More 'no_plan'; | 6 | #use Test::More 'no_plan'; |
7 | use Test::More tests=>26; | 7 | use Test::More tests=>26; |
8 | use Test::Exception; | ||
9 | 8 | ||
10 | BEGIN { use_ok('Nagios::Plugin') }; | 9 | BEGIN { use_ok('Nagios::Plugin') }; |
11 | use Nagios::Plugin::Functions; | 10 | use Nagios::Plugin::Functions; |
12 | Nagios::Plugin::Functions::_fake_exit(1); | 11 | Nagios::Plugin::Functions::_fake_exit(1); |
13 | 12 | ||
14 | 13 | ||
15 | lives_ok sub { my $broke = Nagios::Plugin->new(); }, "constructor DOESN'T die without usage"; | 14 | eval { Nagios::Plugin->new(); }; |
15 | ok(! $@, "constructor DOESN'T die without usage"); | ||
16 | 16 | ||
17 | my $p = Nagios::Plugin->new(); | 17 | my $p = Nagios::Plugin->new(); |
18 | dies_ok sub { $p->add_arg('warning', 'warning') }, "add_arg() dies if you haven't instantiated with usage"; | 18 | eval { $p->add_arg('warning', 'warning') }; |
19 | dies_ok sub { $p->getopts }, "getopts() dies if you haven't instantiated with usage"; | 19 | ok($@, "add_arg() dies if you haven't instantiated with usage"); |
20 | eval { $p->getopts }; | ||
21 | ok($@, "getopts() dies if you haven't instantiated with usage"); | ||
20 | 22 | ||
21 | $p = Nagios::Plugin->new( usage => "dummy usage statement" ); | 23 | $p = Nagios::Plugin->new( usage => "dummy usage statement" ); |
22 | 24 | ||
@@ -41,7 +43,8 @@ can_ok $p, 'threshold'; | |||
41 | #isa_ok $p->threshold, 'Nagios::Plugin::Threshold', "threshold object is defined"; | 43 | #isa_ok $p->threshold, 'Nagios::Plugin::Threshold', "threshold object is defined"; |
42 | 44 | ||
43 | 45 | ||
44 | dies_ok sub { $p->check_threshold() }, "check_threshold dies if called with no args"; | 46 | eval { $p->check_threshold() }; |
47 | ok($@, "check_threshold dies if called with no args"); | ||
45 | 48 | ||
46 | 49 | ||
47 | # thresholds set implicitly | 50 | # thresholds set implicitly |
diff --git a/t/Nagios-Plugin-Threshold.t b/t/Nagios-Plugin-Threshold.t index ccb53eb..d3711bb 100644 --- a/t/Nagios-Plugin-Threshold.t +++ b/t/Nagios-Plugin-Threshold.t | |||
@@ -1,7 +1,6 @@ | |||
1 | 1 | ||
2 | use strict; | 2 | use strict; |
3 | use Test::More tests => 71; | 3 | use Test::More tests => 87; |
4 | #use Test::Exception; # broken for now so we don't need this. | ||
5 | BEGIN { | 4 | BEGIN { |
6 | use_ok('Nagios::Plugin::Threshold'); | 5 | use_ok('Nagios::Plugin::Threshold'); |
7 | use_ok('Nagios::Plugin::Functions', ':all' ); | 6 | use_ok('Nagios::Plugin::Functions', ':all' ); |
@@ -37,19 +36,31 @@ sub test_expected_statuses { | |||
37 | my $debug = shift; | 36 | my $debug = shift; |
38 | 37 | ||
39 | foreach (sort {$a<=>$b} keys %$expected) { | 38 | foreach (sort {$a<=>$b} keys %$expected) { |
40 | is $STATUS_TEXT{$t->get_status($_)}, $expected->{$_}, " $_ - $expected->{$_}"; | 39 | is $STATUS_TEXT{$t->get_status($_)}, $expected->{$_}, " $_ - $expected->{$_}"; |
41 | if ($debug) { | 40 | if ($debug) { |
42 | diag "val = $_; critical check = ".$t->critical->check_range($_). | 41 | diag "val = $_; critical check = ".$t->critical->check_range($_). |
43 | "; warning check = ".$t->warning->check_range($_); | 42 | "; warning check = ".$t->warning->check_range($_); |
44 | } | 43 | } |
45 | } | 44 | } |
46 | use Data::Dumper; | 45 | use Data::Dumper; |
47 | diag "thresh dump: ". Dumper $t if $debug; | 46 | diag "thresh dump: ". Dumper $t if $debug; |
48 | } | 47 | } |
49 | test_expected_statuses( $t, $expected ); | 48 | test_expected_statuses( $t, $expected ); |
50 | 49 | ||
50 | # GMC: this test seems bogus to me - either we've died, in which case internal | ||
51 | # state is undefined (and untestable!), or we should be returning a non-fatal error | ||
52 | if (0) { | ||
53 | diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; | ||
54 | eval { $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") }; | ||
55 | ok( defined $t, "Threshold ('5:33', '') set"); | ||
56 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); | ||
57 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); | ||
58 | ok( ! $t->critical->is_set, "Critical not set"); | ||
59 | } | ||
60 | |||
61 | # GC: same as previous test, except critical is undef instead of '' | ||
51 | diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; | 62 | diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; |
52 | eval { $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") }; | 63 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => undef); |
53 | ok( defined $t, "Threshold ('5:33', '') set"); | 64 | ok( defined $t, "Threshold ('5:33', '') set"); |
54 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); | 65 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); |
55 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); | 66 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); |
@@ -88,7 +99,6 @@ $expected = { qw( | |||
88 | ) }; | 99 | ) }; |
89 | test_expected_statuses( $t, $expected ); | 100 | test_expected_statuses( $t, $expected ); |
90 | 101 | ||
91 | |||
92 | # "I'm going to die homeless, penniless, and 30 pounds overweight." | 102 | # "I'm going to die homeless, penniless, and 30 pounds overweight." |
93 | # "...and that's...okay." | 103 | # "...and that's...okay." |
94 | 104 | ||
@@ -163,4 +173,37 @@ $expected = { qw( | |||
163 | ) }; | 173 | ) }; |
164 | test_expected_statuses( $t, $expected ); | 174 | test_expected_statuses( $t, $expected ); |
165 | 175 | ||
176 | |||
177 | # GMC: as of 0.16, set_thresholds can also be called as a mutator | ||
178 | diag "threshold mutator: warn if more than 30; critical if > 60" | ||
179 | if $ENV{TEST_VERBOSE}; | ||
180 | my $t1 = $t; | ||
181 | $t->set_thresholds(warning => "0:45", critical => "0:90"); | ||
182 | is($t1, $t, "same threshold object after \$t->set_thresholds"); | ||
183 | ok( defined $t, "Threshold ('0:45', '0:90') set"); | ||
184 | is( $t->warning->start, 0, "Warning start ok"); | ||
185 | is( $t->warning->end, 45, "Warning end ok"); | ||
186 | is( $t->critical->start, 0, "Critical start ok"); | ||
187 | is( $t->critical->end, 90, "Critical end ok"); | ||
188 | |||
189 | |||
190 | # Also as of 0.16, accepts N::P::Range objects as arguments | ||
191 | my $warning = Nagios::Plugin::Range->parse_range_string("50"); | ||
192 | my $critical = Nagios::Plugin::Range->parse_range_string("70:90"); | ||
193 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical); | ||
194 | ok( defined $t, "Threshold from ranges ('50', '70:90') set"); | ||
195 | is( $t->warning->start, 0, "Warning start ok"); | ||
196 | is( $t->warning->end, 50, "Warning end ok"); | ||
197 | is( $t->critical->start, 70, "Critical start ok"); | ||
198 | is( $t->critical->end, 90, "Critical end ok"); | ||
199 | |||
200 | $critical = Nagios::Plugin::Range->parse_range_string("90:"); | ||
201 | $t->set_thresholds(warning => "~:20", critical => $critical); | ||
202 | ok( defined $t, "Threshold from string + range ('~:20', '90:') set"); | ||
203 | ok( $t->warning->start_infinity, "Warning start ok (infinity)"); | ||
204 | is( $t->warning->end, 20, "Warning end ok"); | ||
205 | is( $t->critical->start, 90, "Critical start ok"); | ||
206 | ok( $t->critical->end_infinity, "Critical end ok (infinity)"); | ||
207 | |||
208 | |||
166 | ok 1, "sweet, made it to the end."; | 209 | ok 1, "sweet, made it to the end."; |