Changeset 154


Ignore:
Timestamp:
Jun 8, 2016, 7:47:21 PM (8 years ago)
Author:
g7moreau
Message:
  • Push switch human readable patch on switch table
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r153 r154  
    425425
    426426      my $swport = $result->{$research1};
    427 
    428       my $research_hr = $OID_NUMBER{ifName} .'.'. $swport;
    429       $result = $session->get_request(
    430          -varbindlist => [$research_hr]
    431          );
    432       my $swport_hr = $swport;
    433       $swport_hr = get_port_human_readable_short($result->{$research_hr}) if defined $result;
     427      my $swport_hr = snmp_get_swithport_hr($session, $swport);
    434428
    435429      $session->close;
     
    467461   return $ret if $mac_address eq 'unknow';
    468462
    469 #   for my $sw (@SWITCH) {
    470 #      next if exists $SWITCH_PORT_COUNT{$sw->{hostname}};
    471 #
    472 #      $SWITCH_PORT_COUNT{$sw->{hostname}} = {};
    473 #      print "DEBUG: SWITCH_PORT_COUNT defined for $sw->{hostname}\n" if $DEBUG xor 2;
    474 #      }
    475 
    476463   my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address);
    477464   my $research2 = $OID_NUMBER{searchPort2} .'.'. $vlan_id . mac_address_hex_to_dec($mac_address);
     
    493480      if (defined $result and $result->{$research1} ne 'noSuchInstance') {
    494481         my $swport = $result->{$research1};
     482         my $swport_hr = snmp_get_swithport_hr($session, $swport);
    495483
    496484         $ret->{$sw->{hostname}} = {};
     
    498486         $ret->{$sw->{hostname}}{description} = $sw->{description};
    499487         $ret->{$sw->{hostname}}{port}        = get_human_readable_port($sw->{model}, $swport);
     488         $ret->{$sw->{hostname}}{port_hr}     = $swport_hr;
    500489
    501490#         $SWITCH_PORT_COUNT{$sw->{hostname}}->{$swport}++;
     
    679668
    680669   return $sw_port_hr;
     670   }
     671
     672sub snmp_get_swithport_hr {
     673   my ($snmp_session, $swport) = @_;
     674   
     675   my $research_hr = $OID_NUMBER{ifName} .'.'. $swport;
     676   $result = $snmp_session->get_request(
     677      -varbindlist => [$research_hr]
     678      );
     679   my $swport_hr = $swport;
     680   $swport_hr = get_port_human_readable_short($result->{$research_hr}) if defined $result;
     681   return $swport_hr;
    681682   }
    682683
     
    13231324      my $mac_sort = sprintf '%04i-%s', 9999, $mac_address;
    13241325
    1325       my ( $host_short ) = sprintf '%s %3s' , split(m/ \. /xms, $db_switch_parent{$sw}->{switch}, 1), $db_switch_parent{$sw}->{port};
     1326      my ( $host_short ) = sprintf '%s %3s' , split(m/ \. /xms, $db_switch_parent{$sw}->{switch}, 1), $db_switch_parent{$sw}->{port_hr};
    13261327
    13271328      print <<"END_HTML";
     
    13291330   <td sorttable_customkey="$switch_hostname_sort">$sw</td>
    13301331   <td class="bklask-port">$db_switch_output_port{$sw}</>
    1331    <td>+--> $db_switch_parent{$sw}->{port}</td>
     1332   <td>+--> $db_switch_parent{$sw}->{port_hr}</td>
    13321333   <td sorttable_customkey="$host_short">$db_switch_parent{$sw}->{switch}</>
    13331334   <td sorttable_customkey="$ip_sort">$ipv4_address</td>
     
    20022003         next ALL_SWITCH_CONNECTED if $switch->{port} eq '0';
    20032004
    2004          $db_switch_output_port{$switch->{hostname}} = $switch->{port};
    2005          print "VERBOSE_2: output port $switch->{hostname} : $switch->{port}\n" if $verbose;
     2005         $db_switch_output_port{$switch->{hostname}} = $switch->{port_hr};
     2006         print "VERBOSE_2: output port $switch->{hostname} : $switch->{port_hr}\n" if $verbose;
    20062007         }
    20072008      }
     
    20552056
    20562057         my $switch = $where{$ip}->{$switch_detected};
    2057          print "VERBOSE_6: $db_switch_ip_hostnamefq{$ip} -> $switch->{hostname} : $switch->{port}\n" if $verbose;
     2058         print "VERBOSE_6: $db_switch_ip_hostnamefq{$ip} -> $switch->{hostname} : $switch->{port_hr}\n" if $verbose;
    20582059
    20592060         next if $switch->{port}     eq '0';
    2060          next if $switch->{port}     eq $db_switch_output_port{$switch->{hostname}};
     2061         next if $switch->{port_hr}  eq $db_switch_output_port{$switch->{hostname}};
    20612062         next if $switch->{hostname} eq $db_switch_ip_hostnamefq{$ip}; # $computerdb->{$ip}{hostname};
    20622063
     
    21312132   for my $sw (sort keys %db_switch_output_port) {
    21322133      if (exists $db_switch_parent{$sw}) {
    2133          printf "%-28s  %2s  +-->  %2s  %-25s\n", $sw, $db_switch_output_port{$sw}, $db_switch_parent{$sw}->{port}, $db_switch_parent{$sw}->{switch};
     2134         printf "%-28s  %2s  +-->  %2s  %-25s\n", $sw, $db_switch_output_port{$sw}, $db_switch_parent{$sw}->{port_hr}, $db_switch_parent{$sw}->{switch};
    21342135         }
    21352136      else {
     
    21992200   for my $sw (sort keys %db_switch_output_port) {
    22002201      if (exists $db_switch_parent{$sw}) {
    2201          printf "%-28s  %2s  +-->  %2s  %-25s\n", $sw, $db_switch_output_port{$sw}, $db_switch_parent{$sw}->{port}, $db_switch_parent{$sw}->{switch};
     2202         printf "%-28s  %2s  +-->  %2s  %-25s\n", $sw, $db_switch_output_port{$sw}, $db_switch_parent{$sw}->{port_hr}, $db_switch_parent{$sw}->{switch};
    22022203         }
    22032204      else {
Note: See TracChangeset for help on using the changeset viewer.