From e0c038d4c2a974f53c37d0b9fb3b22b7cd8d765b Mon Sep 17 00:00:00 2001 From: Nathan Vonnahme Date: Fri, 17 Nov 2006 21:48:22 +0000 Subject: * renamed N::P::arg to add_arg * some POD work git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1539 f882894a-f735-0410-b71e-b25c423dba1c --- lib/Nagios/Plugin.pm | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'lib/Nagios') diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index f1b1807..7187048 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm @@ -123,12 +123,10 @@ sub check_threshold { } ); } - # in order of preference, get warning and critical from # 1. explicit arguments to check_threshold # 2. previously explicitly set threshold object # 3. implicit options from Getopts object - if ( exists $args{warning} || exists $args{critical} ) { $self->set_thresholds( warning => $args{warning}, @@ -152,7 +150,7 @@ sub check_threshold { } # top level interface to my Nagios::Plugin::Getopt object -sub arg { +sub add_arg { my $self = shift; $self->opts->arg(@_) if $self->_check_for_opts; } @@ -258,8 +256,7 @@ plugins # Return code: 3; # output: PAGESIZE UNKNOWN - Could not retrieve page - # Threshold methods (NOT YET IMPLEMENTED - use - # Nagios::Plugin::Threshold for now) + # Threshold methods $code = $np->check_threshold( check => $value, warning => $warning_threshold, @@ -379,16 +376,50 @@ Alias for nagios_die(). Deprecated. =back - =head2 THRESHOLD METHODS -NOT YET IMPLEMENTED - use Nagios::Plugin::Threshold directly for now. +These provide a top level interface to the C +module; for more details, see its documentation. =over 4 =item check_threshold( $value ) + =item check_threshold( check => $value, warning => $warn, critical => $crit ) +Evaluates $value against the thresholds and returns OK, CRITICAL, or +WARNING constant. The thresholds may be: + +1. explicitly set by passing 'warning' and/or 'critical' parameters to + C, or, + +2. explicitly set by calling C before C, or, + +3. implicitly set by command-line parameters -w, -c, --critical or + --warning, if you have run C<$plugin->getopts()>. + +The return value is ready to pass to C , e . g ., + + $p->nagios_exit( + return_code => $p->check_threshold($result), + message => " sample result was $result" + ); + + +=item set_thresholds(warning => "10:25", critical => "~:25") + +Sets the acceptable ranges and creates the plugin's +Nagios::Plugins::Threshold object. See +http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT +for details and examples of the threshold format. + +=item threshold() + +Returns the object's C object, if it has +been defined by calling set_thresholds(). You can pass a new +Threshold object to it to replace the old one too, but you shouldn't +need to do that from a plugin script. + =back -- cgit v1.2.3-74-g34f1