From cce4fccf608b3e4accf7cbf2f11da23b3d627f15 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Thu, 22 Dec 2011 11:56:08 -0500 Subject: check_threshold to check multiple values at once --- lib/Nagios/Plugin.pm | 5 ++++- lib/Nagios/Plugin/Threshold.pm | 13 +++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'lib') 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 { my %args; - if ( $#_ == 0 && ! ref $_[0]) { # one positional param + if ( $#_ == 0 && (! ref $_[0] || ref $_[0] eq "ARRAY" )) { # one positional param %args = (check => shift); } else { @@ -509,6 +509,9 @@ WARNING constant. The thresholds may be: 3. implicitly set by command-line parameters -w, -c, --critical or --warning, if you have run C<< $plugin->getopts() >>. +You can specify $value as an array of values and each will be checked against +the thresholds. + The return value is ready to pass to C , e . g ., $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 { my ($self, $value) = @_; - if ($self->critical->is_set) { - return CRITICAL if $self->critical->check_range($value); + $value = [ $value ] if (ref $value eq ""); + foreach my $v (@$value) { + if ($self->critical->is_set) { + return CRITICAL if $self->critical->check_range($v); + } } - if ($self->warning->is_set) { - return WARNING if $self->warning->check_range($value); + foreach my $v (@$value) { + if ($self->warning->is_set) { + return WARNING if $self->warning->check_range($v); + } } return OK; } -- cgit v1.2.3-74-g34f1