1a2,12 > # vim:foldmethod=syntax:tabstop=4:shiftwidth=4 > # > # matthew.martin, Tuesday August 14, 2007 > # Problems with check_ifstatus.pl > # 1) "No response from remote host" should be unknown, not critical, right? > # 2) Serial link "dormant" should be critical, not okay > # 3) dormant, excluded and unused interfaces are not correctly counted > # 4) default exclusions were broken, fix that and add a couple default exclusions > # 5) made the formatting in this file more consistent > # > # check_ifstatus.pl - nagios plugin 3,4d13 < # check_ifstatus.pl - nagios plugin < # 29c38 < # --- > # 36c45 < use lib "/opt/csw/libexec/nagios-plugins" ; --- > use lib "/opt/csw/libexec/nagios-plugins"; 49d57 < 94c102 < my %excluded ; --- > my %excluded; 97,100d104 < < < < 103,104c107,108 < print ("ERROR: No snmp response from $hostname (alarm timeout)\n"); < exit $ERRORS{"UNKNOWN"}; --- > print ("ERROR: No snmp response from $hostname (alarm timeout)\n"); > exit $ERRORS{"UNKNOWN"}; 107,108c111 < < #Option checking --- > # Option checking 111,112c114 < if ($status != 0) < { --- > if ($status != 0) { 117d118 < 127,129d127 < < < 131,135c129,135 < < if (!defined($response = $session->get_table($snmpoid))) { < $answer=$session->error; < $session->close; < $state = 'CRITICAL'; --- > if (!defined($response = $session->get_table($snmpoid))) { > $answer=$session->error; > $session->close; > # matthew.martin. Tuesday August 14, 2007 > # I think a SNMP error should give UNKNOWN, not CRITICAL > #$state = 'CRITICAL'; > $state = 'UNKNOWN'; 138c138 < }else{ --- > } else { 141,142c141,142 < exit $ERRORS{$state}; < } --- > exit $ERRORS{$state}; > } 144,148c144,148 < foreach $snmpkey (keys %{$response}) { < $snmpkey =~ /.*\.(\d+)$/; < $key = $1; < $ifStatus{$key}{$snmpoid} = $response->{$snmpkey}; < } --- > foreach $snmpkey (keys %{$response}) { > $snmpkey =~ /.*\.(\d+)$/; > $key = $1; > $ifStatus{$key}{$snmpoid} = $response->{$snmpkey}; > } 151d150 < 155a155,156 > # matthew.martin. This script cannot tell that specific logical interfaces are > # associated with their phys IF so it checks them all. 158c159,160 < # skip unused interfaces --- > # Skip interfaces flagged with -u (--unused_ports) > # "A comma separated list of ifIndex values that should be excluded" 160,163c162,166 < # check only if interface is administratively up < if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { < < # check only if interface type is not listed in %excluded --- > > # Further checking only if interface is administratively up > if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { > > # Check only if interface type is not listed in %excluded 170,172c173,175 < $ifStatus{$key}{$snmpIfName}, < $ifStatus{$key}{$snmpIfAlias}); < }else{ --- > $ifStatus{$key}{$snmpIfName}, > $ifStatus{$key}{$snmpIfAlias}); > } else { 174c177 < $ifStatus{$key}{$snmpIfDescr}); --- > $ifStatus{$key}{$snmpIfDescr}); 178c181,182 < }else{ --- > # matthew.martin Interface is listed in %excluded > } else { 181c185,187 < --- > # matthew.martin If not administratively up, mark as unused. > } elsif ($ifStatus{$key}{$snmpIfAdminStatus} == 2 ) { > $ifunused++; 183,184c189,195 < }else{ < $ifunused++; --- > } else { > # matthew.martin. Original line: > # $ifunused++; > # actually matches the flag > # -u (--unused_ports) A comma separated list of ifIndex values that should be excluded > # They should be marked as excluded, not unused. > $ifexclude++; 188,208c199,224 < if ($ifdown > 0) { < $state = 'CRITICAL'; < $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d
", < $hostname, < $ifup, < $ifdown, < $ifdormant, < $ifexclude, < $ifunused); < $answer = $answer . $ifmessage . "\n"; < } < else { < $state = 'OK'; < $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d", < $hostname, < $ifup, < $ifdown, < $ifdormant, < $ifexclude, < $ifunused); < } --- > # matthew.martin > # The original has dormant serial interfaces return status of "OK". > # A dormant serial connection should be CRITICAL, right? > # I changed the following line to address this: > #if ($ifdown > 0) { > if (($ifdown > 0) || ($ifdormant > 0)) { > $state = 'CRITICAL'; > $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d
", > $hostname, > $ifup, > $ifdown, > $ifdormant, > $ifexclude, > $ifunused); > $answer = $answer . $ifmessage . "\n"; > } else { > $state = 'OK'; > $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d", > $hostname, > $ifup, > $ifdown, > $ifdormant, > $ifexclude, > $ifunused); > } > 248c264 < printf " in hex with 0x prefix generated by using \"snmpkey\" utility\n"; --- > printf " in hex with 0x prefix generated by using \"snmpkey\" utility\n"; 252c268 < printf " in hex with 0x prefix generated by using \"snmpkey\" utility\n"; --- > printf " in hex with 0x prefix generated by using \"snmpkey\" utility\n"; 323c339 < }else{ --- > } else { 326c342 < }else{ --- > } else { 338c354 < }else{ --- > } else { 341c357 < }else{ --- > } else { 370,371d385 < }else{ < $excluded{23} = 1; # default PPP(23) if empty list - note (AIX seems to think PPP is 22 according to a post) 372a387,391 > # matthew.martin, Tuesday August 14, 2007. In the original this else was nested wrong and never matched > } else { > $excluded{23} = 1; # default PPP(23) if empty list - note (AIX seems to think PPP is 22 according to a post) > $excluded{24} = 1; # matthew.martin, Tuesday August 14, 2007, Nokia, ifDescr.6 = loop0c0 Software Loopback Layer -- ifType.6 = softwareLoopback(24) (taken from a Nokia IP330) > $excluded{25} = 1; # matthew.martin, Tuesday August 14, 2007, Nokia, ifDescr.1 = pppoe0 Ethernet Layer -- ifType.1 = eon(25) (from a Nokia IP350) 378c397 < foreach $key (@unused_ports) { --- > foreach $key (@unused_ports) { 392c411 < }else{ --- > } else { 450c469 < }else{ --- > } else {