summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
authorMatthias Eble <psychotrahe@users.sourceforge.net>2008-10-22 21:35:15 (GMT)
committerMatthias Eble <psychotrahe@users.sourceforge.net>2008-10-22 21:35:15 (GMT)
commit96d628142872385215bbe4c535f3fcd1195505eb (patch)
tree69408680910e3726cc79fda4a27593b99b38de6d /plugins-scripts
parentab4deccff36c11614086dda8bbda57b5a9450edd (diff)
downloadmonitoring-plugins-96d628142872385215bbe4c535f3fcd1195505eb.tar.gz
check_ifoperstatus -n flag now works as expected (sf.net #1569488)
check_ifoperstatus now supports ifType based lookup for ifIndex git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2061 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts')
-rw-r--r--plugins-scripts/check_ifoperstatus.pl48
1 files changed, 29 insertions, 19 deletions
diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl
index 62891ff..75e852d 100644
--- a/plugins-scripts/check_ifoperstatus.pl
+++ b/plugins-scripts/check_ifoperstatus.pl
@@ -67,6 +67,7 @@ my $port = 161;
67my @snmpoids; 67my @snmpoids;
68my $sysUptime = '1.3.6.1.2.1.1.3.0'; 68my $sysUptime = '1.3.6.1.2.1.1.3.0';
69my $snmpIfDescr = '1.3.6.1.2.1.2.2.1.2'; 69my $snmpIfDescr = '1.3.6.1.2.1.2.2.1.2';
70my $snmpIfType = '1.3.6.1.2.1.2.2.1.3';
70my $snmpIfAdminStatus = '1.3.6.1.2.1.2.2.1.7'; 71my $snmpIfAdminStatus = '1.3.6.1.2.1.2.2.1.7';
71my $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8'; 72my $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8';
72my $snmpIfName = '1.3.6.1.2.1.31.1.1.1.1'; 73my $snmpIfName = '1.3.6.1.2.1.31.1.1.1.1';
@@ -83,6 +84,7 @@ my $ifXTable;
83my $opt_h ; 84my $opt_h ;
84my $opt_V ; 85my $opt_V ;
85my $ifdescr; 86my $ifdescr;
87my $iftype;
86my $key; 88my $key;
87my $lastc; 89my $lastc;
88my $dormantWarn; 90my $dormantWarn;
@@ -105,15 +107,18 @@ alarm($timeout);
105 107
106## map ifdescr to ifindex - should look at being able to cache this value 108## map ifdescr to ifindex - should look at being able to cache this value
107 109
108if (defined $ifdescr) { 110if (defined $ifdescr || defined $iftype) {
109 # escape "/" in ifdescr - very common in the Cisco world 111 # escape "/" in ifdescr - very common in the Cisco world
110 $ifdescr =~ s/\//\\\//g; 112 if (defined $iftype) {
111 113 $status=fetch_ifindex($snmpIfType, $iftype);
112 $status=fetch_ifdescr(); # if using on device with large number of interfaces 114 } else {
113 # recommend use of SNMP v2 (get-bulk) 115 $ifdescr =~ s/\//\\\//g;
116 $status=fetch_ifindex($snmpIfDescr, $ifdescr); # if using on device with large number of interfaces
117 # recommend use of SNMP v2 (get-bulk)
118 }
114 if ($status==0) { 119 if ($status==0) {
115 $state = "UNKNOWN"; 120 $state = "UNKNOWN";
116 printf "$state: could not retrive ifdescr snmpkey - $status-$snmpkey\n"; 121 printf "$state: could not retrive ifdescr/iftype snmpkey - $status-$snmpkey\n";
117 $session->close; 122 $session->close;
118 exit $ERRORS{$state}; 123 exit $ERRORS{$state};
119 } 124 }
@@ -152,10 +157,10 @@ push(@snmpoids,$snmpIfAlias) if (defined $ifXTable) ;
152 157
153 ## Check to see if ifName match is requested and it matches - exit if no match 158 ## Check to see if ifName match is requested and it matches - exit if no match
154 ## not the interface we want to monitor 159 ## not the interface we want to monitor
155 if ( defined $name && not ($response->{$snmpIfName} eq $name) ) { 160 if ( defined $ifName && not ($response->{$snmpIfName} eq $ifName) ) {
156 $state = 'UNKNOWN'; 161 $state = 'UNKNOWN';
157 $answer = "Interface name ($name) doesn't match snmp value ($response->{$snmpIfName}) (index $snmpkey)"; 162 $answer = "Interface name ($ifName) doesn't match snmp value ($response->{$snmpIfName}) (index $snmpkey)";
158 print ("$state: $answer"); 163 print ("$state: $answer\n");
159 exit $ERRORS{$state}; 164 exit $ERRORS{$state};
160 } 165 }
161 166
@@ -219,14 +224,17 @@ push(@snmpoids,$snmpIfAlias) if (defined $ifXTable) ;
219 224
220 225
221 226
222print ("$state: $answer"); 227print ("$state: $answer\n");
223exit $ERRORS{$state}; 228exit $ERRORS{$state};
224 229
225 230
226### subroutines 231### subroutines
227 232
228sub fetch_ifdescr { 233sub fetch_ifindex {
229 if (!defined ($response = $session->get_table($snmpIfDescr))) { 234 my $oid = shift;
235 my $lookup = shift;
236
237 if (!defined ($response = $session->get_table($oid))) {
230 $answer=$session->error; 238 $answer=$session->error;
231 $session->close; 239 $session->close;
232 $state = 'CRITICAL'; 240 $state = 'CRITICAL';
@@ -236,10 +244,10 @@ sub fetch_ifdescr {
236 } 244 }
237 245
238 foreach $key ( keys %{$response}) { 246 foreach $key ( keys %{$response}) {
239 if ($response->{$key} =~ /^$ifdescr$/) { 247 if ($response->{$key} =~ /^$lookup$/) {
240 $key =~ /.*\.(\d+)$/; 248 $key =~ /.*\.(\d+)$/;
241 $snmpkey = $1; 249 $snmpkey = $1;
242 #print "$ifdescr = $key / $snmpkey \n"; #debug 250 #print "$lookup = $key / $snmpkey \n"; #debug
243 } 251 }
244 } 252 }
245 unless (defined $snmpkey) { 253 unless (defined $snmpkey) {
@@ -288,6 +296,7 @@ sub print_help() {
288 printf " privacy password and authEngineID\n"; 296 printf " privacy password and authEngineID\n";
289 printf " -k (--key) SNMP IfIndex value\n"; 297 printf " -k (--key) SNMP IfIndex value\n";
290 printf " -d (--descr) SNMP ifDescr value\n"; 298 printf " -d (--descr) SNMP ifDescr value\n";
299 printf " -T (--type) SNMP ifType integer value (see http://www.iana.org/assignments/ianaiftype-mib)\n";
291 printf " -p (--port) SNMP port (default 161)\n"; 300 printf " -p (--port) SNMP port (default 161)\n";
292 printf " -I (--ifmib) Agent supports IFMIB ifXTable. Do not use if\n"; 301 printf " -I (--ifmib) Agent supports IFMIB ifXTable. Do not use if\n";
293 printf " you don't know what this is. \n"; 302 printf " you don't know what this is. \n";
@@ -299,8 +308,8 @@ sub print_help() {
299 printf " -t (--timeout) seconds before the plugin times out (default=$TIMEOUT)\n"; 308 printf " -t (--timeout) seconds before the plugin times out (default=$TIMEOUT)\n";
300 printf " -V (--version) Plugin version\n"; 309 printf " -V (--version) Plugin version\n";
301 printf " -h (--help) usage help \n\n"; 310 printf " -h (--help) usage help \n\n";
302 printf " -k or -d must be specified\n\n"; 311 printf " -k or -d or -T must be specified\n\n";
303 printf "Note: either -k or -d must be specified and -d is much more network \n"; 312 printf "Note: either -k or -d or -T must be specified and -d and -T are much more network \n";
304 printf "intensive. Use it sparingly or not at all. -n is used to match against\n"; 313 printf "intensive. Use it sparingly or not at all. -n is used to match against\n";
305 printf "a much more descriptive ifName value in the IfXTable to verify that the\n"; 314 printf "a much more descriptive ifName value in the IfXTable to verify that the\n";
306 printf "snmpkey has not changed to some other network interface after a reboot.\n\n"; 315 printf "snmpkey has not changed to some other network interface after a reboot.\n\n";
@@ -331,6 +340,7 @@ sub process_arguments() {
331 "D=s" => \$adminWarn, "admin-down=s" => \$adminWarn, 340 "D=s" => \$adminWarn, "admin-down=s" => \$adminWarn,
332 "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize, 341 "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize,
333 "t=i" => \$timeout, "timeout=i" => \$timeout, 342 "t=i" => \$timeout, "timeout=i" => \$timeout,
343 "T=i" => \$iftype, "type=i" => \$iftype,
334 ); 344 );
335 345
336 346
@@ -356,7 +366,7 @@ sub process_arguments() {
356 } 366 }
357 367
358 368
359 unless ($snmpkey > 0 || defined $ifdescr){ 369 unless ($snmpkey > 0 || defined $ifdescr || defined $iftype){
360 printf "Either a valid snmpkey key (-k) or a ifDescr (-d) must be provided)\n"; 370 printf "Either a valid snmpkey key (-k) or a ifDescr (-d) must be provided)\n";
361 usage(); 371 usage();
362 exit $ERRORS{"UNKNOWN"}; 372 exit $ERRORS{"UNKNOWN"};
@@ -451,7 +461,7 @@ sub process_arguments() {
451 if (!defined($session)) { 461 if (!defined($session)) {
452 $state='UNKNOWN'; 462 $state='UNKNOWN';
453 $answer=$error; 463 $answer=$error;
454 print ("$state: $answer"); 464 print ("$state: $answer\n");
455 exit $ERRORS{$state}; 465 exit $ERRORS{$state};
456 } 466 }
457 467
@@ -490,7 +500,7 @@ sub process_arguments() {
490 if (!defined($session)) { 500 if (!defined($session)) {
491 $state='UNKNOWN'; 501 $state='UNKNOWN';
492 $answer=$error; 502 $answer=$error;
493 print ("$state: $answer"); 503 print ("$state: $answer\n");
494 exit $ERRORS{$state}; 504 exit $ERRORS{$state};
495 } 505 }
496 506