Changeset 11 for trunk/klask


Ignore:
Timestamp:
Jan 31, 2008, 11:16:17 AM (16 years ago)
Author:
g7moreau
Message:
  • Change many global variable to uppercase letters
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r10 r11  
    1313# libcrypt-des-perl libcrypt-hcesha-perl   libdigest-hmac-perl
    1414
    15 our $KLASK_DB  = '/var/cache/klask/klaskdb';
    16 our $KLASK_SW  = '/var/cache/klask/switchdb';
    17 our $KLASK_CFG = '/etc/klask.conf';
    18 
    19 my $switchdb = YAML::LoadFile("$KLASK_CFG");
    20 
    21 our %default = %{$switchdb->{default}};
    22 our @switch  = @{$switchdb->{switch}};
    23 
    24 our %switch_level = ();
     15my $KLASK_DB  = '/var/cache/klask/klaskdb';
     16my $KLASK_SW  = '/var/cache/klask/switchdb';
     17my $KLASK_CFG = '/etc/klask.conf';
     18
     19my $SWITCH_DB = YAML::LoadFile("$KLASK_CFG");
     20
     21my %DEFAULT = %{$SWITCH_DB->{default}};
     22my @SWITCH  = @{$SWITCH_DB->{switch}};
     23
     24my %switch_level = ();
    2525LEVEL_OF_EACH_SWITCH:
    26 for my $sw (@switch){
    27    $switch_level{$sw->{hostname}} = $sw->{level} || $default{switch_level}  || 2;
    28    }
    29 @switch  = sort { $switch_level{$b->{hostname}} <=> $switch_level{$a->{hostname}} } @{$switchdb->{switch}}; 
    30 
    31 our %switch_port_count = ();
    32 
    33 our %cmddb = (
     26for my $sw (@SWITCH){
     27   $switch_level{$sw->{hostname}} = $sw->{level} || $DEFAULT{switch_level}  || 2;
     28   }
     29@SWITCH = sort { $switch_level{$b->{hostname}} <=> $switch_level{$a->{hostname}} } @{$SWITCH_DB->{switch}}; 
     30
     31my %switch_port_count = ();
     32
     33my %CMD_DB = (
    3434   help       => \&cmd_help,
    3535   exportdb   => \&cmd_exportdb,
     
    4747   );
    4848
    49 our %INTERNALPORTMAP = (
     49my %INTERNAL_PORT_MAP = (
    5050   0 => 'A',
    5151   1 => 'B',
     
    5757   7 => 'H',
    5858   );
    59 our %INTERNALPORTMAPREV = reverse %INTERNALPORTMAP;
     59my %INTERNAL_PORT_MAP_REV = reverse %INTERNAL_PORT_MAP;
    6060
    6161
     
    6464################
    6565
    66 my $cmd = shift || 'help';
    67 if (defined $cmddb{$cmd}) {
    68    $cmddb{$cmd}->(@ARGV);
     66my $cmd = shift @ARGV || 'help';
     67if (defined $CMD_DB{$cmd}) {
     68   $CMD_DB{$cmd}->(@ARGV);
    6969   }
    7070else {
    7171   print STDERR "klask: command $cmd not found\n\n";
    72    $cmddb{help}->();
     72   $CMD_DB{help}->();
    7373   exit 1;
    7474   }
     
    168168
    169169   INIT_EACH_SWITCH:
    170    for my $sw (@switch) {
     170   for my $sw (@SWITCH) {
    171171#print "$sw->{hostname} \n";
    172172      my %session = ( -hostname   => $sw->{hostname} );
    173173         $session{-version} = $sw->{version}   || 1;
    174          $session{-port}    = $sw->{snmpport}  || $default{snmpport}  || 161;
     174         $session{-port}    = $sw->{snmpport}  || $DEFAULT{snmpport}  || 161;
    175175         if (exists $sw->{version} and $sw->{version} eq 3) {
    176176            $session{-username} = $sw->{username} || 'snmpadmin';
     
    181181            }
    182182         else {
    183             $session{-community} = $sw->{community} || $default{community} || 'public';
     183            $session{-community} = $sw->{community} || $DEFAULT{community} || 'public';
    184184            }
    185185
     
    189189#         -hostname   => $sw->{hostname},
    190190#         -version    => $sw->{version}   || 1,
    191 #         -community  => $sw->{community} || $default{community} || 'public',
     191#         -community  => $sw->{community} || $DEFAULT{community} || 'public',
    192192#         -username   => $sw->{username}  || 'snmpadmin',
    193 #         -port       => $sw->{snmpport}  || $default{snmpport}  || 161,
     193#         -port       => $sw->{snmpport}  || $DEFAULT{snmpport}  || 161,
    194194#         );
    195195#         if (exists $sw->{version} and $sw->{version} eq 3) {
     
    252252   return %ret if $arp eq 'unknow';;
    253253
    254    my @switch_search = @switch;
     254   my @SWITCH_search = @SWITCH;
    255255   if ($switch_proposal ne '') {
    256       for my $sw (@switch) {
     256      for my $sw (@SWITCH) {
    257257         next if $sw->{hostname} ne $switch_proposal;
    258          unshift @switch_search, $sw;
     258         unshift @SWITCH_search, $sw;
    259259         last;
    260260         }
     
    264264   
    265265   LOOP_ON_SWITCH:
    266    for my $sw (@switch_search) {
     266   for my $sw (@SWITCH_search) {
    267267      my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} );
    268268print "$error \n" if $error;
    269269#         -hostname   => $sw->{hostname},
    270 #         -community  => $sw->{community} || $default{community} || 'public',
    271 #         -port       => $sw->{snmpport}  || $default{snmpport}  || 161
     270#         -community  => $sw->{community} || $DEFAULT{community} || 'public',
     271#         -port       => $sw->{snmpport}  || $DEFAULT{snmpport}  || 161
    272272#         );
    273273#print "$sw->{hostname} --  $research \n";
     
    323323   return $ret if $arp eq 'unknow';
    324324
    325    for my $sw (@switch) {
     325   for my $sw (@SWITCH) {
    326326      $switch_port_count{$sw->{hostname}} = {} if not exists $switch_port_count{$sw->{hostname}};
    327327#      $sw->{_port} = {} if not exists $sw->{_port};
     
    331331#print " $arp -> $research\n";
    332332   LOOP_ON_ALL_SWITCH:
    333    for my $sw (@switch) {
     333   for my $sw (@SWITCH) {
    334334      my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} );
    335335print "$error \n" if $error;
    336336#         -hostname   => $sw->{hostname},
    337 #         -community  => $sw->{community} || $default{community} || 'public',
    338 #         -port       => $sw->{snmpport}  || $default{snmpport}  || 161
     337#         -community  => $sw->{community} || $DEFAULT{community} || 'public',
     338#         -port       => $sw->{snmpport}  || $DEFAULT{snmpport}  || 161
    339339#         );
    340340#print "$sw->{hostname} --  $research \n";
     
    366366sub get_list_network {
    367367
    368    return keys %{$switchdb->{network}};
     368   return keys %{$SWITCH_DB->{network}};
    369369   }
    370370
     
    372372   my $network = shift;
    373373
    374    return $switchdb->{network}{$network}{interface};
     374   return $SWITCH_DB->{network}{$network}{interface};
    375375   }
    376376 
     
    383383
    384384   for my $net (@network) {
    385       my @line  = @{$switchdb->{network}{$net}{'ip-subnet'}};
     385      my @line  = @{$SWITCH_DB->{network}{$net}{'ip-subnet'}};
    386386      for my $cmd (@line) {
    387387         for my $method (keys %$cmd){
     
    411411
    412412   for my $net (@network) {
    413       push @res, $switchdb->{network}{$net}{'main-router'};
     413      push @res, $SWITCH_DB->{network}{$net}{'main-router'};
    414414      }
    415415
     
    426426   my $major = int( ($port - 1) / 8 );
    427427
    428    return "$INTERNALPORTMAP{$major}$reste";
     428   return "$INTERNAL_PORT_MAP{$major}$reste";
    429429   }
    430430
     
    441441   my $reste =  substr($port, 1);
    442442   
    443    return $INTERNALPORTMAPREV{$letter} * 8 + $reste;
     443   return $INTERNAL_PORT_MAP_REV{$letter} * 8 + $reste;
    444444   }
    445445
     
    722722 
    723723      my $sw_location = '';
    724       for my $sw (@switch) {
     724      for my $sw (@SWITCH) {
    725725         next if $sw_hostname ne $sw->{hostname};
    726726         $sw_location = $sw->{location};
     
    767767   DETECT_ALL_ROUTER:
    768768#   for my $one_computer ('194.254.66.254') {
    769    for my $one_computer ( get_list_main_router(get_list_network()) ) {
    770       my %resol_arp = resolve_ip_arp_host($one_computer,'*','low');            #resolution arp
     769   for my $one_router ( get_list_main_router(get_list_network()) ) {
     770      my %resol_arp = resolve_ip_arp_host($one_router,'*','low');            #resolution arp
    771771      next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow';
    772772     
     
    802802   my @list_switch_ip = ();
    803803   my @list_switch_ipv4 = ();
    804    for my $sw (@switch){
     804   for my $sw (@SWITCH){
    805805      push @list_switch_ip, $sw->{hostname};
    806806      }
     
    10001000     
    10011001   my %db_building= ();
    1002    for my $sw (@switch) {
     1002   for my $sw (@SWITCH) {
    10031003      my ($building, $location) = split /\//, $sw->{location}, 2;
    10041004      $db_building{$building} ||= {};
Note: See TracChangeset for help on using the changeset viewer.