From ad5456f6e5e3bf3850c431a2cc8a1104ba27925c Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 20 Sep 2013 15:23:38 +0200 Subject: add timeout --- check_snmp_switch_traffic.pl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/check_snmp_switch_traffic.pl b/check_snmp_switch_traffic.pl index b38dc58..d1e9194 100755 --- a/check_snmp_switch_traffic.pl +++ b/check_snmp_switch_traffic.pl @@ -109,17 +109,24 @@ sub nagios_die ($) { my $host; my $port = 161; my $community = 'public'; +my $timeout = 10; my $help = 0; Getopt::Long::Configure ("bundling"); GetOptions('host|H=s' => \$host, 'port|p=i' => \$port, 'community|C=s' => \$community, + 'timeout|t=i' => \$timeout, 'help|?' => \$help) or pod2usage(2); pod2usage(0) if $help; pod2usage(2) unless (defined $host); +$SIG{'ALRM'} = sub { + nagios_die('Check timed out'); +}; +alarm($timeout); + my ($session, $err) = Net::SNMP->session( -hostname => $host, -port => $port, @@ -154,6 +161,7 @@ check_snmp_swtich_traffic --host|-H HOSTNAME [options] --port|-p PORT --community|-C COMMUNITY + --timeout|-t TIMEOUT --help|-? =head1 OPTIONS @@ -172,6 +180,11 @@ Port to connect to. If not specified it defaults to 161. SNMPv1 Community string. If not specified it defaults to "public". +=item B<--timeout|-t> + +Maximum runtime in seconds of this script before returning UNKNOWN. +If not specified it defaults to 10. + =item B<--help|-?> Display a help message about the available options. -- cgit v1.2.3-1-g7c22