Changeset 244 for trunk/klask


Ignore:
Timestamp:
Sep 7, 2017, 10:53:00 PM (7 years ago)
Author:
g7moreau
Message:
  • Small code cleanning
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r243 r244  
    507507
    508508      my $swport_num = $result->{$research1};
    509       my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_hr($session, $swport_num));
     509      my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_num2hr($session, $swport_num));
    510510
    511511      $session->close;
     
    563563      if (defined $result and $result->{$research1} ne 'noSuchInstance') {
    564564         my $swport_num = $result->{$research1};
    565          my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_hr($session, $swport_num));
     565         my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_num2hr($session, $swport_num));
    566566
    567567         SWITCH_PORT_IGNORE:
     
    799799
    800800#---------------------------------------------------------------
    801 sub snmp_get_switchport_hr {
    802    my ($snmp_session, $swport_num, $flag) = @_;
     801sub snmp_get_switchport_num2hr {
     802   my ($snmp_session, $swport_num) = @_;
    803803
    804804   # On H3C, port number and port index are not the same
    805805   # Double SNMP request to get the name
    806    $flag ||= 'distinct';
     806
     807   my $research_index = $OID_NUMBER{ifIndex} .'.'. $swport_num;
     808   my $result_index = $snmp_session->get_request(
     809      -varbindlist => [$research_index]
     810      );
     811
    807812   my $swport_index = $swport_num;
    808 
    809    if ($flag eq 'distinct') {
    810       my $research_index = $OID_NUMBER{ifIndex} .'.'. $swport_num;
    811       my $result_index = $snmp_session->get_request(
    812          -varbindlist => [$research_index]
    813          );
    814       $swport_index = $result_index->{$research_index} if defined $result_index;
    815       }
     813   $swport_index = $result_index->{$research_index} if defined $result_index;
     814
     815   return snmp_get_switchport_index2hr($snmp_session, $swport_index);
     816   }
     817
     818#---------------------------------------------------------------
     819sub snmp_get_switchport_index2hr {
     820   my ($snmp_session, $swport_index) = @_;
    816821
    817822   my $research_hr = $OID_NUMBER{ifName} .'.'. $swport_index;
     
    842847         next LOOP_ON_OID_PORT if not $port_aggregator_index == $swport_index;
    843848
    844          my $current_port_name = snmp_get_switchport_hr($snmp_session, $current_port_index, 'index');
     849         my $current_port_name = snmp_get_switchport_index2hr($snmp_session, $current_port_index);
    845850         $swport_hr .= ":$current_port_name";
    846851         }
     
    851856#---------------------------------------------------------------
    852857# Reverse search port number
    853 sub snmp_get_switchport_num {
     858sub snmp_get_switchport_hr2num {
    854859   my ($snmp_session, $swport_hr, $verbose) = @_;
    855860
     
    23242329
    23252330   # Retrieve numeric port value
    2326    my $port_num = snmp_get_switchport_num($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
     2331   my $port_num = snmp_get_switchport_hr2num($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
    23272332   die "Error : Port $port does not exist on switch $switch_name\n" if not $port_num =~ m/^\d+$/;
    23282333
     
    23692374
    23702375   # Retrieve numeric port value
    2371    my $port_num = snmp_get_switchport_num($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
     2376   my $port_num = snmp_get_switchport_hr2num($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
    23722377   die "Error : Port $port does not exist on switch $switch_name\n" if not $port_num =~ m/^\d+$/;
    23732378
     
    24122417
    24132418   # Retrieve numeric port value
    2414    my $port_num = snmp_get_switchport_num($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
     2419   my $port_num = snmp_get_switchport_hr2num($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
    24152420   die "Error : Port $port does not exist on switch $switch_name\n" if not $port_num =~ m/^\d+$/;
    24162421
     
    24802485      if (defined $result and $result->{$research1} ne 'noSuchInstance') {
    24812486         my $swport_num = $result->{$research1};
    2482          my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_hr($session, $swport_num));
     2487         my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_num2hr($session, $swport_num));
    24832488         print "Klask find MAC $mac_address on switch $sw_name port $swport_hr\n";
    24842489         }
Note: See TracChangeset for help on using the changeset viewer.