[Nagiosplug-devel] Nagios::Plugin thresholds

Vonnahme, Nathan nathan.vonnahme at bannerhealth.com
Thu Sep 7 20:00:15 CEST 2006


erm, I guess I'm kind of re-blending this with the general API
discussion:

Gavin wrote, though Outlook is too stupid to quote correctly:

> How about something like this:
> 
>   $plugin->check_threshold(
>     check => $value, message => "page size at http://... was 
> ${value}kB",
>     warning => $warning, critical => $critical,
>   );
> 
> which creates your N::P::Threshold object behind the scenes, sets the
> thresholds using $warning and $critical, calls 
> N::P::Threshold->get_status, 
> and exits iff the result is a WARNING or a CRITICAL. 
> 
> You might also have:
> 
>   $plugin->check_threshold_exit( <same_args> );
> 
> which always exits i.e. it's a convenience for:
> 
>   $self->check_threshold( %args );
>   $self->nagios_exit( OK, %args{message} );



Wouldn't check_threshold return a valid nagios status code (OK, WARNING,
CRITICAL) ?  

Also, we're talking about subsuming the GetOpts module under the main
plugin API, right, so the prelude to the example would be something
like:
	 
	my $plugin = Nagios::Plugin->new;

	$plugin->define_arg(
		spec => 'warning|w=s',
		help => qq{-w, --warning=INTEGER:INTEGER blah blah},
	);
	$plugin->define_arg(
		spec => 'critical|c=s',
		help => qq{-c, --critical=INTEGER:INTEGER  blah blah },
	);

	alarm $plugin->timeout;  
	my $value = get_my_plugin_specific_stuff_here();
	my $message = "page size at http://... was  ${value}kB";


# then either

	my $return_status = $plugin->check_threshold(
	     check => $value, 
	     warning => $plugin->opt('warning'),        # it would have
to call Nagios::Plugin::Getopt::getopts() 
							# the first time
we ask for an opt()
	     critical => $plugin->opt('critical'),
	);

	$plugin->nagios_exit($return_status, $message);


# or a shortcut like

	$plugin->check_threshold_exit(
	     check => $value, 
	     message => $message,
	     warning => $plugin->opt('warning'), 
	     critical => $plugin->opt('critical'),
	);



and I would vote to *not* have that shortcut since it doesn't really
save or clarify...  you might just as well say:

	$plugin->nagios_exit(  
		$plugin->check_threshold(
		     check => $value, 
		     warning => $plugin->opt('warning'), 
		     critical => $plugin->opt('critical'),
		),
		$message
	);

	

also, I would still like to have a die() method so I'd be able to say
something like:

	my $value = get_my_plugin_specific_stuff_here()
		or $plugin->die("couldn't check stuff because of foo!
$!");  # returns UNKNOWN plus message




On a side note, Gavin, is there any problem with standardizing on one
spelling of license/licence in Getopt.pm ?





More information about the Devel mailing list