diff options
-rw-r--r-- | Changes | 3 | ||||
-rw-r--r-- | lib/Nagios/Plugin.pm | 5 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Threshold.pm | 13 | ||||
-rw-r--r-- | t/Nagios-Plugin-04.t | 8 |
4 files changed, 23 insertions, 6 deletions
@@ -1,5 +1,8 @@ | |||
1 | Revision history for Perl module Nagios::Plugin. | 1 | Revision history for Perl module Nagios::Plugin. |
2 | 2 | ||
3 | 0.36 22nd December 2011 | ||
4 | - Updated check_threshold to allow multiple check values to be checked at once | ||
5 | |||
3 | 0.35 3rd December 2010 | 6 | 0.35 3rd December 2010 |
4 | - Fixed test failures with Test::More 0.96 (Slaven Rezic and Peter John Edwards - RT57709) | 7 | - Fixed test failures with Test::More 0.96 (Slaven Rezic and Peter John Edwards - RT57709) |
5 | 8 | ||
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index d2a5145..8950477 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm | |||
@@ -110,7 +110,7 @@ sub check_threshold { | |||
110 | 110 | ||
111 | my %args; | 111 | my %args; |
112 | 112 | ||
113 | if ( $#_ == 0 && ! ref $_[0]) { # one positional param | 113 | if ( $#_ == 0 && (! ref $_[0] || ref $_[0] eq "ARRAY" )) { # one positional param |
114 | %args = (check => shift); | 114 | %args = (check => shift); |
115 | } | 115 | } |
116 | else { | 116 | else { |
@@ -509,6 +509,9 @@ WARNING constant. The thresholds may be: | |||
509 | 3. implicitly set by command-line parameters -w, -c, --critical or | 509 | 3. implicitly set by command-line parameters -w, -c, --critical or |
510 | --warning, if you have run C<< $plugin->getopts() >>. | 510 | --warning, if you have run C<< $plugin->getopts() >>. |
511 | 511 | ||
512 | You can specify $value as an array of values and each will be checked against | ||
513 | the thresholds. | ||
514 | |||
512 | The return value is ready to pass to C <nagios_exit>, e . g ., | 515 | The return value is ready to pass to C <nagios_exit>, e . g ., |
513 | 516 | ||
514 | $p->nagios_exit( | 517 | $p->nagios_exit( |
diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm index 73fce53..95a089b 100644 --- a/lib/Nagios/Plugin/Threshold.pm +++ b/lib/Nagios/Plugin/Threshold.pm | |||
@@ -16,11 +16,16 @@ sub get_status | |||
16 | { | 16 | { |
17 | my ($self, $value) = @_; | 17 | my ($self, $value) = @_; |
18 | 18 | ||
19 | if ($self->critical->is_set) { | 19 | $value = [ $value ] if (ref $value eq ""); |
20 | return CRITICAL if $self->critical->check_range($value); | 20 | foreach my $v (@$value) { |
21 | if ($self->critical->is_set) { | ||
22 | return CRITICAL if $self->critical->check_range($v); | ||
23 | } | ||
21 | } | 24 | } |
22 | if ($self->warning->is_set) { | 25 | foreach my $v (@$value) { |
23 | return WARNING if $self->warning->check_range($value); | 26 | if ($self->warning->is_set) { |
27 | return WARNING if $self->warning->check_range($v); | ||
28 | } | ||
24 | } | 29 | } |
25 | return OK; | 30 | return OK; |
26 | } | 31 | } |
diff --git a/t/Nagios-Plugin-04.t b/t/Nagios-Plugin-04.t index d88ad73..e5eb3ab 100644 --- a/t/Nagios-Plugin-04.t +++ b/t/Nagios-Plugin-04.t | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | use strict; | 4 | use strict; |
5 | #use Test::More 'no_plan'; | 5 | #use Test::More 'no_plan'; |
6 | use Test::More tests=>26; | 6 | use Test::More tests=>30; |
7 | 7 | ||
8 | BEGIN { use_ok('Nagios::Plugin') }; | 8 | BEGIN { use_ok('Nagios::Plugin') }; |
9 | use Nagios::Plugin::Functions; | 9 | use Nagios::Plugin::Functions; |
@@ -52,6 +52,12 @@ is $p->check_threshold(6), WARNING, "check_threshold WARNING"; | |||
52 | is $p->check_threshold(11), CRITICAL, "check_threshold CRITICAL"; | 52 | is $p->check_threshold(11), CRITICAL, "check_threshold CRITICAL"; |
53 | is $p->check_threshold(check=>11), CRITICAL, "check_threshold CRITICAL with hash param"; | 53 | is $p->check_threshold(check=>11), CRITICAL, "check_threshold CRITICAL with hash param"; |
54 | 54 | ||
55 | # Check that arrays allowed | ||
56 | is $p->check_threshold([2,1]), OK, "check_threshold OK when called implicitly"; | ||
57 | is $p->check_threshold([6,2]), WARNING, "check_threshold WARNING"; | ||
58 | is $p->check_threshold([1,2,6,11]), CRITICAL, "check_threshold CRITICAL"; | ||
59 | is $p->check_threshold(check=>[1,2,6,11]), CRITICAL, "check_threshold CRITICAL with hash param"; | ||
60 | |||
55 | # thresholds set explicitly | 61 | # thresholds set explicitly |
56 | is $p->check_threshold( | 62 | is $p->check_threshold( |
57 | check => 2, | 63 | check => 2, |