Changeset 217


Ignore:
Timestamp:
Feb 18, 2017, 2:56:02 PM (8 years ago)
Author:
g7moreau
Message:
  • Return port ifIndex and not port index
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r216 r217  
    786786
    787787   my $swport_num = $swport_hr;
    788    return $swport_num if $swport_num =~ m/^\d+$/; # direct return if already numeric
     788   return $swport_num if $swport_num =~ m/^\d+$/; # direct return if already numeric (next loop is expensive)
    789789
    790790   my $research_index = $OID_NUMBER{ifIndex}; # base OID
    791791   my @args = ( -varbindlist =>  [$research_index]);
    792    LOOP_OID_PORT:
     792   LOOP_ON_OID_PORT:
    793793   while ( defined $snmp_session->get_next_request(@args) ) {
    794794      my ($oid_current) = $snmp_session->var_bind_names;
    795       last if  not Net::SNMP::oid_base_match($research_index, $oid_current);
     795      last LOOP_ON_OID_PORT if  not Net::SNMP::oid_base_match($research_index, $oid_current);
    796796     
    797797      my $port_ifIndex = $snmp_session->var_bind_list->{$oid_current};
     
    799799      printf "PORT1: %s => %s\n", $oid_current, $port_ifIndex if $verbose;
    800800
    801       # prepare next loop
     801      # prepare next loop item
    802802      @args = (-varbindlist => [$oid_current]);
    803803     
    804804      my $oid_ifName = $OID_NUMBER{ifName} .'.'. $port_ifIndex;
    805805      my $result = $snmp_session->get_request(-varbindlist => [$oid_ifName]);
    806       next LOOP_OID_PORT if not defined $result;
     806      next LOOP_ON_OID_PORT if not defined $result;
    807807     
    808808      my $current_port_hr = normalize_port_human_readable($result->{$oid_ifName});
     
    810810      if ($current_port_hr eq $swport_hr) {
    811811         print "PORT3: $current_port_hr <-> $port_index\n" if $verbose;
    812          $swport_num = $port_index;
    813          last LOOP_OID_PORT;
     812         
     813         # return port number ifIndex need by OID portUpDown
     814         $swport_num = $port_ifIndex; # other possible value could be $port_index
     815         last LOOP_ON_OID_PORT;
    814816         }
    815817      }
    816818   return $swport_num;
    817819   }
    818 
    819 #   $research_index = $OID_NUMBER{ifName}; # base OID
    820 #   @args = ( -varbindlist =>  [$research_index]);
    821 #   while ( defined $snmp_session->get_next_request(@args) ) {
    822 #      my ($oid_current) = $snmp_session->var_bind_names;
    823 #      last if not Net::SNMP::oid_base_match($research_index, $oid_current);
    824 #      my $current_port_hr = normalize_port_human_readable($snmp_session->var_bind_list->{$oid_current});
    825  #     printf "%s => %s\n", $oid_current, $current_port_hr;  # if $verbose;
    826 #      if ( $current_port_hr =~ m/$swport_hr/i ) {
    827 #         print "FIND PORT $current_port_hr  -- $swport_h\n";
    828 #         last
    829 #         }
    830 #      @args = (-varbindlist => [$oid_current]);
    831 #      }
    832 #   return;
    833 
    834 #   my $result_index = $snmp_session->get_bulk_request(
    835 #      -maxrepetitions   => 10,
    836 #      -varbindlist => [$research_index]
    837  #     );
    838 #   my $swifindex = $swport;
    839 #   $swifindex = $result_index->{$research_index} if defined $result_index;
    840 #
    841 #   my $research_hr = $OID_NUMBER{ifName} .'.'. $swifindex;
    842 #   my $result_hr = $snmp_session->get_request(
    843 #      -varbindlist => [$research_hr]
    844 #      );
    845 #   my $swport_hr = $swport;
    846 #   $swport_hr = normalize_port_human_readable($result_hr->{$research_hr}) if defined $result_hr;
    847 #   return $swport_hr;
    848 #   }
    849820
    850821# Load computer database
Note: See TracChangeset for help on using the changeset viewer.