Bugfix: Better error handling when DNS resolve fails

This commit is contained in:
Páll Guðjón Sigurðsson 2010-08-03 20:17:00 +00:00
parent a94dec1228
commit 4d4c9cde73
1 changed files with 15 additions and 1 deletions

View File

@ -28,6 +28,7 @@
use lib qw ( /usr/local/nagios/perl/lib );
use Net::SNMP;
use Getopt::Std;
use Socket;
$script = "check_snmp_interfaces";
$script_version = "1.1";
@ -179,9 +180,10 @@ if ($opt_C) {
$community = $opt_C;
}
$exclude_interface = "bull";
if ($opt_E) {
if (defined($opt_E)) {
$exclude_interface = $opt_E;
}
if ($opt_w) {
$warning = $opt_w;
}
@ -205,6 +207,17 @@ $version = "1";
-timeout => $timeout,
);
if ( !defined($s) ) {
if (!gethostbyname($hostname)) {
print "Can't resolve $hostname !\n";
}
else {
print "Unable to establish SNMP session with $hostname !\n";
}
exit(1);
}
if ( !defined( $s->get_request($oid_sysDescr) ) ) {
# If we can't connect using SNMPv1 lets try as SNMPv2
@ -406,6 +419,7 @@ Usage: $script -H <hostname> -c <community> [...]
Options: -H Hostname or IP address
-C Community (default is public)
-B To use MIB designed for Brocade San switches
-E Exclude Regexp
-d Debug
-l Detailed Output (Long service output)