[Nagiosplug-devel] Nagios::Plugin api

Gavin Carr gavin at openfusion.com.au
Fri Sep 1 22:40:09 CEST 2006


On Fri, Sep 01, 2006 at 08:53:12AM +0100, Ton Voon wrote:
> I've had a thought - does overriding die cause a problem with  
> embedded perl? Design-wise, Nagios::Plugin should play nicely with  
> embedded perl.
> 
> On 31 Aug 2006, at 20:36, Lawrence, Lynne wrote:
> 
> >I believe that if you put the signal handler in the BEGIN{} block  
> >of Nagios::Plugin it will take effect when the class is loaded with  
> >the 'use' statement, even before object creation:
> >
> >package Nagios::Plugin;
> >use strict;
> >
> >our %STAT= 
> >('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
> >
> >BEGIN { $SIG{__DIE__} = sub { die_exit(@_) }; }
> >.
> >.
> >.
> >sub die_exit {
> >    my $fmt = shift;
> >    printf("Execution Error: " . $fmt, @_);
> >    exit($STAT{UNKNOWN},);
> >}
> >
> >This way users would not have to include it in plugin scripts.

BEGIN blocks are problematic with ePN in the sense that they're
only called once per ePN invocation, not once per plugin invocation,
which is what a plugin author would expect. In this case it doesn't
matter.

OTOH, I don't think it's necessary to put the die handler in a 
BEGIN block - if it's done in global scope in a module it will get
setup at 'use' time anyway. We only really care that it's set before
the first use of die in the plugin.

Cheers,
Gavin





More information about the Devel mailing list