Changeset 22


Ignore:
Timestamp:
Feb 2, 2008, 9:59:29 PM (16 years ago)
Author:
g7moreau
Message:
  • Human Readable Port depend now on the switch model. No anymore hardcore switch hostname !
  • Switch port inter-connection are now add to Portignore in command updatedb. No need to add the portignore directive for each switch in the config file anymore.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r21 r22  
    181181# Find Surname of a switch
    182182sub get_switch_model {
    183    my $sw_description = shift || '?';
     183   my $sw_snmp_description = shift || 'unknow';
    184184   
    185185   for my $sw_kind (keys %SWITCH_KIND) {
    186       next if not $sw_description =~ m/$SWITCH_KIND{$sw_kind}->{match}/;
     186      next if not $sw_snmp_description =~ m/$SWITCH_KIND{$sw_kind}->{match}/;
    187187     
    188188      return $SWITCH_KIND{$sw_kind}->{model};
    189189      }
    190190     
    191    return $sw_description;
     191   return $sw_snmp_description;
    192192   }
    193193
     
    231231      #$sw->{contact} = $result->{"1.3.6.1.2.1.1.4.0"} || $sw->{hostname};
    232232      $session->close;
    233  
     233
     234      # Ligne à virer car on récupère maintenant le modèle du switch
    234235      my ($desc, $type) = split ':', $sw->{description}, 2;
    235236#      printf "%-25s 0--------->>>> %-25s %s\n", $sw->{hostname}, $desc, uc($type)."**" if $verbose;
     
    281282   return %ret if $arp eq 'unknow';;
    282283
    283    my @SWITCH_search = @SWITCH;
     284   my @switch_search = @SWITCH;
    284285   if ($switch_proposal ne '') {
    285286      for my $sw (@SWITCH) {
    286287         next if $sw->{hostname} ne $switch_proposal;
    287          unshift @SWITCH_search, $sw;
     288         unshift @switch_search, $sw;
    288289         last;
    289290         }
     
    293294   
    294295   LOOP_ON_SWITCH:
    295    for my $sw (@SWITCH_search) {
     296   for my $sw (@switch_search) {
    296297      my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} );
    297 print "$error \n" if $error;
    298 #         -hostname   => $sw->{hostname},
    299 #         -community  => $sw->{community} || $DEFAULT{community} || 'public',
    300 #         -port       => $sw->{snmpport}  || $DEFAULT{snmpport}  || 161
    301 #         );
    302 #print "$sw->{hostname} --  $research \n";
     298      print "$error \n" if $error;
     299
    303300      my $result = $session->get_request(
    304301         -varbindlist => [$research]
    305302         );
    306 #      if(defined($result)) {
    307303      if (not defined($result) or $result->{$research} eq 'noSuchInstance') {
    308 #print "$sw->{hostname} --  $research --".$session->error()."\n";
    309304         $session->close;
    310305         next LOOP_ON_SWITCH;
     
    323318         SWITCH_PORT_IGNORE:
    324319         foreach my $p (@{$sw->{portignore}}) {
    325             next SWITCH_PORT_IGNORE if $swport ne get_numerical_port($sw->{hostname},$p);
     320            next SWITCH_PORT_IGNORE if $swport ne get_numerical_port($sw->{model},$p);
    326321#            $flag = 1;
    327322            next LOOP_ON_SWITCH;
     
    330325            $ret{switch_hostname}    = $sw->{hostname};
    331326            $ret{switch_description} = $sw->{description};
    332             $ret{switch_port}        = get_human_readable_port($sw->{hostname}, $swport); # $swport;
     327            $ret{switch_port}        = get_human_readable_port($sw->{model}, $swport); # $swport;
    333328           
    334329            last LOOP_ON_SWITCH;
     
    369364         $ret->{$sw->{hostname}}{hostname}    = $sw->{hostname};
    370365         $ret->{$sw->{hostname}}{description} = $sw->{description};
    371          $ret->{$sw->{hostname}}{port}        = get_human_readable_port($sw->{hostname}, $swport);
     366         $ret->{$sw->{hostname}}{port}        = get_human_readable_port($sw->{model}, $swport);
    372367
    373368         $SWITCH_PORT_COUNT{$sw->{hostname}}->{$swport}++;
     
    433428
    434429sub get_human_readable_port {
    435    my $sw = shift;
    436    my $port = shift;
    437    
    438    return $port if not $sw eq 'sw8000-batA.hmg.priv';
    439    
    440    my $reste = (($port - 1) % 8) + 1;
    441    my $major = int( ($port - 1) / 8 );
     430   my $sw_model = shift;
     431   my $sw_port = shift;
     432   
     433   return $sw_port if not $sw_model eq 'HP8000M';
     434   
     435   my $reste = (($sw_port - 1) % 8) + 1;
     436   my $major = int( ($sw_port - 1) / 8 );
    442437
    443438   return "$INTERNAL_PORT_MAP{$major}$reste";
     
    445440
    446441sub get_numerical_port {
    447    my $sw  = shift;
    448    my $port = shift;
    449    
    450    return $port if not $sw eq 'sw8000-batA.hmg.priv';
    451 
    452    my $letter = substr($port, 0, 1);
     442   my $sw_model = shift;
     443   my $sw_port = shift;
     444   
     445   return $sw_port if not $sw_model eq 'HP8000';
     446
     447   my $letter = substr($sw_port, 0, 1);
    453448   
    454449#   return $port if $letter =~ m/\d/;
    455450   
    456    my $reste =  substr($port, 1);
     451   my $reste =  substr($sw_port, 1);
    457452   
    458453   return $INTERNAL_PORT_MAP_REV{$letter} * 8 + $reste;
     
    527522   my $computerdb = YAML::LoadFile("$KLASK_DB_FILE");
    528523   my $timestamp = time;
    529    
     524
    530525   my %computer_not_detected = ();
    531526   my $timestamp_last_week = $timestamp - (3600 * 24 * 7);
     
    535530   my $i = 0;
    536531   my $detected_computer = 0;
    537    
     532
    538533   init_switch_names('yes');    #nomme les switchs
     534
     535   { # Remplis le champs portignore des ports d'inter-connection pour chaque switch
     536   my $switch_connection = YAML::LoadFile("$KLASK_SW_FILE");
     537   my %db_switch_output_port       = %{$switch_connection->{output_port}};
     538   my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}};
     539   my %db_switch_chained_port = ();
     540   for my $swport (keys %db_switch_connected_on_port) {       
     541      my ($sw_connect,$port_connect) = split ':', $swport;
     542      $db_switch_chained_port{$sw_connect} .= "$port_connect:";
     543      }
     544   for my $sw (@SWITCH){
     545      push @{$sw->{portignore}}, $db_switch_output_port{$sw->{hostname}}  if exists $db_switch_output_port{$sw->{hostname}};
     546      if ( exists $db_switch_chained_port{$sw->{hostname}} ) {
     547         chop $db_switch_chained_port{$sw->{hostname}};
     548         push @{$sw->{portignore}}, split(':',$db_switch_chained_port{$sw->{hostname}});
     549         }
     550#      print "$sw->{hostname} ++ @{$sw->{portignore}}\n";
     551      }
     552   }
    539553
    540554   my %router_mac_ip = ();
Note: See TracChangeset for help on using the changeset viewer.