Changeset 44 for trunk


Ignore:
Timestamp:
Apr 20, 2009, 3:11:17 PM (15 years ago)
Author:
g7moreau
Message:
  • Add HP3500-24G switch model
  • Change to YAML::Syck perl module in replacement to YAML. 10 times faster.
  • Correct bug in resolve_ip_arp_host function
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r43 r44  
    99
    1010use Net::SNMP;
    11 use YAML;
     11#use YAML;
     12use YAML::Syck;
    1213use Net::Netmask;
    1314use Net::CIDR::Lite;
     
    2627test_running_environnement();
    2728
    28 my $KLASK_CFG = YAML::LoadFile("$KLASK_CFG_FILE");
     29my $KLASK_CFG = YAML::Syck::LoadFile("$KLASK_CFG_FILE");
    2930
    3031my %DEFAULT = %{$KLASK_CFG->{default}};
     
    8485   J9022A => { model => 'HP2810-48G', match => 'ProCurve J9022A Switch 2810-48G' },
    8586   J4903A => { model => 'HP2824',     match => 'J4903A.+?Switch 2824,'           },
    86    J8692A => { model => 'HP3500-24G', match => 'J8692A'                          },
    8787   J4110A => { model => 'HP8000M',    match => 'HP J4110A ProCurve Switch 8000M' },
    8888   BS350T => { model => 'BS350T',     match => 'BayStack 350T HW'                },
     
    145145
    146146#   my $cmdarping  = `arping -c 1 -w 1 -rR $param 2>/dev/null`;
     147   if (not $param_ip_or_host =~ m/^\d+\.\d+\.\d+\.\d+$/) {
     148      $param_ip_or_host =~ s/\..*//;
     149      }
    147150
    148151   # controler que arpwatch tourne !
     
    150153   # /var/lib/arpwatch/arp.dat
    151154   # 0:13:d3:e1:92:d0        192.168.24.109  1163681980      theo8sv109
    152    #my $cmd = "grep  -e '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/arp.dat | sort +2rn | head -1";
    153  my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1";
    154    my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/$interface.dat | sort -rn -k 2 | head -1";
     155   # my $cmd = "grep  -e '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/arp.dat | sort +2rn | head -1";
     156   # my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1";
     157   my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
    155158   my $cmd_arpwatch = `$cmd`;
    156159   chomp $cmd_arpwatch;
    157160   my ($arp, $ip, $timestamp, $host) = split /\s+/, $cmd_arpwatch;
     161
    158162#print "OOO $cmd\n";
    159163#print "TTT arp $arp -> $ip pour host $host\n";
     164
    160165   $ret{ipv4_address} = $ip        if $ip;
    161166   $ret{mac_address}  = $arp       if $arp;
     
    171176  # resultat de la commande arp
    172177   # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0
     178   # sw2-batF0-legi.hmg.priv (192.168.22.112) at 00:30:c1:76:9c:01 [ether] on eth0.37
    173179   my $cmd_arp  = `arp -a $param_ip_or_host 2>/dev/null`;
    174180   chomp $cmd_arp;
     
    177183   $ret{ipv4_address} = $2 if(defined($2));
    178184   $ret{mac_address}  = $3 if(defined($3));
     185#print "RET1 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n";
    179186
    180187#   if ($ret{ipv4_address} eq '0.0.0.0' and $ret{mac_address} eq 'unknow'and $ret{hostname_fq} eq 'unknow') {
     
    188195      # resultat de la commande host si parametre est hostname
    189196      # tech7meylan.hmg.inpg.fr has address 194.254.66.240
    190       $cmd_host =~ m/\shas\saddress\s([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/;
    191       $ret{ipv4_address} = $1 if defined $1;
     197      $cmd_host =~ m/(\S*)\shas\saddress\s([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/;
     198      $ret{hostname_fq}  = $1 if defined $1;
     199      $ret{ipv4_address} = $2 if defined $2;
    192200
    193201      $cmd_host =~ m/\b([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.in-addr\.arpa\s/;
     
    196204#      }
    197205
     206#print "RET2 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n";
    198207   unless ($ret{mac_address} eq 'unknow') {
    199208      my @paquets = ();
     
    205214      }
    206215
     216#print "RET3 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n";
    207217   return %ret;
    208218   }
     
    533543
    534544   fastping(@computer);
    535    my $computerdb = YAML::LoadFile("$KLASK_DB_FILE");
     545   my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
    536546   
    537547   LOOP_ON_COMPUTER:
     
    564574
    565575   my $computerdb = {};
    566       $computerdb = YAML::LoadFile("$KLASK_DB_FILE") if -e "$KLASK_DB_FILE";
     576      $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE") if -e "$KLASK_DB_FILE";
    567577   my $timestamp = time;
    568578
     
    579589
    580590   { # Remplis le champs portignore des ports d'inter-connection pour chaque switch
    581    my $switch_connection = YAML::LoadFile("$KLASK_SW_FILE");
     591   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    582592   my %db_switch_output_port       = %{$switch_connection->{output_port}};
    583593   my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}};
     
    724734      $dirdb =~ s#/[^/]*$##;
    725735   mkdir "$dirdb", 0755 unless -d "$dirdb";
    726    YAML::DumpFile("$KLASK_DB_FILE", $computerdb);
     736   YAML::Syck::DumpFile("$KLASK_DB_FILE", $computerdb);
    727737
    728738   for my $one_computer (keys %computer_not_detected) {
     
    738748   test_maindb_environnement();
    739749
    740    my $computerdb = YAML::LoadFile("$KLASK_DB_FILE");
     750   my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
    741751
    742752   LOOP_ON_COMPUTER:
     
    751761      $dirdb =~ s#/[^/]*$##;
    752762   mkdir "$dirdb", 0755 unless -d "$dirdb";
    753    YAML::DumpFile("$KLASK_DB_FILE", $computerdb);
     763   YAML::Syck::DumpFile("$KLASK_DB_FILE", $computerdb);
    754764   }
    755765
     
    757767   test_maindb_environnement();
    758768
    759    my $computerdb = YAML::LoadFile("$KLASK_DB_FILE");
     769   my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
    760770
    761771   printf "%-24s %-4s            %-30s %-15s %-18s %-s\n", qw(Switch Port Hostname IPv4-Address MAC-Address Date);
     
    789799
    790800sub cmd_iplocation {
    791    my $computerdb = YAML::LoadFile("$KLASK_DB_FILE");
     801   my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
    792802
    793803   LOOP_ON_IP_ADDRESS:
     
    889899#   for my $one_computer ('194.254.66.254') {
    890900   for my $one_router ( get_list_main_router(get_list_network()) ) {
     901print "TT$one_router\n";     
    891902      my %resol_arp = resolve_ip_arp_host($one_router,'*','low');            # resolution arp
    892903      next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow';
    893      
     904print "$one_router\n";     
    894905      $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements des routeurs
    895906      }
     
    10541065      };
    10551066     
    1056    YAML::DumpFile("$KLASK_SW_FILE", $switch_connection);
     1067   YAML::Syck::DumpFile("$KLASK_SW_FILE", $switch_connection);
    10571068   }
    10581069
     
    10801091sub cmd_exportsw_txt {
    10811092
    1082    my $switch_connection = YAML::LoadFile("$KLASK_SW_FILE");
     1093   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    10831094
    10841095   my %db_switch_output_port       = %{$switch_connection->{output_port}};
     
    11151126sub cmd_exportsw_dot {
    11161127
    1117    my $switch_connection = YAML::LoadFile("$KLASK_SW_FILE");
     1128   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    11181129   
    11191130   my %db_switch_output_port       = %{$switch_connection->{output_port}};
Note: See TracChangeset for help on using the changeset viewer.