[Nagiosplug-devel] Suggested code addition to perl Nagios::Plugin module - instance methods for starting and resetting a global alarm()
Thomas Guyot-Sionnest
dermoth at aei.ca
Fri Jul 10 04:34:06 CEST 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 08/07/09 11:16 PM, Max wrote:
> 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();
Sure, but I don't get why making such an issue about it... There would
be nothing else in this function than a call to alarm($self->opts->timeout).
> 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.
This is already possible to implement in the current way of doing it.
> $plugin->start_timer(
> sub { my $secs = $plugin->opts->get('timeout');
> $plugin->exit(CRITICAL, "Timeout of ${secs} seconds breached!"); }
> );
I'm not a perl OO guru, but you'll probably need to pass $plugin (or any
variable you need to access) to the sub somehow. Making is global will
likely break ePN...
- --
Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFKVqid6dZ+Kt5BchYRAh9dAJ9JEGhygOFlIn3UJBLM7LA5kBsX8gCeOALA
lh7ocG7Pn/vuZz/IN+uzaZs=
=OKxV
-----END PGP SIGNATURE-----
More information about the Devel
mailing list