Changeset 214


Ignore:
Timestamp:
Feb 18, 2017, 2:21:46 PM (8 years ago)
Author:
g7moreau
Message:
  • Normalize human readable port
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r213 r214  
    744744   }
    745745
    746 sub get_port_human_readable_short {
     746sub normalize_port_human_readable {
    747747   my $sw_port_hr  = shift;
    748748
     749   # Manufacturer abbreviation
    749750   $sw_port_hr =~ s/^Bridge-Aggregation/Br/i;
    750751   $sw_port_hr =~ s/^Port-Channel/Po/i;
     
    754755   $sw_port_hr =~ s/^FastEthernet/Fa/i;
    755756
     757   # Customer abbreviation
     758   $sw_port_hr =~ s/^Ten/Te/i;
     759   $sw_port_hr =~ s/^Giga/Gi/i;
     760
    756761   return $sw_port_hr;
    757762   }
     
    772777      );
    773778   my $swport_hr = $swport;
    774    $swport_hr = get_port_human_readable_short($result_hr->{$research_hr}) if defined $result_hr;
     779   $swport_hr = normalize_port_human_readable($result_hr->{$research_hr}) if defined $result_hr;
    775780   return $swport_hr;
    776781   }
     
    801806      next LOOP_OID_PORT if not defined $result;
    802807     
    803       my $current_port_hr = get_port_human_readable_short($result->{$oid_ifName});
     808      my $current_port_hr = normalize_port_human_readable($result->{$oid_ifName});
    804809      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;
     810      if ($current_port_hr eq $swport_hr) {
     811         print "PORT3: $current_port_hr <-> $port_index\n" if $verbose;
    807812         $swport_num = $port_index;
    808813         last LOOP_OID_PORT;
     
    817822#      my ($oid_current) = $snmp_session->var_bind_names;
    818823#      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});
     824#      my $current_port_hr = normalize_port_human_readable($snmp_session->var_bind_list->{$oid_current});
    820825 #     printf "%s => %s\n", $oid_current, $current_port_hr;  # if $verbose;
    821826#      if ( $current_port_hr =~ m/$swport_hr/i ) {
     
    839844#      );
    840845#   my $swport_hr = $swport;
    841 #   $swport_hr = get_port_human_readable_short($result_hr->{$research_hr}) if defined $result_hr;
     846#   $swport_hr = normalize_port_human_readable($result_hr->{$research_hr}) if defined $result_hr;
    842847#   return $swport_hr;
    843848#   }
     
    21382143
    21392144   # Retrieve numeric port value
    2140    my $port_num = snmp_get_switchport_num($session, $port, $verbose ? 'yes' : '');
     2145   my $port_num = snmp_get_switchport_num($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
    21412146   die "Error : Port $port not exist on switch $switch_name\n" if $port_num =~ m/^\d+$/;
    21422147
Note: See TracChangeset for help on using the changeset viewer.