diff options
Diffstat (limited to 'lib/Nagios')
| -rw-r--r-- | lib/Nagios/Plugin.pm | 45 |
1 files changed, 38 insertions, 7 deletions
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 { | |||
| 123 | } ); | 123 | } ); |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | |||
| 127 | # in order of preference, get warning and critical from | 126 | # in order of preference, get warning and critical from |
| 128 | # 1. explicit arguments to check_threshold | 127 | # 1. explicit arguments to check_threshold |
| 129 | # 2. previously explicitly set threshold object | 128 | # 2. previously explicitly set threshold object |
| 130 | # 3. implicit options from Getopts object | 129 | # 3. implicit options from Getopts object |
| 131 | |||
| 132 | if ( exists $args{warning} || exists $args{critical} ) { | 130 | if ( exists $args{warning} || exists $args{critical} ) { |
| 133 | $self->set_thresholds( | 131 | $self->set_thresholds( |
| 134 | warning => $args{warning}, | 132 | warning => $args{warning}, |
| @@ -152,7 +150,7 @@ sub check_threshold { | |||
| 152 | } | 150 | } |
| 153 | 151 | ||
| 154 | # top level interface to my Nagios::Plugin::Getopt object | 152 | # top level interface to my Nagios::Plugin::Getopt object |
| 155 | sub arg { | 153 | sub add_arg { |
| 156 | my $self = shift; | 154 | my $self = shift; |
| 157 | $self->opts->arg(@_) if $self->_check_for_opts; | 155 | $self->opts->arg(@_) if $self->_check_for_opts; |
| 158 | } | 156 | } |
| @@ -258,8 +256,7 @@ plugins | |||
| 258 | # Return code: 3; | 256 | # Return code: 3; |
| 259 | # output: PAGESIZE UNKNOWN - Could not retrieve page | 257 | # output: PAGESIZE UNKNOWN - Could not retrieve page |
| 260 | 258 | ||
| 261 | # Threshold methods (NOT YET IMPLEMENTED - use | 259 | # Threshold methods |
| 262 | # Nagios::Plugin::Threshold for now) | ||
| 263 | $code = $np->check_threshold( | 260 | $code = $np->check_threshold( |
| 264 | check => $value, | 261 | check => $value, |
| 265 | warning => $warning_threshold, | 262 | warning => $warning_threshold, |
| @@ -379,16 +376,50 @@ Alias for nagios_die(). Deprecated. | |||
| 379 | 376 | ||
| 380 | =back | 377 | =back |
| 381 | 378 | ||
| 382 | |||
| 383 | =head2 THRESHOLD METHODS | 379 | =head2 THRESHOLD METHODS |
| 384 | 380 | ||
| 385 | NOT YET IMPLEMENTED - use Nagios::Plugin::Threshold directly for now. | 381 | These provide a top level interface to the C<Nagios::Plugins::Threshold> |
| 382 | module; for more details, see its documentation. | ||
| 386 | 383 | ||
| 387 | =over 4 | 384 | =over 4 |
| 388 | 385 | ||
| 389 | =item check_threshold( $value ) | 386 | =item check_threshold( $value ) |
| 387 | |||
| 390 | =item check_threshold( check => $value, warning => $warn, critical => $crit ) | 388 | =item check_threshold( check => $value, warning => $warn, critical => $crit ) |
| 391 | 389 | ||
| 390 | Evaluates $value against the thresholds and returns OK, CRITICAL, or | ||
| 391 | WARNING constant. The thresholds may be: | ||
| 392 | |||
| 393 | 1. explicitly set by passing 'warning' and/or 'critical' parameters to | ||
| 394 | C<check_threshold()>, or, | ||
| 395 | |||
| 396 | 2. explicitly set by calling C<set_thresholds()> before C<check_threshold()>, or, | ||
| 397 | |||
| 398 | 3. implicitly set by command-line parameters -w, -c, --critical or | ||
| 399 | --warning, if you have run C<$plugin->getopts()>. | ||
| 400 | |||
| 401 | The return value is ready to pass to C <nagios_exit>, e . g ., | ||
| 402 | |||
| 403 | $p->nagios_exit( | ||
| 404 | return_code => $p->check_threshold($result), | ||
| 405 | message => " sample result was $result" | ||
| 406 | ); | ||
| 407 | |||
| 408 | |||
| 409 | =item set_thresholds(warning => "10:25", critical => "~:25") | ||
| 410 | |||
| 411 | Sets the acceptable ranges and creates the plugin's | ||
| 412 | Nagios::Plugins::Threshold object. See | ||
| 413 | http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT | ||
| 414 | for details and examples of the threshold format. | ||
| 415 | |||
| 416 | =item threshold() | ||
| 417 | |||
| 418 | Returns the object's C<Nagios::Plugin::Threshold> object, if it has | ||
| 419 | been defined by calling set_thresholds(). You can pass a new | ||
| 420 | Threshold object to it to replace the old one too, but you shouldn't | ||
| 421 | need to do that from a plugin script. | ||
| 422 | |||
| 392 | =back | 423 | =back |
| 393 | 424 | ||
| 394 | 425 | ||
