Changeset 404


Ignore:
Timestamp:
Oct 4, 2018, 10:36:06 AM (6 years ago)
Author:
g7moreau
Message:
  • Small format change
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r402 r404  
    298298   $ret{'hostname_fq'} = $hostname_fq if defined $hostname_fq;
    299299
    300    # my $cmd = q{grep  -he '\b} . $param_ip_or_host . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
    301    #my $cmd = q{grep  -he '\b} . $ret{'ipv4_address'} . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
    302    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';
    303    #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
    304 
     300   my $cmd = q{grep -He '\b}
     301      . $ret{'ipv4_address'} . q{\b' }
     302      . "/var/lib/arpwatch/$interface.dat"
     303      . '| sed -e \'s|^/var/lib/arpwatch/\(.*\)\.dat:|\1 |;\' | sort -rn -k 4,4 | head -1';
    305304   my $cmd_arpwatch = shell_command $cmd;
    306    #my ($arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch;
    307305   my ($interface2, $arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch;
    308306
     
    661659            }
    662660
    663          $ret->{$sw->{'hostname'}} = {};
     661         $ret->{$sw->{'hostname'}}                = {};
    664662         $ret->{$sw->{'hostname'}}{'hostname'}    = $sw->{'hostname'};
    665663         $ret->{$sw->{'hostname'}}{'description'} = $sw->{'description'};
     
    12521250   LOOP_ON_COMPUTER:
    12531251   for my $clientname (@computer) {
    1254       my %resol_arp = resolve_ip_arp_host($clientname); # resolution arp
     1252      my %resol_arp = resolve_ip_arp_host($clientname);                          # resolution arp
    12551253      my $vlan_name = get_current_vlan_name_for_interface($resol_arp{'interface'});
    12561254      my $vlan_id   = get_current_vlan_id($vlan_name);
    12571255      my %where     = find_switch_port($resol_arp{'mac_address'}, '', $vlan_id); # retrouve l'emplacement
    12581256
    1259       next LOOP_ON_COMPUTER if $where{'switch_description'} eq 'unknow' or $resol_arp{'hostname_fq'} eq 'unknow' or $resol_arp{'mac_address'} eq 'unknow';
     1257      next LOOP_ON_COMPUTER
     1258         if $where{'switch_description'} eq 'unknow'
     1259         or $resol_arp{'hostname_fq'}    eq 'unknow'
     1260         or $resol_arp{'mac_address'}    eq 'unknow';
    12601261
    12611262      printf '%-22s %2s %-30s %-15s %18s',
     
    13861387
    13871388   {
    1388    my $switch_checksum = get_switchdb_checksum(%SWITCH_DB);
    1389    # Remplis le champs portignore des ports d'inter-connection pour chaque switch
    1390    my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    1391    if ($switch_checksum ne $switch_connection->{'checksum'}) { # Verify checksum
    1392       if ($no_rebuildsw) {
    1393          print "WARNING: switch database is outdate, please rebuild if with updatesw command\n";
    1394          }
    1395       else {
    1396          print "WARNING: switch database is going to be rebuilt\n";
    1397          update_switchdb(verbose => $verbose)
    1398          }
    1399       }
    1400 
    1401    my %db_switch_output_port       = %{$switch_connection->{'output_port'}};
    1402    my %db_switch_connected_on_port = %{$switch_connection->{'connected_on_port'}};
    1403    my %db_switch_chained_port = ();
    1404    for my $swport (keys %db_switch_connected_on_port) {
    1405       my ($sw_connect, $port_connect) = split m/ $SEP_SWITCH_PORT /xms, $swport, 2;
    1406       $db_switch_chained_port{$sw_connect} .= "$port_connect:";
    1407       }
    1408    for my $sw (@SWITCH_LIST) {
    1409       push @{$sw->{'portignore'}}, $db_switch_output_port{$sw->{'hostname'}} if exists $db_switch_output_port{$sw->{'hostname'}};
    1410       if ( exists $db_switch_chained_port{$sw->{'hostname'}} ) {
    1411          chop $db_switch_chained_port{$sw->{'hostname'}};
    1412          push @{$sw->{'portignore'}}, split m/ : /xms, $db_switch_chained_port{$sw->{'hostname'}};
    1413          }
    1414 #      print "$sw->{'hostname'} ++ @{$sw->{'portignore'}}\n";
    1415       }
    1416    }
     1389      my $switch_checksum = get_switchdb_checksum(%SWITCH_DB);
     1390      # Remplis le champs portignore des ports d'inter-connection pour chaque switch
     1391      my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
     1392      if ($switch_checksum ne $switch_connection->{'checksum'}) { # Verify checksum
     1393         if ($no_rebuildsw) {
     1394            print "WARNING: switch database is outdate, please rebuild if with updatesw command\n";
     1395            }
     1396         else {
     1397            print "WARNING: switch database is going to be rebuilt\n";
     1398            update_switchdb(verbose => $verbose)
     1399            }
     1400         }
     1401
     1402      my %db_switch_output_port       = %{$switch_connection->{'output_port'}};
     1403      my %db_switch_connected_on_port = %{$switch_connection->{'connected_on_port'}};
     1404      my %db_switch_chained_port = ();
     1405      for my $swport (keys %db_switch_connected_on_port) {
     1406         my ($sw_connect, $port_connect) = split m/ $SEP_SWITCH_PORT /xms, $swport, 2;
     1407         $db_switch_chained_port{$sw_connect} .= "$port_connect:";
     1408         }
     1409      for my $sw (@SWITCH_LIST) {
     1410         push @{$sw->{'portignore'}}, $db_switch_output_port{$sw->{'hostname'}} if exists $db_switch_output_port{$sw->{'hostname'}};
     1411         if (exists $db_switch_chained_port{$sw->{'hostname'}}) {
     1412            chop $db_switch_chained_port{$sw->{'hostname'}};
     1413            push @{$sw->{'portignore'}}, split m/ : /xms, $db_switch_chained_port{$sw->{'hostname'}};
     1414            }
     1415         #print "$sw->{'hostname'} ++ @{$sw->{'portignore'}}\n";
     1416         }
     1417      }
    14171418
    14181419   my %router_mac_ip = ();
     
    14711472
    14721473         # do not have a mac address
    1473          if ($resol_arp{'mac_address'} eq 'unknow' or (exists $resol_arp{'timestamps'} and $resol_arp{'timestamps'} < ($timestamp - 3 * 3600))) {
     1474         if ($resol_arp{'mac_address'} eq 'unknow'
     1475               or (exists $resol_arp{'timestamps'} and $resol_arp{'timestamps'} < ($timestamp - 3 * 3600))
     1476               ) {
    14741477            $computer_not_detected{$one_computer} = $current_net;
    14751478            next LOOP_ON_COMPUTER;
     
    15281531
    15291532         # mise à jour de la date de détection si détection plus récente par arpwatch
    1530          $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'}   = $resol_arp{'timestamp'} if exists $resol_arp{'timestamp'} and $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $resol_arp{'timestamp'};
     1533         $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'}   = $resol_arp{'timestamp'}
     1534            if exists $resol_arp{'timestamp'} and $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $resol_arp{'timestamp'};
    15311535
    15321536         # relance un arping sur la machine si celle-ci n'a pas été détectée depuis plus d'une semaine
    1533          # push @computer_not_detected, $resol_arp{'ipv4_address'} if $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week;
    1534          $computer_not_detected{$resol_arp{'ipv4_address'}} = $current_net if $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week;
     1537         $computer_not_detected{$resol_arp{'ipv4_address'}} = $current_net
     1538           if $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week;
    15351539
    15361540         }
     
    15451549      my $current_net       = $computer_not_detected{$one_computer};
    15461550      my $current_interface = get_current_interface($current_net);
    1547       system "arping -c 1 -w 1 -rR -i $current_interface $one_computer > /dev/null 2>&1" if get_current_scan_mode($current_net) eq 'active';
     1551      system "arping -c 1 -w 1 -rR -i $current_interface $one_computer > /dev/null 2>&1"
     1552         if get_current_scan_mode($current_net) eq 'active';
    15481553      }
    15491554   return;
     
    18071812
    18081813      # to be improve in the future
    1809       next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself !
     1814      next LOOP_ON_IP_ADDRESS
     1815         if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself !
    18101816
    18111817      my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $computerdb->{$ip}{'timestamp'};
     
    19101916
    19111917      my $vlan = '';
    1912       $vlan = $computerdb->{$ip}{'network'}.' ('.get_current_vlan_id($computerdb->{$ip}{'network'}).')' if $computerdb->{$ip}{'network'};
     1918      $vlan = $computerdb->{$ip}{'network'} . ' (' . get_current_vlan_id($computerdb->{$ip}{'network'}) . ')'
     1919         if $computerdb->{$ip}{'network'};
    19131920
    19141921      my $parent_port_hr = format_aggregator4html($computerdb->{$ip}{'switch_port_hr'});
     
    27882795            LOOP_ON_DATABASE:
    27892796            for my $ip_db (keys %{$computerdb}) {
    2790                next LOOP_ON_DATABASE if $computerdb->{$ip_db}{'mac_address'} ne $mac_address;
     2797               next LOOP_ON_DATABASE   if $computerdb->{$ip_db}{'mac_address'} ne $mac_address;
    27912798               next LOOP_ON_IP_ADDRESS if $computerdb->{$ip_db}{'timestamp'} > $timestamp_barrier;
    27922799               }
     
    28032810         my $packed_ip   = scalar gethostbyname($ip);
    28042811         my $hostname_fq = 'unknown';
    2805             $hostname_fq = scalar gethostbyaddr($packed_ip, AF_INET) || 'unknown' if defined $packed_ip and get_current_scan_mode($vlan) eq 'active';
     2812            $hostname_fq = scalar gethostbyaddr($packed_ip, AF_INET) || 'unknown'
     2813               if defined $packed_ip and get_current_scan_mode($vlan) eq 'active';
    28062814
    28072815         next LOOP_ON_IP_ADDRESS if $hostname_fq =~ m/$RE_FLOAT_HOSTNAME/;
     
    31493157
    31503158   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    3151    my $interway = 0;
     3159   my $interway          = 0;
    31523160
    31533161   if ($args{'way'} =~ m/all|desc/) {
Note: See TracChangeset for help on using the changeset viewer.