Changeset 277
- Timestamp:
- Sep 23, 2017, 10:42:06 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r276 r277 504 504 } 505 505 506 my $ research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);507 my $ research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address);506 my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address); 507 my $oid_search_port2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address); 508 508 509 509 LOOP_ON_SWITCH: … … 513 513 514 514 my $result = $session->get_request( 515 -varbindlist => [$ research1]515 -varbindlist => [$oid_search_port1] 516 516 ); 517 517 if (not defined $result) { 518 518 $result = $session->get_request( 519 -varbindlist => [$ research2]519 -varbindlist => [$oid_search_port2] 520 520 ); 521 $result->{$ research1} = $result->{$research2} if defined $result;522 } 523 524 if (not (defined $result and $result->{$ research1} ne 'noSuchInstance')) {521 $result->{$oid_search_port1} = $result->{$oid_search_port2} if defined $result; 522 } 523 524 if (not (defined $result and $result->{$oid_search_port1} ne 'noSuchInstance')) { 525 525 $session->close; 526 526 next LOOP_ON_SWITCH; 527 527 } 528 528 529 my $swport_id = $result->{$ research1};529 my $swport_id = $result->{$oid_search_port1}; 530 530 my $swport_hr = snmp_get_switchport_id2hr($session, $swport_id); 531 531 … … 565 565 return $ret if $mac_address eq 'unknow'; 566 566 567 my $ research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);568 my $ research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address);567 my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address); 568 my $oid_search_port2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address); 569 569 LOOP_ON_ALL_SWITCH: 570 570 for my $sw (@SWITCH_LIST) { … … 573 573 574 574 my $result = $session->get_request( 575 -varbindlist => [$ research1]575 -varbindlist => [$oid_search_port1] 576 576 ); 577 577 if (not defined $result) { 578 578 $result = $session->get_request( 579 -varbindlist => [$ research2]579 -varbindlist => [$oid_search_port2] 580 580 ); 581 $result->{$ research1} = $result->{$research2} if defined $result;582 } 583 584 if (defined $result and $result->{$ research1} ne 'noSuchInstance') {585 my $swport_id = $result->{$ research1};581 $result->{$oid_search_port1} = $result->{$oid_search_port2} if defined $result; 582 } 583 584 if (defined $result and $result->{$oid_search_port1} ne 'noSuchInstance') { 585 my $swport_id = $result->{$oid_search_port1}; 586 586 my $swport_hr = snmp_get_switchport_id2hr($session, $swport_id); 587 587 … … 723 723 # First get the index, second get the name (port_hr) 724 724 725 my $ research_ix = $OID_NUMBER{'ifIndex'} .'.'. $swport_id;725 my $oid_search_ix = $OID_NUMBER{'ifIndex'} .'.'. $swport_id; 726 726 my $result_ix = $snmp_session->get_request( 727 -varbindlist => [$ research_ix]727 -varbindlist => [$oid_search_ix] 728 728 ); 729 729 730 730 my $swport_ix = $swport_id; 731 $swport_ix = $result_ix->{$ research_ix} if defined $result_ix;731 $swport_ix = $result_ix->{$oid_search_ix} if defined $result_ix; 732 732 733 733 return snmp_get_switchport_ix2hr($snmp_session, $swport_ix); … … 738 738 my ($snmp_session, $swport_ix) = @_; 739 739 740 my $ research_hr = $OID_NUMBER{'ifName'} .'.'. $swport_ix;740 my $oid_search_hr = $OID_NUMBER{'ifName'} .'.'. $swport_ix; 741 741 my $result_hr = $snmp_session->get_request( 742 -varbindlist => [$ research_hr]742 -varbindlist => [$oid_search_hr] 743 743 ); 744 744 my $swport_hr = $swport_ix; 745 $swport_hr = normalize_port_human_readable($result_hr->{$ research_hr}) if defined $result_hr;745 $swport_hr = normalize_port_human_readable($result_hr->{$oid_search_hr}) if defined $result_hr; 746 746 747 747 # Aggregator port 748 748 if ($swport_hr =~ m/^(Trk|Br|Po)/) { 749 my $ research_index = $OID_NUMBER{'ifAggregator'}; # base OID750 my @args = ( -varbindlist => [$ research_index]);749 my $oid_search_index = $OID_NUMBER{'ifAggregator'}; # base OID 750 my @args = ( -varbindlist => [$oid_search_index]); 751 751 LOOP_ON_OID_PORT: 752 752 while ( defined $snmp_session->get_next_request(@args) ) { 753 753 my ($oid_current) = $snmp_session->var_bind_names; 754 last LOOP_ON_OID_PORT if not Net::SNMP::oid_base_match($ research_index, $oid_current);754 last LOOP_ON_OID_PORT if not Net::SNMP::oid_base_match($oid_search_index, $oid_current); 755 755 756 756 # IEEE8023-LAG-MIB::dot3adAggPortSelectedAggID.28 = INTEGER: 337 … … 785 785 return $swport_id if $swport_id =~ m/^\d+$/; 786 786 787 my $ research_ix = $OID_NUMBER{'ifIndex'}; # base OID788 my @args = ( -varbindlist => [$ research_ix]);787 my $oid_search_ix = $OID_NUMBER{'ifIndex'}; # base OID 788 my @args = ( -varbindlist => [$oid_search_ix]); 789 789 LOOP_ON_OID_PORT: 790 790 while ( defined $snmp_session->get_next_request(@args) ) { 791 791 my ($oid_current) = $snmp_session->var_bind_names; 792 last LOOP_ON_OID_PORT if not Net::SNMP::oid_base_match($ research_ix, $oid_current);792 last LOOP_ON_OID_PORT if not Net::SNMP::oid_base_match($oid_search_ix, $oid_current); 793 793 794 794 my $port_ifIndex = $snmp_session->var_bind_list->{$oid_current}; … … 799 799 @args = (-varbindlist => [$oid_current]); 800 800 801 my $oid_ ifName = $OID_NUMBER{'ifName'} .'.'. $port_ifIndex;802 my $result = $snmp_session->get_request(-varbindlist => [$oid_ ifName]);801 my $oid_search_ifName = $OID_NUMBER{'ifName'} .'.'. $port_ifIndex; 802 my $result = $snmp_session->get_request(-varbindlist => [$oid_search_ifName]); 803 803 next LOOP_ON_OID_PORT if not defined $result; 804 804 805 my $current_port_hr = normalize_port_human_readable($result->{$oid_ ifName});806 printf "PORT2: $oid_ ifName => $current_port_hr\n" if $verbose;805 my $current_port_hr = normalize_port_human_readable($result->{$oid_search_ifName}); 806 printf "PORT2: $oid_search_ifName => $current_port_hr\n" if $verbose; 807 807 if ($current_port_hr eq $swport_hr) { 808 808 print "PORT3: $current_port_hr <-> $port_ix\n" if $verbose; … … 823 823 my %vlandb = (); # Hash vlan number => vlan name 824 824 825 my $ research_index = $OID_NUMBER{'vlanName'}; # base OID826 my @args = ( -varbindlist => [$ research_index]);825 my $oid_search_index = $OID_NUMBER{'vlanName'}; # base OID 826 my @args = ( -varbindlist => [$oid_search_index]); 827 827 LOOP_ON_VLAN: 828 828 while ( defined $snmp_session->get_next_request(@args) ) { 829 829 my ($oid_current) = $snmp_session->var_bind_names; 830 last LOOP_ON_VLAN if not Net::SNMP::oid_base_match($ research_index, $oid_current);830 last LOOP_ON_VLAN if not Net::SNMP::oid_base_match($oid_search_index, $oid_current); 831 831 832 832 my $vlan_name = $snmp_session->var_bind_list->{$oid_current}; … … 1835 1835 } 1836 1836 1837 my $ search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number1837 my $oid_search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number 1838 1838 1839 1839 my $sw = $SWITCH_DB{$sw_name}; … … 1842 1842 1843 1843 my $result = $session->set_request( 1844 -varbindlist => [$ search, INTEGER, 8], # Only NEXANS1844 -varbindlist => [$oid_search, INTEGER, 8], # Only NEXANS 1845 1845 ); 1846 1846 print $session->error()."\n" if $session->error_status(); … … 1873 1873 } 1874 1874 1875 my $ search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number1875 my $oid_search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number 1876 1876 1877 1877 my $sw = $SWITCH_DB{$sw_name}; … … 1880 1880 1881 1881 my $result = $session->set_request( 1882 -varbindlist => [$ search, INTEGER, 2], # Only NEXANS1882 -varbindlist => [$oid_search, INTEGER, 2], # Only NEXANS 1883 1883 ); 1884 1884 print $session->error()."\n" if $session->error_status(); … … 1911 1911 } 1912 1912 1913 my $ search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number1913 my $oid_search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number 1914 1914 1915 1915 my $sw = $SWITCH_DB{$sw_name}; … … 1918 1918 1919 1919 my $result = $session->get_request( 1920 -varbindlist => [$ search],1920 -varbindlist => [$oid_search], 1921 1921 ); 1922 1922 1923 if (defined $result and $result->{$ search} ne 'noSuchInstance') {1924 my $poe_status = $result->{$ search} || 'empty';1923 if (defined $result and $result->{$oid_search} ne 'noSuchInstance') { 1924 my $poe_status = $result->{$oid_search} || 'empty'; 1925 1925 $poe_status =~ s/8/enable/; 1926 1926 $poe_status =~ s/2/disable/; … … 1953 1953 } 1954 1954 1955 my $ research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);1956 my $ research2 = $OID_NUMBER{'searchPort2'} .'.'. 0 . mac_address_hex2dec($mac_address);1957 print "Klask search OID $ research1 on switch $sw_name\n";1958 print "Klask search OID $ research2 on switch $sw_name\n";1955 my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address); 1956 my $oid_search_port2 = $OID_NUMBER{'searchPort2'} .'.'. 0 . mac_address_hex2dec($mac_address); 1957 print "Klask search OID $oid_search_port1 on switch $sw_name\n"; 1958 print "Klask search OID $oid_search_port2 on switch $sw_name\n"; 1959 1959 1960 1960 my $sw = $SWITCH_DB{$sw_name}; … … 1963 1963 1964 1964 my $result = $session->get_request( 1965 -varbindlist => [$ research1]1965 -varbindlist => [$oid_search_port1] 1966 1966 ); 1967 1967 if (not defined $result) { 1968 1968 $result = $session->get_request( 1969 -varbindlist => [$ research2]1969 -varbindlist => [$oid_search_port2] 1970 1970 ); 1971 $result->{$ research1} = $result->{$research2} if defined $result;1972 } 1973 1974 if (defined $result and $result->{$ research1} ne 'noSuchInstance') {1975 my $swport = $result->{$ research1};1971 $result->{$oid_search_port1} = $result->{$oid_search_port2} if defined $result; 1972 } 1973 1974 if (defined $result and $result->{$oid_search_port1} ne 'noSuchInstance') { 1975 my $swport = $result->{$oid_search_port1}; 1976 1976 print "Klask find MAC $mac_address on switch $sw_name port $swport\n"; 1977 1977 } … … 2006 2006 } 2007 2007 2008 my $ search = $OID_NUMBER{'vlanPortDefault'} . ".$switch_port";2008 my $oid_search = $OID_NUMBER{'vlanPortDefault'} . ".$switch_port"; 2009 2009 2010 2010 my $sw = $SWITCH_DB{$sw_name}; … … 2013 2013 2014 2014 my $result = $session->get_request( 2015 -varbindlist => [$ search],2015 -varbindlist => [$oid_search], 2016 2016 ); 2017 2017 2018 if (defined $result and $result->{$ search} ne 'noSuchInstance') {2019 my $vlan_id = $result->{$ search} || 'empty';2018 if (defined $result and $result->{$oid_search} ne 'noSuchInstance') { 2019 my $vlan_id = $result->{$oid_search} || 'empty'; 2020 2020 print "Klask VLAN Id $vlan_id on switch $sw_name on port $switch_port\n"; 2021 2021 } … … 2083 2083 } 2084 2084 2085 my $ search_vlan_name = $OID_NUMBER{'vlanName'} . ".$vlan_id";2085 my $oid_search_vlan_name = $OID_NUMBER{'vlanName'} . ".$vlan_id"; 2086 2086 2087 2087 my $sw = $SWITCH_DB{$sw_name}; … … 2090 2090 2091 2091 my $result = $session->get_request( 2092 -varbindlist => [$ search_vlan_name]2092 -varbindlist => [$oid_search_vlan_name] 2093 2093 ); 2094 2094 2095 if (defined $result and $result->{$ search_vlan_name} ne 'noSuchInstance') {2096 my $vlan_name = $result->{$ search_vlan_name} || 'empty';2095 if (defined $result and $result->{$oid_search_vlan_name} ne 'noSuchInstance') { 2096 my $vlan_name = $result->{$oid_search_vlan_name} || 'empty'; 2097 2097 print "Klask find VLAN $vlan_id on switch $sw_name with name $vlan_name\n"; 2098 2098 } … … 2333 2333 die "Error : Port $port_hr does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/; 2334 2334 2335 my $ search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;2336 print "Info: switch $switch_name port $port_hr SNMP OID $ search_portstatus\n" if $verbose;2335 my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id; 2336 print "Info: switch $switch_name port $port_hr SNMP OID $oid_search_portstatus\n" if $verbose; 2337 2337 2338 2338 my $result = $session->set_request( 2339 -varbindlist => [$ search_portstatus, INTEGER, 1],2339 -varbindlist => [$oid_search_portstatus, INTEGER, 1], 2340 2340 ); 2341 2341 print $session->error()."\n" if $session->error_status(); … … 2378 2378 die "Error : Port $port_hr does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/; 2379 2379 2380 my $ search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;2381 print "Info: switch $switch_name port $port_hr SNMP OID $ search_portstatus\n" if $verbose;2380 my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id; 2381 print "Info: switch $switch_name port $port_hr SNMP OID $oid_search_portstatus\n" if $verbose; 2382 2382 2383 2383 my $result = $session->set_request( 2384 -varbindlist => [$ search_portstatus, INTEGER, 2],2384 -varbindlist => [$oid_search_portstatus, INTEGER, 2], 2385 2385 ); 2386 2386 print $session->error()."\n" if $session->error_status(); … … 2421 2421 die "Error : Port $port_hr does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/; 2422 2422 2423 my $ search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;2424 print "Info: switch $switch_name port $port_hr ($port_id) SNMP OID $ search_portstatus\n" if $verbose;2423 my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id; 2424 print "Info: switch $switch_name port $port_hr ($port_id) SNMP OID $oid_search_portstatus\n" if $verbose; 2425 2425 2426 2426 my $result = $session->get_request( 2427 -varbindlist => [$ search_portstatus]2427 -varbindlist => [$oid_search_portstatus] 2428 2428 ); 2429 2429 print $session->error()."\n" if $session->error_status(); 2430 2430 if (defined $result) { 2431 print "$PORT_UPDOWN{$result->{$ search_portstatus}}\n";2431 print "$PORT_UPDOWN{$result->{$oid_search_portstatus}}\n"; 2432 2432 } 2433 2433 … … 2465 2465 } 2466 2466 2467 my $ research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);2468 my $ research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address);2469 print "Klask search OID $ research1 on switch $sw_name\n" if $verbose;2470 print "Klask search OID $ research2 on switch $sw_name\n" if $verbose;2467 my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address); 2468 my $oid_search_port2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address); 2469 print "Klask search OID $oid_search_port1 on switch $sw_name\n" if $verbose; 2470 print "Klask search OID $oid_search_port2 on switch $sw_name\n" if $verbose; 2471 2471 2472 2472 my $sw = $SWITCH_DB{$sw_name}; … … 2475 2475 2476 2476 my $result = $session->get_request( 2477 -varbindlist => [$ research1]2477 -varbindlist => [$oid_search_port1] 2478 2478 ); 2479 2479 if (not defined $result) { 2480 2480 $result = $session->get_request( 2481 -varbindlist => [$ research2]2481 -varbindlist => [$oid_search_port2] 2482 2482 ); 2483 $result->{$ research1} = $result->{$research2} if defined $result;2484 } 2485 2486 if (defined $result and $result->{$ research1} ne 'noSuchInstance') {2487 my $swport_id = $result->{$ research1};2483 $result->{$oid_search_port1} = $result->{$oid_search_port2} if defined $result; 2484 } 2485 2486 if (defined $result and $result->{$oid_search_port1} ne 'noSuchInstance') { 2487 my $swport_id = $result->{$oid_search_port1}; 2488 2488 my $swport_hr = snmp_get_switchport_id2hr($session, $swport_id); 2489 2489 print "Klask find MAC $mac_address on switch $sw_name port $swport_hr\n";
Note: See TracChangeset
for help on using the changeset viewer.