Changeset 144


Ignore:
Timestamp:
Jan 9, 2016, 10:22:29 PM (9 years ago)
Author:
g7moreau
Message:
  • Search with OID containing VLAN ID
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r143 r144  
    141141   sysLocation     => '1.3.6.1.2.1.1.6.0',
    142142   searchPort1     => '1.3.6.1.2.1.17.4.3.1.2',       # BRIDGE-MIB (802.1D).
    143    searchPort2     => '1.3.6.1.2.1.17.7.1.2.2.1.2.0', # Q-BRIDGE-MIB (802.1Q) replace last 0 with real vlan number if needed
     143   searchPort2     => '1.3.6.1.2.1.17.7.1.2.2.1.2',   # Q-BRIDGE-MIB (802.1Q) add 0 if unknown vlan id
    144144   vlanPortDefault => '1.3.6.1.2.1.17.7.1.4.5.1.1',   # dot1qPvid
    145145   vlanStatus      => '1.3.6.1.2.1.17.7.1.4.3.1.5',   # integer 4 Create, 6 Destroy
     
    229229
    230230   # my $cmd = q{grep  -he '\b} . $param_ip_or_host . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
    231    my $cmd = q{grep  -he '\b} . $ret{ipv4_address} . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
     231   #my $cmd = q{grep  -he '\b} . $ret{ipv4_address} . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
     232   my $cmd = q{grep  -He '\b} . $ret{ipv4_address} . q{\b' } . "/var/lib/arpwatch/$interface.dat" . '| sed -e \'s|^/var/lib/arpwatch/\(.*\)\.dat:|\1 |;\' | sort -rn -k 4,4 | head -1';
     233   #grep -He 194.254.66.252 /var/lib/arpwatch/*.dat | sed -e 's|^/var/lib/arpwatch/\(.*\)\.dat:|\1\t|;' | sort -rn -k 4,4 | head -1
     234
    232235   my $cmd_arpwatch = shell_command $cmd;
    233    my ($arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch;
    234 
     236   #my ($arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch;
     237   my ($interface2, $arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch;
     238
     239   $ret{interface}    = $interface2 || $interface;
    235240   $ret{mac_address}  = $arp       if $arp;
    236241   $ret{timestamp}    = $timestamp if $timestamp;
     
    246251   # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0
    247252   # sw2-batF0-legi.hmg.priv (192.168.22.112) at 00:30:c1:76:9c:01 [ether] on eth0.37
    248    my $cmd_arp  = shell_command "arp -a $param_ip_or_host";
     253   my $cmd_arp  = shell_command "arp -a $param_ip_or_host -i $ret{interface}";
    249254   if ( $cmd_arp =~ m{ (\S*) \s \( ( $RE_IPv4_ADDRESS ) \) \s at \s ( $RE_MAC_ADDRESS ) }xms ) {
    250255      ( $ret{hostname_fq}, $ret{ipv4_address}, $ret{mac_address} )  = ($1, $2, $3);
     
    375380   my $mac_address     = shift;
    376381   my $switch_proposal = shift || q{};
     382   my $vlan_id = shift || 0;
    377383
    378384   my %ret;
     
    392398
    393399   my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address);
    394    my $research2 = $OID_NUMBER{searchPort2} . mac_address_hex_to_dec($mac_address);
     400   my $research2 = $OID_NUMBER{searchPort2} .'.'. $vlan_id . mac_address_hex_to_dec($mac_address);
    395401
    396402   LOOP_ON_SWITCH:
     
    447453sub find_all_switch_port {
    448454   my $mac_address = shift;
     455   my $vlan_id     = shift || 0;
    449456
    450457   my $ret = {};
     
    460467
    461468   my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address);
    462    my $research2 = $OID_NUMBER{searchPort2} . mac_address_hex_to_dec($mac_address);
     469   my $research2 = $OID_NUMBER{searchPort2} .'.'. $vlan_id . mac_address_hex_to_dec($mac_address);
    463470   LOOP_ON_ALL_SWITCH:
    464471   for my $sw (@SWITCH) {
     
    503510   }
    504511
     512sub get_current_vlan_id {
     513   my $vlan_name = shift;
     514
     515   return $KLASK_CFG->{network}{$vlan_name}{'vlan-id'};
     516   }
     517
     518sub get_current_vlan_name_for_interface {
     519   my $interface = shift;
     520
     521   for my $vlan_name (keys %{$KLASK_CFG->{network}}) {
     522      next if $KLASK_CFG->{network}{$vlan_name}{interface} ne $interface;
     523      return $vlan_name;
     524      }
     525   }
     526
    505527###
    506528# liste l'ensemble des adresses ip d'un réseau
     
    698720   for my $clientname (@computer) {
    699721      my %resol_arp = resolve_ip_arp_host($clientname);          #resolution arp
    700       my %where     = find_switch_port($resol_arp{mac_address}); #retrouve l'emplacement
     722      my $vlan_name = get_current_vlan_name_for_interface($resol_arp{interface});
     723      my $vlan_id   = get_current_vlan_id($vlan_name);
     724      my %where     = find_switch_port($resol_arp{mac_address}, '', $vlan_id); #retrouve l'emplacement
    701725
    702726      next LOOP_ON_COMPUTER if $where{switch_description} eq 'unknow' or $resol_arp{hostname_fq} eq 'unknow' or $resol_arp{mac_address} eq 'unknow';
     
    14711495
    14721496      my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address);
    1473       my $research2 = $OID_NUMBER{searchPort2} . mac_address_hex_to_dec($mac_address);
     1497      my $research2 = $OID_NUMBER{searchPort2} .'.'. 0 . mac_address_hex_to_dec($mac_address);
    14741498      print "Klask search OID $research1 on switch $sw_name\n";
    14751499      print "Klask search OID $research2 on switch $sw_name\n";
     
    18391863
    18401864   my $verbose;
     1865   my $vlan_id = 0;
    18411866
    18421867   GetOptions(
    18431868      'verbose|v' => \$verbose,
     1869      'vlan|l=i'  => \$vlan_id,
    18441870      );
    18451871
     
    18711897
    18721898      my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address);
    1873       my $research2 = $OID_NUMBER{searchPort2} . mac_address_hex_to_dec($mac_address);
     1899      my $research2 = $OID_NUMBER{searchPort2} .'.'. $vlan_id . mac_address_hex_to_dec($mac_address);
    18741900      print "Klask search OID $research1 on switch $sw_name\n" if $verbose;
    18751901      print "Klask search OID $research2 on switch $sw_name\n" if $verbose;
     
    19251951      print "VERBOSE_1: Router detected $resol_arp{ipv4_address} - $resol_arp{mac_address}\n" if $verbose;
    19261952
    1927       $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements des routeurs
     1953      my $vlan_name = get_current_vlan_name_for_interface($resol_arp{interface});
     1954      my $vlan_id   = get_current_vlan_id($vlan_name);
     1955      $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address},$vlan_id); # retrouve les emplacements des routeurs
    19281956      }
    19291957
     
    19621990      push @list_switch_ipv4, $resol_arp{ipv4_address};
    19631991
    1964       $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # find port on all switch
     1992      my $vlan_name = get_current_vlan_name_for_interface($resol_arp{interface});
     1993      my $vlan_id   = get_current_vlan_id($vlan_name);
     1994      $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address},$vlan_id); # find port on all switch
    19651995
    19661996      if ($verbose) {
Note: See TracChangeset for help on using the changeset viewer.