Changeset 196


Ignore:
Timestamp:
Jan 5, 2017, 11:32:18 AM (8 years ago)
Author:
g7moreau
Message:
  • Better verbose mode for updatesw, begin delete broken switch
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r195 r196  
    77use strict;
    88use warnings;
    9 use version; our $VERSION = qv('0.5.6');
     9use version; our $VERSION = qv('0.5.7');
    1010
    1111use Readonly;
     
    3434my $KLASK_CFG = YAML::Syck::LoadFile("$KLASK_CFG_FILE");
    3535
    36 my %DEFAULT = %{ $KLASK_CFG->{default} };
    37 my @SWITCH  = @{ $KLASK_CFG->{switch}  };
    38 
    39 my %switch_level = ();
     36my %DEFAULT     = %{$KLASK_CFG->{default}};
     37my @SWITCH_LIST = @{$KLASK_CFG->{switch}};
     38
     39my %SWITCH_LEVEL = ();
    4040my %SWITCH_DB    = ();
    4141LEVEL_OF_EACH_SWITCH:
    42 for my $sw (@SWITCH){
    43    $switch_level{$sw->{hostname}} = $sw->{level} || $DEFAULT{switch_level}  || 2;
     42for my $sw (@SWITCH_LIST){
     43   $SWITCH_LEVEL{$sw->{hostname}} = $sw->{level} || $DEFAULT{switch_level}  || 2;
    4444   $SWITCH_DB{$sw->{hostname}} = $sw;
    4545   }
    46 @SWITCH = reverse sort { $switch_level{$a->{hostname}} <=> $switch_level{$b->{hostname}} } @{$KLASK_CFG->{switch}};
    47 
    48 my %SWITCH_PORT_COUNT = ();
     46@SWITCH_LIST = reverse sort { $SWITCH_LEVEL{$a->{hostname}} <=> $SWITCH_LEVEL{$b->{hostname}} } @{$KLASK_CFG->{switch}};
     47
     48#my %SWITCH_PORT_COUNT = ();
    4949
    5050my %CMD_DB = (
     
    270270#      }
    271271   if ($ret{mac_address} eq 'unknow') {
    272       # Another chance to have mac_address
     272      # Last chance to have the mac_address
    273273      my $cmd_arp  = shell_command "ip neigh show to $ret{ipv4_address} dev $ret{interface}";
    274274      if ( $cmd_arp =~ m{ ^$RE_IPv4_ADDRESS \s lladdr \s ( $RE_MAC_ADDRESS ) \s }xms ) {
     
    313313
    314314   INIT_EACH_SWITCH:
    315    for my $sw (@SWITCH) {
     315   for my $sw (@SWITCH_LIST) {
    316316      my %session = ( -hostname   => $sw->{hostname} );
    317317         $session{-version} = $sw->{version}   || 1;
     
    337337            ]
    338338         );
     339      if (!defined $result) {
     340         printf {*STDERR} "ERROR: %s.\n", $session->error();
     341         $session->close();
     342         # Remove bad switch
     343         @SWITCH_LIST = grep { $_->{hostname} ne $sw->{hostname} } @SWITCH_LIST;
     344         delete $SWITCH_LEVEL{$sw->{hostname}} if exists $SWITCH_LEVEL{$sw->{hostname}};
     345         delete $SWITCH_DB{$sw->{hostname}}    if exists $SWITCH_DB{$sw->{hostname}};
     346         next INIT_EACH_SWITCH;
     347         }
     348
    339349      $sw->{description} = $result->{$OID_NUMBER{sysName}} || $sw->{hostname};
    340350      $sw->{model} = get_switch_model($result->{$OID_NUMBER{sysDescription}});
     
    358368
    359369      # Ligne à virer car on récupère maintenant le modèle du switch
    360       my ($desc, $type) = split m/ : /xms, $sw->{description}, 2;
     370      #my ($desc, $type) = split m/ : /xms, $sw->{description}, 2;
    361371      printf "%-26s 0--------->>>> %-25s %s\n", $sw->{hostname}, $desc, $sw->{model} if $verbose;
    362372      }
     
    424434   return %ret if $mac_address eq 'unknow';;
    425435
    426    my @switch_search = @SWITCH;
     436   my @switch_search = @SWITCH_LIST;
    427437   if ($switch_proposal ne q{}) {
    428       for my $sw (@SWITCH) {
     438      for my $sw (@SWITCH_LIST) {
    429439         next if $sw->{hostname} ne $switch_proposal;
    430440         unshift @switch_search, $sw;
     
    495505   my $research2 = $OID_NUMBER{searchPort2} .'.'. $vlan_id . mac_address_hex_to_dec($mac_address);
    496506   LOOP_ON_ALL_SWITCH:
    497    for my $sw (@SWITCH) {
     507   for my $sw (@SWITCH_LIST) {
    498508      my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} );
    499509      print "$error \n" if $error;
     
    949959      $db_switch_chained_port{$sw_connect} .= "$port_connect:";
    950960      }
    951    for my $sw (@SWITCH){
     961   for my $sw (@SWITCH_LIST){
    952962      push @{$sw->{portignore}}, $db_switch_output_port{$sw->{hostname}}  if exists $db_switch_output_port{$sw->{hostname}};
    953963      if ( exists $db_switch_chained_port{$sw->{hostname}} ) {
     
    10031013
    10041014         # do not search on switch inter-connection
    1005          if (exists $switch_level{$resol_arp{hostname_fq}}) {
     1015         if (exists $SWITCH_LEVEL{$resol_arp{hostname_fq}}) {
    10061016            $computer_not_detected{$one_computer} = $current_net;
    10071017            next LOOP_ON_COMPUTER;
     
    16161626      }
    16171627
    1618    $switch_name = join(',', map {$_->{hostname}} @SWITCH ) if $switch_name eq q{*};
     1628   $switch_name = join(',', map {$_->{hostname}} @SWITCH_LIST ) if $switch_name eq q{*};
    16191629
    16201630   for my $sw_name (split /,/, $switch_name) {
     
    17721782      }
    17731783
    1774    $switch_name = join(',', map {$_->{hostname}} @SWITCH ) if $switch_name eq q{*};
     1784   $switch_name = join(',', map {$_->{hostname}} @SWITCH_LIST ) if $switch_name eq q{*};
    17751785
    17761786   for my $sw_name (split /,/, $switch_name) {
     
    18251835      my $sw_location = q{};
    18261836      LOOP_ON_ALL_SWITCH:
    1827       for my $sw (@SWITCH) {
     1837      for my $sw (@SWITCH_LIST) {
    18281838         next LOOP_ON_ALL_SWITCH if $sw_hostname ne $sw->{hostname};
    18291839         $sw_location = $sw->{location};
     
    20212031
    20222032   $mac_address = normalize_mac_address($mac_address);
    2023    $switch_name = join(',', map {$_->{hostname}} @SWITCH ) if $switch_name eq q{*};
     2033   $switch_name = join(',', map {$_->{hostname}} @SWITCH_LIST ) if $switch_name eq q{*};
    20242034
    20252035   for my $sw_name (split /,/, $switch_name) {
     
    20882098
    20892099   DETECT_ALL_ROUTER:
    2090 #   for my $one_computer ('194.254.66.254') {
    20912100   for my $one_router ( get_list_main_router(get_list_network()) ) {
     2101      print "Info: router loop $one_router\n" if $verbose;
    20922102      my %resol_arp = resolve_ip_arp_host($one_router, q{*}, q{low}); # resolution arp
    20932103
     
    21212131   my @list_all_switch = ();
    21222132   my @list_switch_ipv4 = ();
    2123    for my $sw (@SWITCH){
     2133   for my $sw (@SWITCH_LIST){
    21242134      push @list_all_switch, $sw->{hostname};
    21252135      }
     
    21302140   for my $one_computer (@list_all_switch) {
    21312141      my %resol_arp = resolve_ip_arp_host($one_computer, q{*}, q{low}); # arp resolution
     2142      print "Info: switch loop $one_computer\n" if $verbose;
    21322143      next ALL_SWITCH if $resol_arp{mac_address} eq 'unknow';
    21332144
     
    23482359
    23492360   my %db_building= ();
    2350    for my $sw (@SWITCH) {
     2361   for my $sw (@SWITCH_LIST) {
    23512362      my ($building, $location) = split m/ \/ /xms, $sw->{location}, 2;
    23522363      $db_building{$building} ||= {};
Note: See TracChangeset for help on using the changeset viewer.