Changeset 86 for trunk/klask


Ignore:
Timestamp:
Mar 30, 2011, 3:18:26 PM (13 years ago)
Author:
g7moreau
Message:
  • Cleanup code
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r84 r86  
    107107   sysContact      => '1.3.6.1.2.1.1.4.0',
    108108   sysLocation     => '1.3.6.1.2.1.1.6.0',
     109   searchPort      => '1.3.6.1.2.1.17.4.3.1.2',
    109110   );
    110111
     
    330331###
    331332# convertit l'hexa (uniquement 2 chiffres) en decimal
    332 sub hex_to_dec {
     333sub digit_hex_to_dec {
    333334   #00:0F:1F:43:E4:2B
    334335   my $car = '00' . uc shift;
     
    345346
    346347###
    347 # convertit l'@ arp en decimal
    348 sub arp_hex_to_dec {
     348# convertit l'@ mac en decimal
     349sub mac_address_hex_to_dec {
    349350   #00:0F:1F:43:E4:2B
    350    my $arp = shift;
    351 
    352    my @paquets = split m/ : /xms, $arp;
     351   my $mac_address = shift;
     352
     353   my @paquets = split m/ : /xms, $mac_address;
    353354   my $return = q{};
    354355   foreach(@paquets) {
    355       $return .= q{.} . hex_to_dec($_);
     356      $return .= q{.} . digit_hex_to_dec($_);
    356357      }
    357358   return $return;
     
    361362# va rechercher le port et le switch sur lequel est la machine
    362363sub find_switch_port {
    363    my $arp             = shift;
     364   my $mac_address     = shift;
    364365   my $switch_proposal = shift || q{};
    365366
     
    368369   $ret{switch_port} = '0';
    369370
    370    return %ret if $arp eq 'unknow';;
     371   return %ret if $mac_address eq 'unknow';;
    371372
    372373   my @switch_search = @SWITCH;
     
    379380      }
    380381
    381    my $research = '1.3.6.1.2.1.17.4.3.1.2' . arp_hex_to_dec($arp);
     382   my $research = $OID_NUMBER{searchPort} . mac_address_hex_to_dec($mac_address);
    382383
    383384   LOOP_ON_SWITCH:
     
    426427# va rechercher les port et les switch sur lequel est la machine
    427428sub find_all_switch_port {
    428    my $arp = shift;
     429   my $mac_address = shift;
    429430
    430431   my $ret = {};
    431432
    432    return $ret if $arp eq 'unknow';
    433 
    434    for my $sw (@SWITCH) {
    435       next if exists $SWITCH_PORT_COUNT{$sw->{hostname}};
    436 
    437       $SWITCH_PORT_COUNT{$sw->{hostname}} = {};
     433   return $ret if $mac_address eq 'unknow';
     434
     435#   for my $sw (@SWITCH) {
     436#      next if exists $SWITCH_PORT_COUNT{$sw->{hostname}};
     437#
     438#      $SWITCH_PORT_COUNT{$sw->{hostname}} = {};
    438439#      print "DEBUG: SWITCH_PORT_COUNT defined for $sw->{hostname}\n" if $DEBUG xor 2;
    439       }
    440 
    441    my $research = '1.3.6.1.2.1.17.4.3.1.2' . arp_hex_to_dec($arp);
     440#      }
     441
     442   my $research = $OID_NUMBER{searchPort} . mac_address_hex_to_dec($mac_address);
    442443   LOOP_ON_ALL_SWITCH:
    443444   for my $sw (@SWITCH) {
     
    452453         my $swport = $result->{$research};
    453454
    454 #print "DEBUG $arp  $swport --  $sw->{hostname} \n";
    455 #         if ( $sw->{hostname} eq 'sw10-batE1-3s.hmg.priv' and $swport == 19 ) { $swport = 20; print "DEBUG $swport --  $sw->{hostname} \n";}
    456 #         if ( $sw->{hostname} eq 'sw8-batE1-3s.hmg.priv'  and $swport == 23 ) { $swport = 24; print "DEBUG $swport --  $sw->{hostname} \n";}
    457 #         if ( $sw->{hostname} eq 'sw10-batE1-3s.hmg.priv' ) {  print "DEBUG $swport --  $sw->{hostname} \n";}
    458 #         if ( $sw->{hostname} eq 'sw8-batE1-3s.hmg.priv'  ) {  print "DEBUG $swport --  $sw->{hostname} \n";}
    459 
    460455         $ret->{$sw->{hostname}} = {};
    461456         $ret->{$sw->{hostname}}{hostname}    = $sw->{hostname};
     
    463458         $ret->{$sw->{hostname}}{port}        = get_human_readable_port($sw->{model}, $swport);
    464459
    465          $SWITCH_PORT_COUNT{$sw->{hostname}}->{$swport}++;
     460#         $SWITCH_PORT_COUNT{$sw->{hostname}}->{$swport}++;
    466461         }
    467462
     
    14051400      }
    14061401
    1407    my $research = '1.3.6.1.2.1.17.4.3.1.2' . arp_hex_to_dec($mac_address);
     1402   my $research = $OID_NUMBER{searchPort} . mac_address_hex_to_dec($mac_address);
    14081403   print "Klask search OID $research on switch $switch_name\n";
    14091404
Note: See TracChangeset for help on using the changeset viewer.