Changeset 4


Ignore:
Timestamp:
Jan 14, 2008, 3:56:45 PM (17 years ago)
Author:
g7moreau
Message:
  • Remove some old commented code
  • Add option exportsw with the option --format
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r3 r4  
    3535   updatedb   => \&cmd_updatedb,
    3636   searchdb   => \&cmd_searchdb,
     37   removedb   => \&cmd_removedb,
    3738   search     => \&cmd_search,
    3839   enable     => \&cmd_enable,
    3940   disable    => \&cmd_disable,
    4041   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,
    4445   iplocation => \&cmd_iplocation,
    4546   );
     
    159160###
    160161# va rechercher le nom des switchs pour savoir qui est qui
    161 sub initswitchnames {
     162sub init_switch_names {
    162163   my $verbose = shift;
    163164   
     
    211212###
    212213# convertit l'hexa (uniquement 2 chiffres) en decimal
    213 sub hextodec {
     214sub hex_to_dec {
    214215   #00:0F:1F:43:E4:2B
    215    my $car = '00' . shift;
    216 
    217    return '00' if $car eq '00unknow';
     216   my $car = '00' . uc(shift);
     217
     218   return '00' if $car eq '00UNKNOW';
    218219   my %table = (
    219220      "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",
    221221      "A"=>"10", "B"=>"11", "C"=>"12", "D"=>"13", "E"=>"14", "F"=>"15"
    222222      );
     
    227227###
    228228# convertit l'@ arp en decimal
    229 sub arphextodec {
     229sub arp_hex_to_dec {
    230230   #00:0F:1F:43:E4:2B
    231231   my $arp = shift;
     
    234234   my $return = '';
    235235   foreach(@paquets) {
    236       $return .= ".".hextodec($_);
     236      $return .= ".".hex_to_dec($_);
    237237      }
    238238   return $return;
     
    260260      }
    261261
    262    my $research = "1.3.6.1.2.1.17.4.3.1.2".arphextodec($arp);
     262   my $research = "1.3.6.1.2.1.17.4.3.1.2".arp_hex_to_dec($arp);
    263263   
    264264   LOOP_ON_SWITCH:
     
    327327      }
    328328
    329    my $research = "1.3.6.1.2.1.17.4.3.1.2".arphextodec($arp);
     329   my $research = "1.3.6.1.2.1.17.4.3.1.2".arp_hex_to_dec($arp);
    330330#print " $arp -> $research\n";
    331331   LOOP_ON_ALL_SWITCH:
     
    390390      }
    391391
    392    my @res =();
     392   my @res = ();
    393393
    394394   for my $cidr ($cidrlist->list()) {
     
    454454   my @computer = @_;
    455455   
    456    initswitchnames();    #nomme les switchs
     456   init_switch_names();    #nomme les switchs
    457457   fastping(@computer);
    458458   for my $clientname (@computer) {
     
    507507   my $detected_computer = 0;
    508508   
    509    initswitchnames('yes');    #nomme les switchs
     509   init_switch_names('yes');    #nomme les switchs
    510510
    511511   my %router_mac_ip = ();
     
    741741
    742742
    743 sub cmd_switchmap {
    744 
    745    initswitchnames('yes');    #nomme les switchs
     743sub cmd_updatesw {
     744
     745   init_switch_names('yes');    #nomme les switchs
    746746   print "\n";
    747747
     
    758758      }
    759759
    760 print "etape 1\n";
    761760   ALL_ROUTER_IP_ADDRESS:
    762761   for my $ip (Net::Netmask::sort_by_ip_address('194.254.66.254')) {
     
    774773         }
    775774      }   
    776 print "etape 2\n";
    777775
    778776#   print "Switch output port\n"; 
     
    792790      }
    793791
    794 print "etape 3\n";
    795792   ALL_SWITCH:
    796793   for my $one_computer (@list_switch_ip) {
     
    805802      }
    806803     
    807 print "etape 4\n";
    808804   ALL_SWITCH_IP_ADDRESS:
    809805   for my $ip (Net::Netmask::sort_by_ip_address(@list_switch_ipv4)) {
     
    828824      }
    829825   
    830 print "etape 5\n";
    831826   my %db_switch_connected_on_port = ();
    832827   my $maybe_more_than_one_switch_connected = 'yes';
     
    874869      }
    875870
    876 print "etape 6\n";
    877871   my %db_switch_parent =();
    878872
     
    925919   }
    926920
    927 sub cmd_swdot {
     921sub 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
     941sub 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
     976sub cmd_exportsw_dot {
    928977
    929978   my $switch_connection = YAML::LoadFile("/var/cache/klask/switchdb");
     
    945994   print "digraph G {\n";
    946995
    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";
    951998
    952999   my $b=0;
     
    9541001      $b++;
    9551002     
    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";
    9651005
    9661006      my $l = 0;
     
    9681008         $l++;
    9691009 
    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";
    9791012
    9801013         for my $sw (keys %{$db_building{$building}->{$loc}}) {
    9811014
    982 #            print <<ENDS;
    983 #         subgraph "cluster_$sw" {
    984 #            label = "$sw";
    985 #            style = filled;
    986 #            color = hot_pink;
    987 #ENDS
    988 # "sw-batB-legi:24" [label = 24, color = white,  peripheries = 3, style = filled];
    9891015            print "\"$sw:$db_switch_output_port{$sw}\" [label = $db_switch_output_port{$sw}, color = black, fillcolor = lightblue,  peripheries = 2, style = filled];\n";
    9901016
    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";
    9941020
    9951021
     
    9991025               next if $port_connect eq $db_switch_output_port{$sw};
    10001026               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";
    10021028              }
    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         }
    10201031      }
    10211032
Note: See TracChangeset for help on using the changeset viewer.