Changeset 348


Ignore:
Timestamp:
Nov 1, 2017, 2:47:11 PM (6 years ago)
Author:
g7moreau
Message:
  • Error in web switch sort. Make a new function format_switchport4sort to cleanup code and debug error !
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r344 r348  
    501501
    502502#---------------------------------------------------------------
     503# port can be switch index or human readable
     504sub format_switchport4sort {
     505   my ($switch_name, $port) = @_;
     506
     507   # numeric port
     508   return sprintf '%s %09i', $switch_name, $port if $port =~ m{^\d+$};
     509
     510   # Gi3/0/14 type port
     511   if ($port =~ m{^(\w+?)(\d+)/(\d+)/(\d+)$}) {
     512      return sprintf '%s %03i%03i%03i', $switch_name, $2, $3, $4;
     513      }
     514
     515   # Gi3/14 type port
     516   if ($port =~ m{^(\w+?)(\d+)/(\d+)$}) {
     517      return sprintf '%s %06i%03i', $switch_name, $2, $3;
     518      }
     519
     520   # Po14 or A3 type port
     521   if ($port =~ m{^(\w+?)(\d+)(.*)$}) {
     522      return sprintf '%s %s%04i%s', $switch_name, $1, $2, $3;
     523      }
     524
     525   # otherwise
     526   return sprintf '%s %s', $switch_name, $port;
     527   }
     528
     529#---------------------------------------------------------------
    503530# fqdn_html_breakable change it's parameter, use it like chomp perl function
    504531
     
    17911818      my $switch_hostname = $computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'} || 'unkown';
    17921819      chomp $switch_hostname;
    1793       my $switch_hostname_sort = sprintf '%s %06i' ,$switch_hostname, $computerdb->{$ip}{'switch_port_id'}; # Take switch index
     1820      my $switch_hostname_sort = format_switchport4sort($switch_hostname, $computerdb->{$ip}{'switch_port_hr'});
    17941821
    17951822      my $ip_sort = sprintf '%03i%03i%03i%03i', split m/ \. /xms, $ip;
     
    18331860   for my $sw (sort keys %db_switch_output_port) {
    18341861
    1835       my $switch_hostname_sort = sprintf '%s %3s' ,$sw, $db_switch_output_port{$sw};
     1862      my $switch_hostname_sort = format_switchport4sort($sw, $db_switch_output_port{$sw});
    18361863
    18371864      $typerow = $typerow eq 'even' ? 'odd' : 'even';
     
    18601887         my $mac_sort = sprintf '%04i-%s', 9999, $mac_address;
    18611888
    1862          my ( $host_short ) = sprintf '%s %3s' , split(m/ \. /xms, $db_switch_parent{$sw}->{'switch'}, 1), $db_switch_parent{$sw}->{'port_hr'};
     1889         my $host_short = format_switchport4sort(split(m/ \. /xms, $db_switch_parent{$sw}->{'switch'}, 1), $db_switch_parent{$sw}->{'port_hr'});
    18631890
    18641891         my $vlan = $db_switch{$db_switch_parent{$sw}->{'switch'}}->{'network'};
     
    18881915         my $parent_port_hr = format_aggregator4html($db_switch_output_port{$sw});
    18891916
    1890          my $host_short = sprintf '%s %3s' ,$sw, $db_switch_output_port{$sw};
     1917         my $host_short = format_switchport4sort($sw, $db_switch_output_port{$sw});
    18911918
    18921919         my $mac_address = $db_switch{$sw}->{'mac_address'};
     
    19321959      for my $sw (keys %{$db_switch_connected_on_port{$swport}}) {
    19331960
    1934          my $switch_hostname_sort = sprintf '%s %3s' ,$sw_connect, $port_connect;
     1961         my $switch_hostname_sort = format_switchport4sort($sw_connect, $port_connect);
    19351962
    19361963         my $mac_address = $db_switch{$sw}->{'mac_address'};
     
    19591986         if (exists $db_switch_output_port{$sw}) {
    19601987
    1961             my ( $host_short ) = sprintf '%s %3s' , split( m/\./xms, $sw, 1), $db_switch_output_port{$sw};
     1988            my $host_short = format_switchport4sort(split( m/\./xms, $sw, 1), $db_switch_output_port{$sw});
    19621989
    19631990            my $parent_port_hr = format_aggregator4html($port_connect);
     
    22092236      $typerow = $typerow eq 'even' ? 'odd' : 'even';
    22102237
    2211       my $switch_hostname_sort = sprintf '%s %3s' ,$item->{'switch'}, $item->{'port_hr'};
     2238      my $switch_hostname_sort = format_switchport4sort($item->{'switch'}, $item->{'port_hr'});
    22122239      my ( $host_short ) = split m/ \. /xms, $item->{'hostname_fq'};
    22132240
Note: See TracChangeset for help on using the changeset viewer.