<br>I don't use Nagios::Plugin library but I have this type of code in half of my plugins. I suggest not only adding to the library but actually making a default or at least recommended in the docs. It comes real handy when your plugin has to call external commands that may hang - you don't want any extra zombie processes, etc.<br>
<br><div class="gmail_quote">On Wed, Jul 8, 2009 at 9:53 AM, Max <span dir="ltr"><<a href="mailto:perldork@webwizarddesign.com">perldork@webwizarddesign.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
We use this extensively in our scripts, simple addition, but keeps<br>
code nice and clean.  I realize this is simplistic and will break if<br>
the user uses a module that sets alarm() after the plugin alarm is<br>
set, we mostly use this in my subclass of Nagios::Plugin,<br>
Nagios::Plugin::SNMP, but use it for some non-SNMP plugins as well.<br>
<br>
- Max<br>
<br>
Example use:<br>
<br>
my $plugin = Nagios::Plugin->new(...);<br>
<br>
#  Starts a timer only if the user provided a positive integer to --timeout;<br>
#  If timeout is reached, will exit with UNKNOWN and error message.<br>
<br>
$plugin->start_timer();<br>
<br>
... code<br>
... code<br>
<br>
# All done, reset so alarm is not triggered.<br>
$plugin->reset_timer();<br>
<br>
- Max<br>
<br>
Code:<br>
<br>
# -------------------------------------------------------------------------<br>
# NP - time out helpers<br>
<br>
# Start a global timer for the plugin<br>
sub start_timer {<br>
<br>
    my $self = shift;<br>
    my $timeout = $self->opts->get('timeout');<br>
<br>
    return if ((! defined $timeout) || ($timeout < 1));<br>
<br>
    $SIG{'ALRM'} = sub {<br>
        $self->nagios_exit(UNKNOWN, "Plugin timeout (${timeout}s) exceeded!");<br>
    };<br>
<br>
    alarm($timeout);<br>
<br>
}<br>
<br>
# Reset the global counter<br>
sub reset_timer {<br>
    my $self = shift;<br>
    alarm(0);<br>
}<br>
<br>
------------------------------------------------------------------------------<br>
Enter the BlackBerry Developer Challenge<br>
This is your chance to win up to $100,000 in prizes! For a limited time,<br>
vendors submitting new applications to BlackBerry App World(TM) will have<br>
the opportunity to enter the BlackBerry Developer Challenge. See full prize<br>
details at: <a href="http://p.sf.net/sfu/Challenge" target="_blank">http://p.sf.net/sfu/Challenge</a><br>
_______________________________________________________<br>
Nagios Plugin Development Mailing List <a href="mailto:Nagiosplug-devel@lists.sourceforge.net">Nagiosplug-devel@lists.sourceforge.net</a><br>
Unsubscribe at <a href="https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel</a><br>
::: Please include plugins version (-v) and OS when reporting any issue.<br>
::: Messages without supporting info will risk being sent to /dev/null</blockquote></div>