[Nagiosplug-devel] Nagios::Plugin api

Vonnahme, Nathan nathan.vonnahme at bannerhealth.com
Wed Aug 30 22:04:00 CEST 2006


> On Wed, Aug 30, 2006 at 10:40:26AM +1000, Gavin Carr wrote:
> >   $p->die( OK, $msg )
> >   $p->die( CRITICAL, $msg )
> >   $p->die( UNKNOWN, $msg )
> 
> Hmmm, or maybe this is better:
> 
>     $p->die( $msg );      # defaults to CRITICAL
>     $p->die( $msg, WARNING );
>     $p->die( $msg, UNKNOWN );
> 
> etc.


I like that, it is more intuitive.  Maybe it should default to UNKNOWN
though-- you should explicitly throw CRITICAL or WARNING if it's an
expected problem (the thing you're checking is down/excessive), and just
plain die() (which would return UNKNOWN) if it's something that keeps
you from checking, like if a file your check script needs isn't there.


What about even overloading the die and end handlers like this (I may
not have it quite right... and you'd have to do it in the check script,
not the module) ?

	local $SIG{__DIE__} = sub { &Nagios::Plugin::die(@_) }
	END = sub { Nagios::Plugin::exit() }

# then I think you could say:

	open F, $f 
	   or die "can't open $f for reading - $!";

	die "oh no!", CRITICAL if $critical;
	die "uh oh, slightly bad", WARNING if ! $critical && ! $ok;

	# everything's fine
	$p->exit();  # unnecessary, EOF would work the same


Maybe something more Carp-ish would be better though?  Maybe
Nagios::Plugin::Carp ?





More information about the Devel mailing list