Changeset 4
- Timestamp:
- Jan 14, 2008, 3:56:45 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r3 r4 35 35 updatedb => \&cmd_updatedb, 36 36 searchdb => \&cmd_searchdb, 37 removedb => \&cmd_removedb, 37 38 search => \&cmd_search, 38 39 enable => \&cmd_enable, 39 40 disable => \&cmd_disable, 40 41 status => \&cmd_status, 41 switchmap => \&cmd_switchmap,42 dotsw => \&cmd_swdot,43 removedb => \&cmd_removedb,42 updatesw => \&cmd_updatesw, 43 exportsw => \&cmd_exportsw, 44 dotsw => \&cmd_exportsw_dot, 44 45 iplocation => \&cmd_iplocation, 45 46 ); … … 159 160 ### 160 161 # va rechercher le nom des switchs pour savoir qui est qui 161 sub init switchnames {162 sub init_switch_names { 162 163 my $verbose = shift; 163 164 … … 211 212 ### 212 213 # convertit l'hexa (uniquement 2 chiffres) en decimal 213 sub hex todec {214 sub hex_to_dec { 214 215 #00:0F:1F:43:E4:2B 215 my $car = '00' . shift;216 217 return '00' if $car eq '00 unknow';216 my $car = '00' . uc(shift); 217 218 return '00' if $car eq '00UNKNOW'; 218 219 my %table = ( 219 220 "0"=>"0", "1"=>"1", "2"=>"2", "3"=>"3", "4"=>"4", "5"=>"5", "6"=>"6", "7"=>"7", "8"=>"8", "9"=>"9", 220 "a"=>"10", "b"=>"11", "c"=>"12", "d"=>"13", "e"=>"14", "f"=>"15",221 221 "A"=>"10", "B"=>"11", "C"=>"12", "D"=>"13", "E"=>"14", "F"=>"15" 222 222 ); … … 227 227 ### 228 228 # convertit l'@ arp en decimal 229 sub arp hextodec {229 sub arp_hex_to_dec { 230 230 #00:0F:1F:43:E4:2B 231 231 my $arp = shift; … … 234 234 my $return = ''; 235 235 foreach(@paquets) { 236 $return .= ".".hex todec($_);236 $return .= ".".hex_to_dec($_); 237 237 } 238 238 return $return; … … 260 260 } 261 261 262 my $research = "1.3.6.1.2.1.17.4.3.1.2".arp hextodec($arp);262 my $research = "1.3.6.1.2.1.17.4.3.1.2".arp_hex_to_dec($arp); 263 263 264 264 LOOP_ON_SWITCH: … … 327 327 } 328 328 329 my $research = "1.3.6.1.2.1.17.4.3.1.2".arp hextodec($arp);329 my $research = "1.3.6.1.2.1.17.4.3.1.2".arp_hex_to_dec($arp); 330 330 #print " $arp -> $research\n"; 331 331 LOOP_ON_ALL_SWITCH: … … 390 390 } 391 391 392 my @res = ();392 my @res = (); 393 393 394 394 for my $cidr ($cidrlist->list()) { … … 454 454 my @computer = @_; 455 455 456 init switchnames(); #nomme les switchs456 init_switch_names(); #nomme les switchs 457 457 fastping(@computer); 458 458 for my $clientname (@computer) { … … 507 507 my $detected_computer = 0; 508 508 509 init switchnames('yes'); #nomme les switchs509 init_switch_names('yes'); #nomme les switchs 510 510 511 511 my %router_mac_ip = (); … … 741 741 742 742 743 sub cmd_ switchmap{744 745 init switchnames('yes'); #nomme les switchs743 sub cmd_updatesw { 744 745 init_switch_names('yes'); #nomme les switchs 746 746 print "\n"; 747 747 … … 758 758 } 759 759 760 print "etape 1\n";761 760 ALL_ROUTER_IP_ADDRESS: 762 761 for my $ip (Net::Netmask::sort_by_ip_address('194.254.66.254')) { … … 774 773 } 775 774 } 776 print "etape 2\n";777 775 778 776 # print "Switch output port\n"; … … 792 790 } 793 791 794 print "etape 3\n";795 792 ALL_SWITCH: 796 793 for my $one_computer (@list_switch_ip) { … … 805 802 } 806 803 807 print "etape 4\n";808 804 ALL_SWITCH_IP_ADDRESS: 809 805 for my $ip (Net::Netmask::sort_by_ip_address(@list_switch_ipv4)) { … … 828 824 } 829 825 830 print "etape 5\n";831 826 my %db_switch_connected_on_port = (); 832 827 my $maybe_more_than_one_switch_connected = 'yes'; … … 874 869 } 875 870 876 print "etape 6\n";877 871 my %db_switch_parent =(); 878 872 … … 925 919 } 926 920 927 sub cmd_swdot { 921 sub cmd_exportsw { 922 my @ARGV = @_; 923 924 my $format = 'txt'; 925 use Getopt::Long; 926 927 my $ret = GetOptions( 928 'format|f=s' => \$format, 929 ); 930 931 my %possible_format = ( 932 txt => \&cmd_exportsw_txt, 933 dot => \&cmd_exportsw_dot, 934 ); 935 936 $format = 'txt' if not defined $possible_format{$format}; 937 938 $possible_format{$format}->(@ARGV); 939 } 940 941 sub cmd_exportsw_txt { 942 943 my $switch_connection = YAML::LoadFile("/var/cache/klask/switchdb"); 944 945 my %db_switch_output_port = %{$switch_connection->{output_port}}; 946 my %db_switch_parent = %{$switch_connection->{parent}}; 947 my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}}; 948 949 print "Switch output port and parent port connection\n"; 950 print "---------------------------------------------\n"; 951 for my $sw (sort keys %db_switch_output_port) { 952 if (exists $db_switch_parent{$sw}) { 953 printf "%-25s %2s +--> %2s %-25s\n", $sw, $db_switch_output_port{$sw}, $db_switch_parent{$sw}->{port}, $db_switch_parent{$sw}->{switch}; 954 } 955 else { 956 printf "%-25s %2s +--> router\n", $sw, $db_switch_output_port{$sw}; 957 } 958 } 959 print "\n"; 960 961 print "Switch parent and children port inter-connection\n"; 962 print "------------------------------------------------\n"; 963 for my $swport (sort keys %db_switch_connected_on_port) { 964 my ($sw_connect,$port_connect) = split ':', $swport; 965 for my $sw (keys %{$db_switch_connected_on_port{$swport}}) { 966 if (exists $db_switch_output_port{$sw}) { 967 printf "%-25s %2s <--+ %2s %-25s\n", $sw_connect, $port_connect, $db_switch_output_port{$sw}, $sw; 968 } 969 else { 970 printf "%-25s %2s <--+ %-25s\n", $sw_connect, $port_connect, $sw; 971 } 972 } 973 } 974 } 975 976 sub cmd_exportsw_dot { 928 977 929 978 my $switch_connection = YAML::LoadFile("/var/cache/klask/switchdb"); … … 945 994 print "digraph G {\n"; 946 995 947 #print "size = \"11.4,8.2!\"; dpi = 600; orientation = landscape;\n"; 948 949 print "site [label = \"site\", color = black, fillcolor = gold, shape = invhouse, style = filled];\n"; 950 print "internet [label = \"internet\", color = black, fillcolor = cyan, shape = house, style = filled];\n"; 996 print "site [label = \"site\", color = black, fillcolor = gold, shape = invhouse, style = filled];\n"; 997 print "internet [label = \"internet\", color = black, fillcolor = cyan, shape = house, style = filled];\n"; 951 998 952 999 my $b=0; … … 954 1001 $b++; 955 1002 956 # print <<ENDB; 957 # subgraph "cluster_$b" { 958 # label = "$building"; 959 # style = filled; 960 # color = yellow; 961 #ENDB 962 963 print "\"building$b\" [label = \"$building\", color = black, fillcolor = gold, style = filled];\n"; 964 print "site -> \"building$b\" [len = 2, color = firebrick];\n"; 1003 print "\"building$b\" [label = \"$building\", color = black, fillcolor = gold, style = filled];\n"; 1004 print "site -> \"building$b\" [len = 2, color = firebrick];\n"; 965 1005 966 1006 my $l = 0; … … 968 1008 $l++; 969 1009 970 # print <<ENDL; 971 # subgraph "cluster_$b-$l" { 972 # label = "$building / $loc"; 973 # style = filled; 974 # color = purple; 975 #ENDL 976 977 print "\"location$b-$l\" [label = \"$building / $loc\", color = black, fillcolor = orange, style = filled];\n"; 978 print "\"building$b\" -> \"location$b-$l\" [len = 2, color = firebrick]\n"; 1010 print "\"location$b-$l\" [label = \"$building / $loc\", color = black, fillcolor = orange, style = filled];\n"; 1011 print "\"building$b\" -> \"location$b-$l\" [len = 2, color = firebrick]\n"; 979 1012 980 1013 for my $sw (keys %{$db_building{$building}->{$loc}}) { 981 1014 982 # print <<ENDS;983 # subgraph "cluster_$sw" {984 # label = "$sw";985 # style = filled;986 # color = hot_pink;987 #ENDS988 # "sw-batB-legi:24" [label = 24, color = white, peripheries = 3, style = filled];989 1015 print "\"$sw:$db_switch_output_port{$sw}\" [label = $db_switch_output_port{$sw}, color = black, fillcolor = lightblue, peripheries = 2, style = filled];\n"; 990 1016 991 print "\"$sw\" [label = \"$sw\", color = black, fillcolor = palegreen, shape = rect, style = filled];\n";992 print "\"location$b-$l\" -> \"$sw\" [len = 2, color = firebrick, arrowtail = dot]\n";993 print "\"$sw\" -> \"$sw:$db_switch_output_port{$sw}\" [len=2, style=bold, arrowhead = normal, arrowtail = invdot]\n";1017 print "\"$sw\" [label = \"$sw\", color = black, fillcolor = palegreen, shape = rect, style = filled];\n"; 1018 print "\"location$b-$l\" -> \"$sw\" [len = 2, color = firebrick, arrowtail = dot]\n"; 1019 print "\"$sw\" -> \"$sw:$db_switch_output_port{$sw}\" [len=2, style=bold, arrowhead = normal, arrowtail = invdot]\n"; 994 1020 995 1021 … … 999 1025 next if $port_connect eq $db_switch_output_port{$sw}; 1000 1026 print "\"$sw:$port_connect\" [label = $port_connect, color = black, fillcolor = plum, peripheries = 1, style = filled];\n"; 1001 print "\"$sw:$port_connect\" -> \"$sw\" [len=2, style=bold, arrowhead= normal, arrowtail = inv]\n";1027 print "\"$sw:$port_connect\" -> \"$sw\" [len=2, style=bold, arrowhead= normal, arrowtail = inv]\n"; 1002 1028 } 1003 1004 # print <<ENDS; 1005 # } 1006 #ENDS 1007 1008 } 1009 1010 # print <<ENDL; 1011 # } 1012 #ENDL 1013 1014 } 1015 1016 # print <<ENDB; 1017 # } 1018 #ENDB 1019 1029 } 1030 } 1020 1031 } 1021 1032
Note: See TracChangeset
for help on using the changeset viewer.