Changeset 49 for trunk


Ignore:
Timestamp:
Jul 23, 2009, 1:12:12 AM (15 years ago)
Author:
g7moreau
Message:
  • Suppress old code
  • Suppress old comment
  • Update year copyright
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r48 r49  
    2929my $KLASK_CFG = YAML::Syck::LoadFile("$KLASK_CFG_FILE");
    3030
    31 my %DEFAULT = %{$KLASK_CFG->{default}};
    32 my @SWITCH  = @{$KLASK_CFG->{switch}};
     31my %DEFAULT = %{ $KLASK_CFG->{default} };
     32my @SWITCH  = @{ $KLASK_CFG->{switch}  };
    3333
    3434my %switch_level = ();
    35 my %SWITCH_DB = ();
     35my %SWITCH_DB    = ();
    3636LEVEL_OF_EACH_SWITCH:
    3737for my $sw (@SWITCH){
     
    3939   $SWITCH_DB{$sw->{hostname}} = $sw;
    4040   }
    41 @SWITCH = sort { $switch_level{$b->{hostname}} <=> $switch_level{$a->{hostname}} } @{$KLASK_CFG->{switch}}; 
     41@SWITCH = sort { $switch_level{$b->{hostname}} <=> $switch_level{$a->{hostname}} } @{$KLASK_CFG->{switch}};
    4242
    4343my %SWITCH_PORT_COUNT = ();
     
    8787   BS350T => { model => 'BS350T',     match => 'BayStack 350T HW'                },
    8888   );
    89  
     89
    9090my %OID_NUMBER = (
    91    sysDescr    => '1.3.6.1.2.1.1.1.0',
     91   sysDescription    => '1.3.6.1.2.1.1.1.0',
    9292   sysName     => '1.3.6.1.2.1.1.5.0',
    9393   sysContact  => '1.3.6.1.2.1.1.4.0',
     
    163163   my ($arp, $ip, $timestamp, $host) = split /\s+/, $cmd_arpwatch;
    164164
    165 #print "OOO $cmd\n";
    166 #print "TTT arp $arp -> $ip pour host $host\n";
    167 
    168165   $ret{ipv4_address} = $ip        if $ip;
    169166   $ret{mac_address}  = $arp       if $arp;
     
    177174      }
    178175
    179   # resultat de la commande arp
     176   # resultat de la commande arp
    180177   # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0
    181178   # sw2-batF0-legi.hmg.priv (192.168.22.112) at 00:30:c1:76:9c:01 [ether] on eth0.37
     
    186183   $ret{ipv4_address} = $2 if(defined($2));
    187184   $ret{mac_address}  = $3 if(defined($3));
    188 #print "RET1 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n";
    189 
    190 #   if ($ret{ipv4_address} eq '0.0.0.0' and $ret{mac_address} eq 'unknow'and $ret{hostname_fq} eq 'unknow') {
    191       # resultat de la commande host si le parametre est ip
    192       # 250.66.254.194.in-addr.arpa domain name pointer legihp2100.hmg.inpg.fr.
    193       my $cmd_host = `host $param_ip_or_host 2>/dev/null`;
    194       chomp $cmd_host;
    195       $cmd_host =~ m/domain\sname\spointer\s(\S+)\.$/;
    196       $ret{hostname_fq} = $1 if defined $1;
    197 
    198       # resultat de la commande host si parametre est hostname
    199       # tech7meylan.hmg.inpg.fr has address 194.254.66.240
    200       $cmd_host =~ m/(\S*)\shas\saddress\s([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/;
    201       $ret{hostname_fq}  = $1 if defined $1;
    202       $ret{ipv4_address} = $2 if defined $2;
    203 
    204       $cmd_host =~ m/\b([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.in-addr\.arpa\s/;
    205       $ret{ipv4_address} = "$4.$3.$2.$1"     if defined $1 and  defined $2 and  defined $3 and  defined $4;
    206       $ret{hostname_fq}  = $param_ip_or_host if not defined $1 and $ret{hostname_fq} eq 'unknow';
    207 #      }
    208 
    209 #print "RET2 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n";
     185
     186   # resultat de la commande host si le parametre est ip
     187   # 250.66.254.194.in-addr.arpa domain name pointer legihp2100.hmg.inpg.fr.
     188   my $cmd_host = `host $param_ip_or_host 2>/dev/null`;
     189   chomp $cmd_host;
     190   $cmd_host =~ m/domain\sname\spointer\s(\S+)\.$/;
     191   $ret{hostname_fq} = $1 if defined $1;
     192
     193   # resultat de la commande host si parametre est hostname
     194   # tech7meylan.hmg.inpg.fr has address 194.254.66.240
     195   $cmd_host =~ m/(\S*)\shas\saddress\s([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/;
     196   $ret{hostname_fq}  = $1 if defined $1;
     197   $ret{ipv4_address} = $2 if defined $2;
     198
     199   $cmd_host =~ m/\b([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.in-addr\.arpa\s/;
     200   $ret{ipv4_address} = "$4.$3.$2.$1"     if defined $1 and  defined $2 and  defined $3 and  defined $4;
     201   $ret{hostname_fq}  = $param_ip_or_host if not defined $1 and $ret{hostname_fq} eq 'unknow';
     202
    210203   unless ($ret{mac_address} eq 'unknow') {
    211204      my @paquets = ();
     
    217210      }
    218211
    219 #print "RET3 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n";
    220212   return %ret;
    221213   }
     
    224216sub get_switch_model {
    225217   my $sw_snmp_description = shift || 'unknow';
    226    
     218
    227219   for my $sw_kind (keys %SWITCH_KIND) {
    228220      next if not $sw_snmp_description =~ m/$SWITCH_KIND{$sw_kind}->{match}/;
    229      
     221
    230222      return $SWITCH_KIND{$sw_kind}->{model};
    231223      }
    232      
     224
    233225   return $sw_snmp_description;
    234226   }
     
    238230sub init_switch_names {
    239231   my $verbose = shift;
    240    
     232
    241233   printf "%-25s                %-25s %s\n",'Switch','Description','Type';
    242234#   print "Switch description\n" if $verbose;
     
    262254      my $result = $session->get_request(
    263255         -varbindlist => [
    264             $OID_NUMBER{sysDescr},
     256            $OID_NUMBER{sysDescription},
    265257            $OID_NUMBER{sysName},
    266258            $OID_NUMBER{sysContact},
     
    269261         );
    270262      $sw->{description} = $result->{$OID_NUMBER{sysName}} || $sw->{hostname};
    271       $sw->{model} = get_switch_model( $result->{$OID_NUMBER{sysDescr}});
     263      $sw->{model} = get_switch_model( $result->{$OID_NUMBER{sysDescription}});
    272264      #$sw->{location} = $result->{"1.3.6.1.2.1.1.6.0"} || $sw->{hostname};
    273265      #$sw->{contact} = $result->{"1.3.6.1.2.1.1.4.0"} || $sw->{hostname};
    274266      $session->close;
    275267
    276       # Ligne à virer car on récupère maintenant le modèle du switch 
     268      # Ligne à virer car on récupère maintenant le modèle du switch
    277269      my ($desc, $type) = split ':', $sw->{description}, 2;
    278 #      printf "%-25s 0--------->>>> %-25s %s\n", $sw->{hostname}, $desc, uc($type)."**" if $verbose;
    279270      printf "%-25s 0--------->>>> %-25s %s\n", $sw->{hostname}, $desc, $sw->{model} if $verbose;
    280271      }
     
    292283   return '00' if $car eq '00UNKNOW';
    293284   my %table = (
    294       "0"=>"0",  "1"=>"1",  "2"=>"2",  "3"=>"3",  "4"=>"4",  "5"=>"5", "6"=>"6", "7"=>"7", "8"=>"8", "9"=>"9",
     285      "0"=>"0",  "1"=>"1",  "2"=>"2",  "3"=>"3",  "4"=>"4",
     286      "5"=>"5",  "6"=>"6",  "7"=>"7",  "8"=>"8",  "9"=>"9",
    295287      "A"=>"10", "B"=>"11", "C"=>"12", "D"=>"13", "E"=>"14", "F"=>"15"
    296288      );
    297    my @chars = split(//, $car);
     289   my @chars = split //, $car;
    298290   return $table{$chars[-2]}*16 + $table{$chars[-1]};
    299291   }
     
    316308# va rechercher le port et le switch sur lequel est la machine
    317309sub find_switch_port {
    318    my $arp = shift;
     310   my $arp             = shift;
    319311   my $switch_proposal = shift || '';
    320    
     312
    321313   my %ret;
    322314   $ret{switch_description} = "unknow";
     
    335327
    336328   my $research = "1.3.6.1.2.1.17.4.3.1.2".arp_hex_to_dec($arp);
    337    
     329
    338330   LOOP_ON_SWITCH:
    339331   for my $sw (@switch_search) {
     
    353345
    354346         # IMPORTANT !!
    355          # ceci empeche la detection sur certains port ... 
     347         # ceci empeche la detection sur certains port ...
    356348         # en effet les switch sont relies entre eux par un cable reseau et du coup
    357349         # tous les arp de toutes les machines sont presentes sur ces ports (ceux choisis ici sont les miens)
     
    369361            $ret{switch_description} = $sw->{description};
    370362            $ret{switch_port}        = get_human_readable_port($sw->{model}, $swport); # $swport;
    371            
     363
    372364            last LOOP_ON_SWITCH;
    373365#            }
     
    427419   return $KLASK_CFG->{network}{$network}{interface};
    428420   }
    429  
     421
    430422###
    431423# liste l'ensemble des adresses ip d'un réseau
     
    473465   my $sw_model = shift;
    474466   my $sw_port  = shift;
    475    
     467
    476468   return $sw_port if not $sw_model eq 'HP8000M';
    477    
     469
    478470   my $reste = (($sw_port - 1) % 8) + 1;
    479471   my $major = int( ($sw_port - 1) / 8 );
     
    485477   my $sw_model = shift;
    486478   my $sw_port  = shift;
    487    
     479
    488480   return $sw_port if not $sw_model eq 'HP8000';
    489481
    490482   my $letter = substr($sw_port, 0, 1);
    491    
     483
    492484#   return $port if $letter =~ m/\d/;
    493    
     485
    494486   my $reste =  substr($sw_port, 1);
    495    
     487
    496488   return $INTERNAL_PORT_MAP_REV{$letter} * 8 + $reste;
    497489   }
     
    537529sub cmd_search {
    538530   my @computer = @_;
    539    
     531
    540532   init_switch_names();    #nomme les switchs
    541533   fastping(@computer);
     
    554546   fastping(@computer);
    555547   my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
    556    
     548
    557549   LOOP_ON_COMPUTER:
    558550   for my $clientname (@computer) {
    559551      my %resol_arp = resolve_ip_arp_host($clientname);      #resolution arp
    560552      my $ip = $resol_arp{ipv4_address};
    561      
     553
    562554      next LOOP_ON_COMPUTER unless exists $computerdb->{$ip};
    563      
     555
    564556      my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($computerdb->{$ip}{timestamp});
    565557      $year += 1900;
     
    604596   my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}};
    605597   my %db_switch_chained_port = ();
    606    for my $swport (keys %db_switch_connected_on_port) {       
     598   for my $swport (keys %db_switch_connected_on_port) {
    607599      my ($sw_connect,$port_connect) = split ':', $swport;
    608600      $db_switch_chained_port{$sw_connect} .= "$port_connect:";
     
    637629      for my $one_computer (@computer) {
    638630         $i++;
    639          
     631
    640632         my $total_percent = int(($i*100)/$number_of_computer);
    641633
     
    655647
    656648         my %resol_arp = resolve_ip_arp_host($one_computer,$current_interface);
    657          
     649
    658650         # do not search on router connection (why ?)
    659651         if ( exists $router_mac_ip{$resol_arp{mac_address}}) {
     
    725717         # mise a jour du nom de la machine si modification dans le dns
    726718         $computerdb->{$resol_arp{ipv4_address}}{hostname_fq} = $resol_arp{hostname_fq};
    727        
     719
    728720         # mise à jour de la date de détection si détection plus récente par arpwatch
    729721         $computerdb->{$resol_arp{ipv4_address}}{timestamp}   = $resol_arp{timestamp} if exists $resol_arp{timestamp} and $computerdb->{$resol_arp{ipv4_address}}{timestamp} < $resol_arp{timestamp};
    730722
    731          # provisoire car changement de nom des attributs
    732 #         $computerdb->{$resol_arp{ipv4_address}}{mac_address}        = $computerdb->{$resol_arp{ipv4_address}}{arp};
    733 #         $computerdb->{$resol_arp{ipv4_address}}{switch_description} = $computerdb->{$resol_arp{ipv4_address}}{switch};
    734 #         $computerdb->{$resol_arp{ipv4_address}}{switch_port}        = $computerdb->{$resol_arp{ipv4_address}}{port};
    735        
    736723         # relance un arping sur la machine si celle-ci n'a pas été détectée depuis plus d'une semaine
    737724#         push @computer_not_detected, $resol_arp{ipv4_address} if $computerdb->{$resol_arp{ipv4_address}}{timestamp} < $timestamp_last_week;
    738725         $computer_not_detected{$resol_arp{ipv4_address}} = $current_interface if $computerdb->{$resol_arp{ipv4_address}}{timestamp} < $timestamp_last_week;
    739        
     726
    740727         }
    741728      }
     
    794781
    795782   $format = 'txt' if not defined $possible_format{$format};
    796    
     783
    797784   $possible_format{$format}->(@ARGV);
    798785   return;
     
    809796   LOOP_ON_IP_ADDRESS:
    810797   foreach my $ip (Net::Netmask::sort_by_ip_address(keys %$computerdb)) {
    811    
     798
    812799#      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq 'unknow';
    813800
     
    817804# dans le futur
    818805#      next if $computerdb->{$ip}{hostname_fq} eq 'unknow';
    819      
     806
    820807      my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($computerdb->{$ip}{timestamp});
    821808      $year += 1900;
     
    873860   LOOP_ON_IP_ADDRESS:
    874861   foreach my $ip (keys %$computerdb) {
    875    
     862
    876863      # to be improve in the future
    877864      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}); # switch on himself !
    878      
     865
    879866      $mac_count{$computerdb->{$ip}{mac_address}}++;
    880867      }
     
    884871   LOOP_ON_IP_ADDRESS:
    885872   foreach my $ip (Net::Netmask::sort_by_ip_address(keys %$computerdb)) {
    886    
     873
    887874      # to be improve in the future
    888875      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}); # switch on himself !
     
    895882#      $odd_or_even++;
    896883#      my $typerow = $odd_or_even % 2 ? 'odd' : 'even';
    897       $typerow = $typerow eq 'even' ? 'odd' : 'even'; 
     884      $typerow = $typerow eq 'even' ? 'odd' : 'even';
    898885
    899886      my $switch_hostname = $computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description} || 'unkown';
     
    932919      my $switch_hostname_sort = sprintf "%s %3s" ,$sw, $db_switch_output_port{$sw};
    933920
    934       $typerow = $typerow eq 'even' ? 'odd' : 'even'; 
     921      $typerow = $typerow eq 'even' ? 'odd' : 'even';
    935922
    936923      if (exists $db_switch_parent{$sw}) {
     
    949936      my $mac_sort = sprintf "%04i-%s", 9999, $mac_address;
    950937
    951 
    952          my ( $host_short ) = sprintf "%s %3s" , split(/\./, $db_switch_parent{$sw}->{switch}, 1), $db_switch_parent{$sw}->{port};
    953 
    954 print <<"END_HTML";
     938      my ( $host_short ) = sprintf "%s %3s" , split(/\./, $db_switch_parent{$sw}->{switch}, 1), $db_switch_parent{$sw}->{port};
     939
     940      print <<"END_HTML";
    955941  <tr class="$typerow">
    956942   <td sorttable_customkey="$switch_hostname_sort">$sw</td>
     
    965951         }
    966952      else {
    967 #         printf "%-25s  %2s  +-->  router\n", $sw, $db_switch_output_port{$sw};
    968 print <<"END_HTML";
     953         print <<"END_HTML";
    969954  <tr class="$typerow">
    970955   <td sorttable_customkey="$switch_hostname_sort">$sw</td>
     
    999984      my $mac_sort = sprintf "%04i-%s", 9999, $mac_address;
    1000985
    1001       $typerow = $typerow eq 'even' ? 'odd' : 'even'; 
     986      $typerow = $typerow eq 'even' ? 'odd' : 'even';
    1002987
    1003988         if (exists $db_switch_output_port{$sw}) {
    1004989
    1005              my ( $host_short ) = sprintf "%s %3s" , split(/\./, $sw, 1), $db_switch_output_port{$sw};
    1006 
    1007 print <<"END_HTML";
     990            my ( $host_short ) = sprintf "%s %3s" , split(/\./, $sw, 1), $db_switch_output_port{$sw};
     991
     992            print <<"END_HTML";
    1008993  <tr class="$typerow">
    1009994   <td sorttable_customkey="$switch_hostname_sort">$sw_connect</td>
     
    10181003            }
    10191004         else {
    1020 print <<"END_HTML";
     1005            print <<"END_HTML";
    10211006  <tr class="$typerow">
    10221007   <td sorttable_customkey="$switch_hostname_sort">$sw_connect</td>
     
    10331018      }
    10341019
    1035 
    10361020   print <<'END_HTML';
    10371021 </tbody>
     
    10511035      my $sw_hostname = $computerdb->{$ip}{switch_hostname} || '';
    10521036      next if $sw_hostname eq 'unknow';
    1053  
     1037
    10541038      my $sw_location = '';
    10551039      for my $sw (@SWITCH) {
     
    10671051   my $switch = shift;
    10681052   my $port   = shift;
    1069    
    1070    #snmpset -v 1 -c community X.X.X.X 1.3.6.1.2.1.2.2.1.7.NoPort = 1 (up) 
    1071    #snmpset -v 1 -c community X.X.X.X 1.3.6.1.2.1.2.2.1.7.NoPort = 2 (down) 
     1053
     1054   #snmpset -v 1 -c community X.X.X.X 1.3.6.1.2.1.2.2.1.7.NoPort = 1 (up)
     1055   #snmpset -v 1 -c community X.X.X.X 1.3.6.1.2.1.2.2.1.7.NoPort = 2 (down)
    10721056   system "snmpset -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port = 1";
    10731057   return;
     
    10771061   my $switch = shift;
    10781062   my $port   = shift;
    1079    
     1063
    10801064   system "snmpset -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port = 2";
    10811065   return;
     
    10851069   my $switch = shift;
    10861070   my $port   = shift;
    1087    
     1071
    10881072   system "snmpget -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port";
    10891073   return;
     
    10931077   my $switch_name = shift || '';
    10941078   my $mac_address = shift || '';
    1095    
     1079
    10961080   if ($switch_name eq '' or $mac_address eq '') {
    10971081      die "Usage: klask search-mac-on-switch SWITCH_NAME MAC_ADDRESS\n";
     
    10991083
    11001084   if (not defined $SWITCH_DB{$switch_name}) {
    1101       die "Switch $switch_name must be defined in klask configuration file\n"; 
     1085      die "Switch $switch_name must be defined in klask configuration file\n";
    11021086      }
    11031087
     
    11221106      -varbindlist => [$research]
    11231107      );
    1124    
     1108
    11251109   if (not defined($result) or $result->{$research} eq 'noSuchInstance') {
    11261110      print "Klask do not find MAC $mac_address on switch $switch_name\n";
     
    11471131#   for my $one_computer ('194.254.66.254') {
    11481132   for my $one_router ( get_list_main_router(get_list_network()) ) {
    1149 #print "TT$one_router\n";     
    11501133      my %resol_arp = resolve_ip_arp_host($one_router,'*','low');            # resolution arp
    11511134      next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow';
    1152 #print "$one_router\n";     
    11531135      $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements des routeurs
    11541136      }
     
    11561138   ALL_ROUTER_IP_ADDRESS:
    11571139   for my $ip (Net::Netmask::sort_by_ip_address(keys %where)) { # '194.254.66.254')) {
    1158    
     1140
    11591141      next ALL_ROUTER_IP_ADDRESS if not exists $where{$ip}; # /a priori/ idiot car ne sers à rien...
    11601142
     
    11651147
    11661148         next ALL_SWITCH_CONNECTED if $switch->{port} eq '0';
    1167          
     1149
    11681150         $db_switch_output_port{$switch->{hostname}} = $switch->{port};
    11691151         }
    1170       }   
    1171 
    1172 #   print "Switch output port\n"; 
    1173 #   print "------------------\n";
    1174 #   for my $sw (sort keys %db_switch_output_port) {
    1175 #      printf "%-25s %2s\n", $sw, $db_switch_output_port{$sw};
    1176 #      }
    1177 #   print "\n";
    1178 
     1152      }
    11791153
    11801154   my %db_switch_link_with = ();
     
    11921166      my %resol_arp = resolve_ip_arp_host($one_computer,'*','low'); # arp resolution
    11931167      next ALL_SWITCH if $resol_arp{mac_address} eq 'unknow';
    1194      
     1168
    11951169      push @list_switch_ipv4,$resol_arp{ipv4_address};
    1196      
     1170
    11971171      $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # find port on all switch
    11981172
     
    12031177      $SWITCH_DB{$one_computer}->{timestamp}    = $timestamp;
    12041178      }
    1205      
     1179
    12061180   ALL_SWITCH_IP_ADDRESS:
    12071181   for my $ip (Net::Netmask::sort_by_ip_address(@list_switch_ipv4)) {
    1208    
     1182
    12091183      next ALL_SWITCH_IP_ADDRESS if not exists $where{$ip};
    12101184
     
    12251199
    12261200      }
    1227    
     1201
    12281202   my %db_switch_connected_on_port = ();
    12291203   my $maybe_more_than_one_switch_connected = 'yes';
    1230    
     1204
    12311205   while ($maybe_more_than_one_switch_connected eq 'yes') {
    12321206      for my $sw (keys %db_switch_link_with) {
    12331207         for my $connect (keys %{$db_switch_link_with{$sw}}) {
    1234          
     1208
    12351209            my $port = $db_switch_link_with{$sw}->{$connect};
    1236          
     1210
    12371211            $db_switch_connected_on_port{"$connect:$port"} ||= {};
    12381212            $db_switch_connected_on_port{"$connect:$port"}->{$sw}++; # Just to define the key
     
    12441218      SWITCH_AND_PORT:
    12451219      for my $swport (keys %db_switch_connected_on_port) {
    1246          
     1220
    12471221         next if keys %{$db_switch_connected_on_port{$swport}} == 1;
    1248          
     1222
    12491223         $maybe_more_than_one_switch_connected = 'yes';
    12501224
     
    12541228         CONNECTED:
    12551229         for my $sw_connected (@sw_on_same_port) {
    1256            
     1230
    12571231            next CONNECTED if not keys %{$db_switch_link_with{$sw_connected}} == 1;
    1258            
     1232
    12591233            $db_switch_connected_on_port{$swport} = {$sw_connected => 1};
    1260            
     1234
    12611235            for my $other_sw (@sw_on_same_port) {
    12621236               next if $other_sw eq $sw_connected;
    1263                
     1237
    12641238               delete $db_switch_link_with{$other_sw}->{$sw_connect};
    12651239               }
    1266            
     1240
    12671241            # We can not do better for this switch for this loop
    12681242            next SWITCH_AND_PORT;
     
    12751249   for my $sw (keys %db_switch_link_with) {
    12761250      for my $connect (keys %{$db_switch_link_with{$sw}}) {
    1277      
     1251
    12781252         my $port = $db_switch_link_with{$sw}->{$connect};
    1279      
     1253
    12801254         $db_switch_connected_on_port{"$connect:$port"} ||= {};
    12811255         $db_switch_connected_on_port{"$connect:$port"}->{$sw} = $port;
    1282        
     1256
    12831257         $db_switch_parent{$sw} = {switch => $connect, port => $port};
    12841258         }
    12851259      }
    12861260
    1287    print "Switch output port and parent port connection\n"; 
     1261   print "Switch output port and parent port connection\n";
    12881262   print "---------------------------------------------\n";
    12891263   for my $sw (sort keys %db_switch_output_port) {
     
    12991273   print "Switch parent and children port inter-connection\n";
    13001274   print "------------------------------------------------\n";
    1301    for my $swport (sort keys %db_switch_connected_on_port) {       
     1275   for my $swport (sort keys %db_switch_connected_on_port) {
    13021276      my ($sw_connect,$port_connect) = split ':', $swport;
    13031277      for my $sw (keys %{$db_switch_connected_on_port{$swport}}) {
     
    13181292      switch_db         => \%SWITCH_DB,
    13191293      };
    1320      
     1294
    13211295   YAML::Syck::DumpFile("$KLASK_SW_FILE", $switch_connection);
    13221296   return;
     
    13401314
    13411315   $format = 'txt' if not defined $possible_format{$format};
    1342    
     1316
    13431317   $possible_format{$format}->(@ARGV);
    13441318   return;
     
    13531327   my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}};
    13541328
    1355    print "Switch output port and parent port connection\n"; 
     1329   print "Switch output port and parent port connection\n";
    13561330   print "---------------------------------------------\n";
    13571331   for my $sw (sort keys %db_switch_output_port) {
     
    13671341   print "Switch parent and children port inter-connection\n";
    13681342   print "------------------------------------------------\n";
    1369    for my $swport (sort keys %db_switch_connected_on_port) {       
     1343   for my $swport (sort keys %db_switch_connected_on_port) {
    13701344      my ($sw_connect,$port_connect) = split ':', $swport;
    13711345      for my $sw (keys %{$db_switch_connected_on_port{$swport}}) {
     
    13841358
    13851359   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    1386    
     1360
    13871361   my %db_switch_output_port       = %{$switch_connection->{output_port}};
    13881362   my %db_switch_parent            = %{$switch_connection->{parent}};
     
    13981372      $db_building{$building}->{$location}{ $sw->{hostname} } = 'y';
    13991373      }
    1400  
    1401  
     1374
     1375
    14021376   print "digraph G {\n";
    14031377
     
    14081382   for my $building (keys %db_building) {
    14091383      $b++;
    1410      
     1384
    14111385      print "\"building$b\" [label = \"$building\", color = black, fillcolor = gold, style = filled];\n";
    14121386      print "site -> \"building$b\" [len = 2, color = firebrick];\n";
     
    14151389      for my $loc (keys %{$db_building{$building}}) {
    14161390         $l++;
    1417  
     1391
    14181392         print "\"location$b-$l\" [label = \"$building".'/'.join('\n',split("/",$loc))."\", color = black, fillcolor = orange, style = filled];\n";
    14191393#         print "\"location$b-$l\" [label = \"$building / $loc\", color = black, fillcolor = orange, style = filled];\n";
     
    14421416      }
    14431417
    1444 #   print "Switch output port and parent port connection\n"; 
     1418#   print "Switch output port and parent port connection\n";
    14451419#   print "---------------------------------------------\n";
    14461420   for my $sw (sort keys %db_switch_output_port) {
     
    14561430#   print "Switch parent and children port inter-connection\n";
    14571431#   print "------------------------------------------------\n";
    1458    for my $swport (sort keys %db_switch_connected_on_port) {       
     1432   for my $swport (sort keys %db_switch_connected_on_port) {
    14591433      my ($sw_connect,$port_connect) = split ':', $swport;
    14601434      for my $sw (keys %{$db_switch_connected_on_port{$swport}}) {
     
    16151589
    16161590=head1 COPYRIGHT
    1617        
    1618 Copyright (C) 2005-2008 Gabriel Moreau.
     1591
     1592Copyright (C) 2005-2009 Gabriel Moreau.
    16191593
    16201594
Note: See TracChangeset for help on using the changeset viewer.