summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-09-20 15:23:38 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-09-20 15:23:38 +0200
commitad5456f6e5e3bf3850c431a2cc8a1104ba27925c (patch)
treec70a820100a6f90c2fa0791714bf55d9000ce2d4
parent54bea0ba4a9db77bebb6bc76ef8db43106a99b29 (diff)
downloadcheck-snmp-switch-ad5456f6e5e3bf3850c431a2cc8a1104ba27925c.tar.gz
check-snmp-switch-ad5456f6e5e3bf3850c431a2cc8a1104ba27925c.tar.bz2
check-snmp-switch-ad5456f6e5e3bf3850c431a2cc8a1104ba27925c.zip
add timeout
-rwxr-xr-xcheck_snmp_switch_traffic.pl13
1 files changed, 13 insertions, 0 deletions
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.