[Nagiosplug-devel] Suggested code addition to perl Nagios::Plugin module - instance methods for starting and resetting a global alarm()
Max
perldork at webwizarddesign.com
Thu Jul 9 05:16:39 CEST 2009
On Wed, Jul 8, 2009 at 7:02 PM, Thomas Guyot-Sionnest<dermoth at aei.ca> wrote:
> What you want is already implemented trough Nagios::Plugin::Getopt,
> which (among others) automatically parses the -t (or -0-timeout) argument.
I did say we subclass Nagios::Plugin, so the code you see in my code
that calls ->opts->get('timeout') is calling your methods as I extend
your module. I am not reimplimenting nor repeating code you have
done. If you look at my module Nagios::Plugin::SNMP on CPAN you will
see I don't reinvent any wheels you have already made :).
> ' alarm($n->opts->timeout);
This still doesn't make sense to me over having a simple wrapper
around timeout in Nagios::Plugin so the user doesn't have to call
alarm($n->opts->timeout) in their code every time they want to do a
timeout instead of doing
$plugin->start_timer();
which would also then make it easy to let the user override a default
$SIG{'ALRM'} handler by passing a reference to a function in to either
new() or to the wrapper function, e.g.
$plugin->start_timer(
sub { my $secs = $plugin->opts->get('timeout');
$plugin->exit(CRITICAL, "Timeout of ${secs} seconds breached!"); }
);
More information about the Devel
mailing list