Changeset 213
- Timestamp:
- Feb 18, 2017, 2:16:19 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r212 r213 776 776 } 777 777 778 # Reverse search port number 779 sub snmp_get_switchport_num { 780 my ($snmp_session, $swport_hr, $verbose) = @_; 781 782 my $swport_num = $swport_hr; 783 return $swport_num if $swport_num =~ m/^\d+$/; # direct return if already numeric 784 785 my $research_index = $OID_NUMBER{ifIndex}; # base OID 786 my @args = ( -varbindlist => [$research_index]); 787 LOOP_OID_PORT: 788 while ( defined $snmp_session->get_next_request(@args) ) { 789 my ($oid_current) = $snmp_session->var_bind_names; 790 last if not Net::SNMP::oid_base_match($research_index, $oid_current); 791 792 my $port_ifIndex = $snmp_session->var_bind_list->{$oid_current}; 793 my ($port_index) = reverse split /\./, $oid_current; # last number 794 printf "PORT1: %s => %s\n", $oid_current, $port_ifIndex if $verbose; 795 796 # prepare next loop 797 @args = (-varbindlist => [$oid_current]); 798 799 my $oid_ifName = $OID_NUMBER{ifName} .'.'. $port_ifIndex; 800 my $result = $snmp_session->get_request(-varbindlist => [$oid_ifName]); 801 next LOOP_OID_PORT if not defined $result; 802 803 my $current_port_hr = get_port_human_readable_short($result->{$oid_ifName}); 804 printf "PORT2: $oid_ifName => $current_port_hr\n" if $verbose; 805 if ( $current_port_hr =~ m/^$swport_hr$/i ) { 806 print "PORT3: $current_port_hr <-> $swport_hr\n" if $verbose; 807 $swport_num = $port_index; 808 last LOOP_OID_PORT; 809 } 810 } 811 return $swport_num; 812 } 813 814 # $research_index = $OID_NUMBER{ifName}; # base OID 815 # @args = ( -varbindlist => [$research_index]); 816 # while ( defined $snmp_session->get_next_request(@args) ) { 817 # my ($oid_current) = $snmp_session->var_bind_names; 818 # last if not Net::SNMP::oid_base_match($research_index, $oid_current); 819 # my $current_port_hr = get_port_human_readable_short($snmp_session->var_bind_list->{$oid_current}); 820 # printf "%s => %s\n", $oid_current, $current_port_hr; # if $verbose; 821 # if ( $current_port_hr =~ m/$swport_hr/i ) { 822 # print "FIND PORT $current_port_hr -- $swport_h\n"; 823 # last 824 # } 825 # @args = (-varbindlist => [$oid_current]); 826 # } 827 # return; 828 829 # my $result_index = $snmp_session->get_bulk_request( 830 # -maxrepetitions => 10, 831 # -varbindlist => [$research_index] 832 # ); 833 # my $swifindex = $swport; 834 # $swifindex = $result_index->{$research_index} if defined $result_index; 835 # 836 # my $research_hr = $OID_NUMBER{ifName} .'.'. $swifindex; 837 # my $result_hr = $snmp_session->get_request( 838 # -varbindlist => [$research_hr] 839 # ); 840 # my $swport_hr = $swport; 841 # $swport_hr = get_port_human_readable_short($result_hr->{$research_hr}) if defined $result_hr; 842 # return $swport_hr; 843 # } 844 778 845 # Load computer database 779 846 sub computerdb_load { … … 2038 2105 -varbindlist => [$search_portstatus, INTEGER, 2], 2039 2106 ); 2107 print $session->error()."\n" if $session->error_status(); 2040 2108 2041 2109 $session->close; … … 2065 2133 } 2066 2134 2067 my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port;2068 print "Info: switch $switch_name port $port SNMP OID $search_portstatus\n" if $verbose;2069 2070 2135 my $sw = $SWITCH_DB{$switch_name}; 2071 2136 my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} ); 2072 2137 print "$error \n" if $error; 2138 2139 # Retrieve numeric port value 2140 my $port_num = snmp_get_switchport_num($session, $port, $verbose ? 'yes' : ''); 2141 die "Error : Port $port not exist on switch $switch_name\n" if $port_num =~ m/^\d+$/; 2142 2143 my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_num; 2144 print "Info: switch $switch_name port $port ($port_num) SNMP OID $search_portstatus\n" if $verbose; 2073 2145 2074 2146 my $result = $session->get_request(
Note: See TracChangeset
for help on using the changeset viewer.