Changeset 49
- Timestamp:
- Jul 23, 2009, 1:12:12 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r48 r49 29 29 my $KLASK_CFG = YAML::Syck::LoadFile("$KLASK_CFG_FILE"); 30 30 31 my %DEFAULT = %{ $KLASK_CFG->{default}};32 my @SWITCH = @{ $KLASK_CFG->{switch}};31 my %DEFAULT = %{ $KLASK_CFG->{default} }; 32 my @SWITCH = @{ $KLASK_CFG->{switch} }; 33 33 34 34 my %switch_level = (); 35 my %SWITCH_DB = ();35 my %SWITCH_DB = (); 36 36 LEVEL_OF_EACH_SWITCH: 37 37 for my $sw (@SWITCH){ … … 39 39 $SWITCH_DB{$sw->{hostname}} = $sw; 40 40 } 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}}; 42 42 43 43 my %SWITCH_PORT_COUNT = (); … … 87 87 BS350T => { model => 'BS350T', match => 'BayStack 350T HW' }, 88 88 ); 89 89 90 90 my %OID_NUMBER = ( 91 sysDescr => '1.3.6.1.2.1.1.1.0',91 sysDescription => '1.3.6.1.2.1.1.1.0', 92 92 sysName => '1.3.6.1.2.1.1.5.0', 93 93 sysContact => '1.3.6.1.2.1.1.4.0', … … 163 163 my ($arp, $ip, $timestamp, $host) = split /\s+/, $cmd_arpwatch; 164 164 165 #print "OOO $cmd\n";166 #print "TTT arp $arp -> $ip pour host $host\n";167 168 165 $ret{ipv4_address} = $ip if $ip; 169 166 $ret{mac_address} = $arp if $arp; … … 177 174 } 178 175 179 # resultat de la commande arp176 # resultat de la commande arp 180 177 # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0 181 178 # sw2-batF0-legi.hmg.priv (192.168.22.112) at 00:30:c1:76:9c:01 [ether] on eth0.37 … … 186 183 $ret{ipv4_address} = $2 if(defined($2)); 187 184 $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 210 203 unless ($ret{mac_address} eq 'unknow') { 211 204 my @paquets = (); … … 217 210 } 218 211 219 #print "RET3 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n";220 212 return %ret; 221 213 } … … 224 216 sub get_switch_model { 225 217 my $sw_snmp_description = shift || 'unknow'; 226 218 227 219 for my $sw_kind (keys %SWITCH_KIND) { 228 220 next if not $sw_snmp_description =~ m/$SWITCH_KIND{$sw_kind}->{match}/; 229 221 230 222 return $SWITCH_KIND{$sw_kind}->{model}; 231 223 } 232 224 233 225 return $sw_snmp_description; 234 226 } … … 238 230 sub init_switch_names { 239 231 my $verbose = shift; 240 232 241 233 printf "%-25s %-25s %s\n",'Switch','Description','Type'; 242 234 # print "Switch description\n" if $verbose; … … 262 254 my $result = $session->get_request( 263 255 -varbindlist => [ 264 $OID_NUMBER{sysDescr },256 $OID_NUMBER{sysDescription}, 265 257 $OID_NUMBER{sysName}, 266 258 $OID_NUMBER{sysContact}, … … 269 261 ); 270 262 $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}}); 272 264 #$sw->{location} = $result->{"1.3.6.1.2.1.1.6.0"} || $sw->{hostname}; 273 265 #$sw->{contact} = $result->{"1.3.6.1.2.1.1.4.0"} || $sw->{hostname}; 274 266 $session->close; 275 267 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 277 269 my ($desc, $type) = split ':', $sw->{description}, 2; 278 # printf "%-25s 0--------->>>> %-25s %s\n", $sw->{hostname}, $desc, uc($type)."**" if $verbose;279 270 printf "%-25s 0--------->>>> %-25s %s\n", $sw->{hostname}, $desc, $sw->{model} if $verbose; 280 271 } … … 292 283 return '00' if $car eq '00UNKNOW'; 293 284 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", 295 287 "A"=>"10", "B"=>"11", "C"=>"12", "D"=>"13", "E"=>"14", "F"=>"15" 296 288 ); 297 my @chars = split (//, $car);289 my @chars = split //, $car; 298 290 return $table{$chars[-2]}*16 + $table{$chars[-1]}; 299 291 } … … 316 308 # va rechercher le port et le switch sur lequel est la machine 317 309 sub find_switch_port { 318 my $arp = shift;310 my $arp = shift; 319 311 my $switch_proposal = shift || ''; 320 312 321 313 my %ret; 322 314 $ret{switch_description} = "unknow"; … … 335 327 336 328 my $research = "1.3.6.1.2.1.17.4.3.1.2".arp_hex_to_dec($arp); 337 329 338 330 LOOP_ON_SWITCH: 339 331 for my $sw (@switch_search) { … … 353 345 354 346 # IMPORTANT !! 355 # ceci empeche la detection sur certains port ... 347 # ceci empeche la detection sur certains port ... 356 348 # en effet les switch sont relies entre eux par un cable reseau et du coup 357 349 # tous les arp de toutes les machines sont presentes sur ces ports (ceux choisis ici sont les miens) … … 369 361 $ret{switch_description} = $sw->{description}; 370 362 $ret{switch_port} = get_human_readable_port($sw->{model}, $swport); # $swport; 371 363 372 364 last LOOP_ON_SWITCH; 373 365 # } … … 427 419 return $KLASK_CFG->{network}{$network}{interface}; 428 420 } 429 421 430 422 ### 431 423 # liste l'ensemble des adresses ip d'un réseau … … 473 465 my $sw_model = shift; 474 466 my $sw_port = shift; 475 467 476 468 return $sw_port if not $sw_model eq 'HP8000M'; 477 469 478 470 my $reste = (($sw_port - 1) % 8) + 1; 479 471 my $major = int( ($sw_port - 1) / 8 ); … … 485 477 my $sw_model = shift; 486 478 my $sw_port = shift; 487 479 488 480 return $sw_port if not $sw_model eq 'HP8000'; 489 481 490 482 my $letter = substr($sw_port, 0, 1); 491 483 492 484 # return $port if $letter =~ m/\d/; 493 485 494 486 my $reste = substr($sw_port, 1); 495 487 496 488 return $INTERNAL_PORT_MAP_REV{$letter} * 8 + $reste; 497 489 } … … 537 529 sub cmd_search { 538 530 my @computer = @_; 539 531 540 532 init_switch_names(); #nomme les switchs 541 533 fastping(@computer); … … 554 546 fastping(@computer); 555 547 my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE"); 556 548 557 549 LOOP_ON_COMPUTER: 558 550 for my $clientname (@computer) { 559 551 my %resol_arp = resolve_ip_arp_host($clientname); #resolution arp 560 552 my $ip = $resol_arp{ipv4_address}; 561 553 562 554 next LOOP_ON_COMPUTER unless exists $computerdb->{$ip}; 563 555 564 556 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($computerdb->{$ip}{timestamp}); 565 557 $year += 1900; … … 604 596 my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}}; 605 597 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) { 607 599 my ($sw_connect,$port_connect) = split ':', $swport; 608 600 $db_switch_chained_port{$sw_connect} .= "$port_connect:"; … … 637 629 for my $one_computer (@computer) { 638 630 $i++; 639 631 640 632 my $total_percent = int(($i*100)/$number_of_computer); 641 633 … … 655 647 656 648 my %resol_arp = resolve_ip_arp_host($one_computer,$current_interface); 657 649 658 650 # do not search on router connection (why ?) 659 651 if ( exists $router_mac_ip{$resol_arp{mac_address}}) { … … 725 717 # mise a jour du nom de la machine si modification dans le dns 726 718 $computerdb->{$resol_arp{ipv4_address}}{hostname_fq} = $resol_arp{hostname_fq}; 727 719 728 720 # mise à jour de la date de détection si détection plus récente par arpwatch 729 721 $computerdb->{$resol_arp{ipv4_address}}{timestamp} = $resol_arp{timestamp} if exists $resol_arp{timestamp} and $computerdb->{$resol_arp{ipv4_address}}{timestamp} < $resol_arp{timestamp}; 730 722 731 # provisoire car changement de nom des attributs732 # $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 736 723 # relance un arping sur la machine si celle-ci n'a pas été détectée depuis plus d'une semaine 737 724 # push @computer_not_detected, $resol_arp{ipv4_address} if $computerdb->{$resol_arp{ipv4_address}}{timestamp} < $timestamp_last_week; 738 725 $computer_not_detected{$resol_arp{ipv4_address}} = $current_interface if $computerdb->{$resol_arp{ipv4_address}}{timestamp} < $timestamp_last_week; 739 726 740 727 } 741 728 } … … 794 781 795 782 $format = 'txt' if not defined $possible_format{$format}; 796 783 797 784 $possible_format{$format}->(@ARGV); 798 785 return; … … 809 796 LOOP_ON_IP_ADDRESS: 810 797 foreach my $ip (Net::Netmask::sort_by_ip_address(keys %$computerdb)) { 811 798 812 799 # next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq 'unknow'; 813 800 … … 817 804 # dans le futur 818 805 # next if $computerdb->{$ip}{hostname_fq} eq 'unknow'; 819 806 820 807 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($computerdb->{$ip}{timestamp}); 821 808 $year += 1900; … … 873 860 LOOP_ON_IP_ADDRESS: 874 861 foreach my $ip (keys %$computerdb) { 875 862 876 863 # to be improve in the future 877 864 next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}); # switch on himself ! 878 865 879 866 $mac_count{$computerdb->{$ip}{mac_address}}++; 880 867 } … … 884 871 LOOP_ON_IP_ADDRESS: 885 872 foreach my $ip (Net::Netmask::sort_by_ip_address(keys %$computerdb)) { 886 873 887 874 # to be improve in the future 888 875 next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}); # switch on himself ! … … 895 882 # $odd_or_even++; 896 883 # my $typerow = $odd_or_even % 2 ? 'odd' : 'even'; 897 $typerow = $typerow eq 'even' ? 'odd' : 'even'; 884 $typerow = $typerow eq 'even' ? 'odd' : 'even'; 898 885 899 886 my $switch_hostname = $computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description} || 'unkown'; … … 932 919 my $switch_hostname_sort = sprintf "%s %3s" ,$sw, $db_switch_output_port{$sw}; 933 920 934 $typerow = $typerow eq 'even' ? 'odd' : 'even'; 921 $typerow = $typerow eq 'even' ? 'odd' : 'even'; 935 922 936 923 if (exists $db_switch_parent{$sw}) { … … 949 936 my $mac_sort = sprintf "%04i-%s", 9999, $mac_address; 950 937 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"; 955 941 <tr class="$typerow"> 956 942 <td sorttable_customkey="$switch_hostname_sort">$sw</td> … … 965 951 } 966 952 else { 967 # printf "%-25s %2s +--> router\n", $sw, $db_switch_output_port{$sw}; 968 print <<"END_HTML"; 953 print <<"END_HTML"; 969 954 <tr class="$typerow"> 970 955 <td sorttable_customkey="$switch_hostname_sort">$sw</td> … … 999 984 my $mac_sort = sprintf "%04i-%s", 9999, $mac_address; 1000 985 1001 $typerow = $typerow eq 'even' ? 'odd' : 'even'; 986 $typerow = $typerow eq 'even' ? 'odd' : 'even'; 1002 987 1003 988 if (exists $db_switch_output_port{$sw}) { 1004 989 1005 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"; 1008 993 <tr class="$typerow"> 1009 994 <td sorttable_customkey="$switch_hostname_sort">$sw_connect</td> … … 1018 1003 } 1019 1004 else { 1020 print <<"END_HTML";1005 print <<"END_HTML"; 1021 1006 <tr class="$typerow"> 1022 1007 <td sorttable_customkey="$switch_hostname_sort">$sw_connect</td> … … 1033 1018 } 1034 1019 1035 1036 1020 print <<'END_HTML'; 1037 1021 </tbody> … … 1051 1035 my $sw_hostname = $computerdb->{$ip}{switch_hostname} || ''; 1052 1036 next if $sw_hostname eq 'unknow'; 1053 1037 1054 1038 my $sw_location = ''; 1055 1039 for my $sw (@SWITCH) { … … 1067 1051 my $switch = shift; 1068 1052 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) 1072 1056 system "snmpset -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port = 1"; 1073 1057 return; … … 1077 1061 my $switch = shift; 1078 1062 my $port = shift; 1079 1063 1080 1064 system "snmpset -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port = 2"; 1081 1065 return; … … 1085 1069 my $switch = shift; 1086 1070 my $port = shift; 1087 1071 1088 1072 system "snmpget -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port"; 1089 1073 return; … … 1093 1077 my $switch_name = shift || ''; 1094 1078 my $mac_address = shift || ''; 1095 1079 1096 1080 if ($switch_name eq '' or $mac_address eq '') { 1097 1081 die "Usage: klask search-mac-on-switch SWITCH_NAME MAC_ADDRESS\n"; … … 1099 1083 1100 1084 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"; 1102 1086 } 1103 1087 … … 1122 1106 -varbindlist => [$research] 1123 1107 ); 1124 1108 1125 1109 if (not defined($result) or $result->{$research} eq 'noSuchInstance') { 1126 1110 print "Klask do not find MAC $mac_address on switch $switch_name\n"; … … 1147 1131 # for my $one_computer ('194.254.66.254') { 1148 1132 for my $one_router ( get_list_main_router(get_list_network()) ) { 1149 #print "TT$one_router\n";1150 1133 my %resol_arp = resolve_ip_arp_host($one_router,'*','low'); # resolution arp 1151 1134 next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow'; 1152 #print "$one_router\n";1153 1135 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements des routeurs 1154 1136 } … … 1156 1138 ALL_ROUTER_IP_ADDRESS: 1157 1139 for my $ip (Net::Netmask::sort_by_ip_address(keys %where)) { # '194.254.66.254')) { 1158 1140 1159 1141 next ALL_ROUTER_IP_ADDRESS if not exists $where{$ip}; # /a priori/ idiot car ne sers à rien... 1160 1142 … … 1165 1147 1166 1148 next ALL_SWITCH_CONNECTED if $switch->{port} eq '0'; 1167 1149 1168 1150 $db_switch_output_port{$switch->{hostname}} = $switch->{port}; 1169 1151 } 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 } 1179 1153 1180 1154 my %db_switch_link_with = (); … … 1192 1166 my %resol_arp = resolve_ip_arp_host($one_computer,'*','low'); # arp resolution 1193 1167 next ALL_SWITCH if $resol_arp{mac_address} eq 'unknow'; 1194 1168 1195 1169 push @list_switch_ipv4,$resol_arp{ipv4_address}; 1196 1170 1197 1171 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # find port on all switch 1198 1172 … … 1203 1177 $SWITCH_DB{$one_computer}->{timestamp} = $timestamp; 1204 1178 } 1205 1179 1206 1180 ALL_SWITCH_IP_ADDRESS: 1207 1181 for my $ip (Net::Netmask::sort_by_ip_address(@list_switch_ipv4)) { 1208 1182 1209 1183 next ALL_SWITCH_IP_ADDRESS if not exists $where{$ip}; 1210 1184 … … 1225 1199 1226 1200 } 1227 1201 1228 1202 my %db_switch_connected_on_port = (); 1229 1203 my $maybe_more_than_one_switch_connected = 'yes'; 1230 1204 1231 1205 while ($maybe_more_than_one_switch_connected eq 'yes') { 1232 1206 for my $sw (keys %db_switch_link_with) { 1233 1207 for my $connect (keys %{$db_switch_link_with{$sw}}) { 1234 1208 1235 1209 my $port = $db_switch_link_with{$sw}->{$connect}; 1236 1210 1237 1211 $db_switch_connected_on_port{"$connect:$port"} ||= {}; 1238 1212 $db_switch_connected_on_port{"$connect:$port"}->{$sw}++; # Just to define the key … … 1244 1218 SWITCH_AND_PORT: 1245 1219 for my $swport (keys %db_switch_connected_on_port) { 1246 1220 1247 1221 next if keys %{$db_switch_connected_on_port{$swport}} == 1; 1248 1222 1249 1223 $maybe_more_than_one_switch_connected = 'yes'; 1250 1224 … … 1254 1228 CONNECTED: 1255 1229 for my $sw_connected (@sw_on_same_port) { 1256 1230 1257 1231 next CONNECTED if not keys %{$db_switch_link_with{$sw_connected}} == 1; 1258 1232 1259 1233 $db_switch_connected_on_port{$swport} = {$sw_connected => 1}; 1260 1234 1261 1235 for my $other_sw (@sw_on_same_port) { 1262 1236 next if $other_sw eq $sw_connected; 1263 1237 1264 1238 delete $db_switch_link_with{$other_sw}->{$sw_connect}; 1265 1239 } 1266 1240 1267 1241 # We can not do better for this switch for this loop 1268 1242 next SWITCH_AND_PORT; … … 1275 1249 for my $sw (keys %db_switch_link_with) { 1276 1250 for my $connect (keys %{$db_switch_link_with{$sw}}) { 1277 1251 1278 1252 my $port = $db_switch_link_with{$sw}->{$connect}; 1279 1253 1280 1254 $db_switch_connected_on_port{"$connect:$port"} ||= {}; 1281 1255 $db_switch_connected_on_port{"$connect:$port"}->{$sw} = $port; 1282 1256 1283 1257 $db_switch_parent{$sw} = {switch => $connect, port => $port}; 1284 1258 } 1285 1259 } 1286 1260 1287 print "Switch output port and parent port connection\n"; 1261 print "Switch output port and parent port connection\n"; 1288 1262 print "---------------------------------------------\n"; 1289 1263 for my $sw (sort keys %db_switch_output_port) { … … 1299 1273 print "Switch parent and children port inter-connection\n"; 1300 1274 print "------------------------------------------------\n"; 1301 for my $swport (sort keys %db_switch_connected_on_port) { 1275 for my $swport (sort keys %db_switch_connected_on_port) { 1302 1276 my ($sw_connect,$port_connect) = split ':', $swport; 1303 1277 for my $sw (keys %{$db_switch_connected_on_port{$swport}}) { … … 1318 1292 switch_db => \%SWITCH_DB, 1319 1293 }; 1320 1294 1321 1295 YAML::Syck::DumpFile("$KLASK_SW_FILE", $switch_connection); 1322 1296 return; … … 1340 1314 1341 1315 $format = 'txt' if not defined $possible_format{$format}; 1342 1316 1343 1317 $possible_format{$format}->(@ARGV); 1344 1318 return; … … 1353 1327 my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}}; 1354 1328 1355 print "Switch output port and parent port connection\n"; 1329 print "Switch output port and parent port connection\n"; 1356 1330 print "---------------------------------------------\n"; 1357 1331 for my $sw (sort keys %db_switch_output_port) { … … 1367 1341 print "Switch parent and children port inter-connection\n"; 1368 1342 print "------------------------------------------------\n"; 1369 for my $swport (sort keys %db_switch_connected_on_port) { 1343 for my $swport (sort keys %db_switch_connected_on_port) { 1370 1344 my ($sw_connect,$port_connect) = split ':', $swport; 1371 1345 for my $sw (keys %{$db_switch_connected_on_port{$swport}}) { … … 1384 1358 1385 1359 my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE"); 1386 1360 1387 1361 my %db_switch_output_port = %{$switch_connection->{output_port}}; 1388 1362 my %db_switch_parent = %{$switch_connection->{parent}}; … … 1398 1372 $db_building{$building}->{$location}{ $sw->{hostname} } = 'y'; 1399 1373 } 1400 1401 1374 1375 1402 1376 print "digraph G {\n"; 1403 1377 … … 1408 1382 for my $building (keys %db_building) { 1409 1383 $b++; 1410 1384 1411 1385 print "\"building$b\" [label = \"$building\", color = black, fillcolor = gold, style = filled];\n"; 1412 1386 print "site -> \"building$b\" [len = 2, color = firebrick];\n"; … … 1415 1389 for my $loc (keys %{$db_building{$building}}) { 1416 1390 $l++; 1417 1391 1418 1392 print "\"location$b-$l\" [label = \"$building".'/'.join('\n',split("/",$loc))."\", color = black, fillcolor = orange, style = filled];\n"; 1419 1393 # print "\"location$b-$l\" [label = \"$building / $loc\", color = black, fillcolor = orange, style = filled];\n"; … … 1442 1416 } 1443 1417 1444 # print "Switch output port and parent port connection\n"; 1418 # print "Switch output port and parent port connection\n"; 1445 1419 # print "---------------------------------------------\n"; 1446 1420 for my $sw (sort keys %db_switch_output_port) { … … 1456 1430 # print "Switch parent and children port inter-connection\n"; 1457 1431 # print "------------------------------------------------\n"; 1458 for my $swport (sort keys %db_switch_connected_on_port) { 1432 for my $swport (sort keys %db_switch_connected_on_port) { 1459 1433 my ($sw_connect,$port_connect) = split ':', $swport; 1460 1434 for my $sw (keys %{$db_switch_connected_on_port{$swport}}) { … … 1615 1589 1616 1590 =head1 COPYRIGHT 1617 1618 Copyright (C) 2005-200 8Gabriel Moreau.1591 1592 Copyright (C) 2005-2009 Gabriel Moreau. 1619 1593 1620 1594
Note: See TracChangeset
for help on using the changeset viewer.