Changeset 261


Ignore:
Timestamp:
Sep 14, 2017, 8:50:26 PM (7 years ago)
Author:
g7moreau
Message:
  • rewrite hash key with quote
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r260 r261  
    4545LEVEL_OF_EACH_SWITCH:
    4646for my $sw (@SWITCH_LIST) {
    47    $SWITCH_LEVEL{$sw->{hostname}} = $sw->{'level'} || $DEFAULT{'switch_level'}  || 2;
    48    $SWITCH_DB{$sw->{hostname}} = $sw;
     47   $SWITCH_LEVEL{$sw->{'hostname'}} = $sw->{'level'} || $DEFAULT{'switch_level'}  || 2;
     48   $SWITCH_DB{$sw->{'hostname'}} = $sw;
    4949
    5050   # SNMP parameter initialisation
    51    my %session = ( -hostname   => $sw->{hostname} );
     51   my %session = ( -hostname   => $sw->{'hostname'} );
    5252   $session{-version} = $sw->{'version'}  || 1;
    5353   $session{-port}    = $sw->{'snmpport'} || $DEFAULT{'snmpport'}  || 161;
     
    6060   $sw->{'snmp_param_session'} = \%session;
    6161   }
    62 @SWITCH_LIST = reverse sort { $SWITCH_LEVEL{$a->{hostname}} <=> $SWITCH_LEVEL{$b->{hostname}} } @{$KLASK_CFG->{'switch'}};
     62@SWITCH_LIST = reverse sort { $SWITCH_LEVEL{$a->{'hostname'}} <=> $SWITCH_LEVEL{$b->{'hostname'}} } @{$KLASK_CFG->{'switch'}};
    6363
    6464#my %SWITCH_PORT_COUNT = ();
     
    273273   my $packed_ip = scalar gethostbyname($param_ip_or_host);
    274274   return %ret if not defined $packed_ip;
    275    $ret{ipv4_address} = inet_ntoa($packed_ip);
    276    #if ($ret{ipv4_address} !~ m/$RE_IPv4_ADDRESS/) {
    277    #   print "Error: for computer $param_ip_or_host on interface $interface, IP $ret{ipv4_address} is not valide\n";
     275   $ret{'ipv4_address'} = inet_ntoa($packed_ip);
     276   #if ($ret{'ipv4_address'} !~ m/$RE_IPv4_ADDRESS/) {
     277   #   print "Error: for computer $param_ip_or_host on interface $interface, IP $ret{'ipv4_address'} is not valide\n";
    278278   #   return %ret;
    279279   #   }
     
    281281   # perl -MSocket -E 'say scalar gethostbyaddr(inet_aton("194.254.66.240"), AF_INET)'
    282282   my $hostname_fq = scalar gethostbyaddr($packed_ip, AF_INET) if $already eq 'yes';
    283    $ret{hostname_fq} = $hostname_fq if defined $hostname_fq;
     283   $ret{'hostname_fq'} = $hostname_fq if defined $hostname_fq;
    284284
    285285   # my $cmd = q{grep  -he '\b} . $param_ip_or_host . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
    286    #my $cmd = q{grep  -he '\b} . $ret{ipv4_address} . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
    287    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';
     286   #my $cmd = q{grep  -he '\b} . $ret{'ipv4_address'} . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
     287   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';
    288288   #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
    289289
     
    292292   my ($interface2, $arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch;
    293293
    294    $ret{interface}    = $interface2 || $interface;
    295    $ret{mac_address}  = $arp       if $arp;
    296    $ret{timestamp}    = $timestamp if $timestamp;
     294   $ret{'interface'}    = $interface2 || $interface;
     295   $ret{'mac_address'}  = $arp       if $arp;
     296   $ret{'timestamp'}    = $timestamp if $timestamp;
    297297
    298298   my $nowtimestamp = time;
    299299
    300300   if ( $type eq 'fast' and ( not defined $timestamp or $timestamp < ( $nowtimestamp - 45 * 60 ) ) ) { # 45 min
    301       $ret{mac_address} = 'unknow';
     301      $ret{'mac_address'} = 'unknow';
    302302      return %ret;
    303303      }
     
    312312   # LANG=C ip neigh show to 194.254.66.62
    313313   # 194.254.66.62 dev eth331 lladdr 00:08:7c:bb:0f:c0 REACHABLE
    314 #   my $cmd_arp  = shell_command "arp -a $param_ip_or_host -i $ret{interface}";
     314#   my $cmd_arp  = shell_command "arp -a $param_ip_or_host -i $ret{'interface'}";
    315315#   if ( $cmd_arp =~ m{ (\S*) \s \( ( $RE_IPv4_ADDRESS ) \) \s at \s ( $RE_MAC_ADDRESS ) }xms ) {
    316 #      ( $ret{hostname_fq}, $ret{ipv4_address}, $ret{mac_address} )  = ($1, $2, $3);
     316#      ( $ret{'hostname_fq'}, $ret{'ipv4_address'}, $ret{'mac_address'} )  = ($1, $2, $3);
    317317#      }
    318    if ($ret{mac_address} eq 'unknow') {
     318   if ($ret{'mac_address'} eq 'unknow') {
    319319      # Last chance to have the mac_address
    320       if ($ret{interface} eq '*') {
    321          my $cmd_arp  = shell_command "ip neigh show to $ret{ipv4_address}";
     320      if ($ret{'interface'} eq '*') {
     321         my $cmd_arp  = shell_command "ip neigh show to $ret{'ipv4_address'}";
    322322         if ( $cmd_arp =~ m{ ^$RE_IPv4_ADDRESS \s dev \s ([\w\d\.\:]+) \s lladdr \s ( $RE_MAC_ADDRESS ) \s }xms ) {
    323             ($ret{interface}, $ret{mac_address}) = ($1, $2);
     323            ($ret{'interface'}, $ret{'mac_address'}) = ($1, $2);
    324324            }
    325325         }
    326326      else {
    327          my $cmd_arp  = shell_command "ip neigh show to $ret{ipv4_address} dev $ret{interface}";
     327         my $cmd_arp  = shell_command "ip neigh show to $ret{'ipv4_address'} dev $ret{'interface'}";
    328328         if ( $cmd_arp =~ m{ ^$RE_IPv4_ADDRESS \s lladdr \s ( $RE_MAC_ADDRESS ) \s }xms ) {
    329             $ret{mac_address} = $1;
     329            $ret{'mac_address'} = $1;
    330330            }
    331331         }
     
    333333
    334334   # Normalize MAC Address
    335    if ($ret{mac_address} ne 'unknow') {
     335   if ($ret{'mac_address'} ne 'unknow') {
    336336      my @paquets = ();
    337       for ( split m/ : /xms, $ret{mac_address} ) {
     337      for ( split m/ : /xms, $ret{'mac_address'} ) {
    338338         my @chars = split m//xms, uc "00$_";
    339339         push @paquets, "$chars[-2]$chars[-1]";
    340340         }
    341       $ret{mac_address} = join q{:}, @paquets;
     341      $ret{'mac_address'} = join q{:}, @paquets;
    342342      }
    343343
     
    375375      my $result = $session->get_request(
    376376         -varbindlist => [
    377             $OID_NUMBER{sysDescription},
    378             $OID_NUMBER{sysName},
    379             $OID_NUMBER{sysContact},
    380             $OID_NUMBER{sysLocation},
     377            $OID_NUMBER{'sysDescription'},
     378            $OID_NUMBER{'sysName'},
     379            $OID_NUMBER{'sysContact'},
     380            $OID_NUMBER{'sysLocation'},
    381381            ]
    382382         );
     
    385385         $session->close();
    386386         # Remove bad switch
    387          @SWITCH_LIST = grep { $_->{hostname} ne $sw->{hostname} } @SWITCH_LIST;
    388          delete $SWITCH_LEVEL{$sw->{hostname}} if exists $SWITCH_LEVEL{$sw->{hostname}};
    389          delete $SWITCH_DB{$sw->{hostname}}    if exists $SWITCH_DB{$sw->{hostname}};
     387         @SWITCH_LIST = grep { $_->{'hostname'} ne $sw->{'hostname'} } @SWITCH_LIST;
     388         delete $SWITCH_LEVEL{$sw->{'hostname'}} if exists $SWITCH_LEVEL{$sw->{'hostname'}};
     389         delete $SWITCH_DB{$sw->{'hostname'}}    if exists $SWITCH_DB{$sw->{'hostname'}};
    390390         next INIT_EACH_SWITCH;
    391391         }
    392392
    393       $sw->{description} = $result->{$OID_NUMBER{sysName}} || $sw->{hostname};
    394       $sw->{model} = get_switch_model($result->{$OID_NUMBER{sysDescription}});
     393      $sw->{description} = $result->{$OID_NUMBER{'sysName'}} || $sw->{'hostname'};
     394      $sw->{model} = get_switch_model($result->{$OID_NUMBER{'sysDescription'}});
    395395      if ($verb_description) {
    396          my $desc = $result->{$OID_NUMBER{sysDescription}};
     396         my $desc = $result->{$OID_NUMBER{'sysDescription'}};
    397397         $desc =~ s/[\n\r]/ /g;
    398398         print "   description: $desc\n"
    399399         }
    400400      if ($check_hostname) {
    401          my ($hostname) = split /\./, $sw->{hostname}, 2;
    402          print " $hostname - error internal hostname: $sw->{hostname}\n" if $result->{$OID_NUMBER{sysName}} ne $hostname;
     401         my ($hostname) = split /\./, $sw->{'hostname'}, 2;
     402         print " $hostname - error internal hostname: $sw->{'hostname'}\n" if $result->{$OID_NUMBER{'sysName'}} ne $hostname;
    403403         }
    404404      if ($check_location) {
    405          my $location = $result->{$OID_NUMBER{sysLocation}};
     405         my $location = $result->{$OID_NUMBER{'sysLocation'}};
    406406         $location =~ s/^"(.+)"$/$1/;
    407          print " $sw->{hostname} - error location: '$location' -> '$sw->{location}'\n" if $location ne $sw->{location};
    408          }
    409       #$sw->{location} = $result->{"1.3.6.1.2.1.1.6.0"} || $sw->{hostname};
    410       #$sw->{contact} = $result->{"1.3.6.1.2.1.1.4.0"} || $sw->{hostname};
     407         print " $sw->{'hostname'} - error location: '$location' -> '$sw->{'location'}'\n" if $location ne $sw->{'location'};
     408         }
     409      #$sw->{'location'} = $result->{"1.3.6.1.2.1.1.6.0"} || $sw->{'hostname'};
     410      #$sw->{contact} = $result->{"1.3.6.1.2.1.1.4.0"} || $sw->{'hostname'};
    411411      $session->close;
    412412
    413413      # Ligne à virer car on récupère maintenant le modèle du switch
    414414      #my ($desc, $type) = split m/ : /xms, $sw->{description}, 2;
    415       printf "%-26s 0--------->>>> %-25s %s\n", $sw->{hostname}, $sw->{description}, $sw->{model} if $verbose;
     415      printf "%-26s 0--------->>>> %-25s %s\n", $sw->{'hostname'}, $sw->{description}, $sw->{model} if $verbose;
    416416      }
    417417
     
    490490
    491491   my %ret;
    492    $ret{switch_description} = 'unknow';
    493    $ret{switch_port} = '0';
     492   $ret{'switch_description'} = 'unknow';
     493   $ret{'switch_port'} = '0';
    494494
    495495   return %ret if $mac_address eq 'unknow';;
     
    498498   if ($switch_proposal ne q{}) {
    499499      for my $sw (@SWITCH_LIST) {
    500          next if $sw->{hostname} ne $switch_proposal;
     500         next if $sw->{'hostname'} ne $switch_proposal;
    501501         unshift @switch_search, $sw;
    502502         last;
     
    545545         }
    546546
    547       $ret{switch_hostname}    = $sw->{hostname};
    548       $ret{switch_description} = $sw->{description};
    549       $ret{switch_port}        = $swport_num;
    550       $ret{switch_port_hr}     = $swport_hr; # human readable
     547      $ret{'switch_hostname'}    = $sw->{'hostname'};
     548      $ret{'switch_description'} = $sw->{description};
     549      $ret{'switch_port'}        = $swport_num;
     550      $ret{'switch_port_hr'}     = $swport_hr; # human readable
    551551
    552552      last LOOP_ON_SWITCH;
     
    594594            }
    595595
    596          $ret->{$sw->{hostname}} = {};
    597          $ret->{$sw->{hostname}}{hostname}    = $sw->{hostname};
    598          $ret->{$sw->{hostname}}{description} = $sw->{description};
    599          $ret->{$sw->{hostname}}{port}        = $swport_num;
    600          $ret->{$sw->{hostname}}{port_hr}     = $swport_hr;
     596         $ret->{$sw->{'hostname'}} = {};
     597         $ret->{$sw->{'hostname'}}{'hostname'}    = $sw->{'hostname'};
     598         $ret->{$sw->{'hostname'}}{description} = $sw->{description};
     599         $ret->{$sw->{'hostname'}}{port}        = $swport_num;
     600         $ret->{$sw->{'hostname'}}{'port_hr'}     = $swport_hr;
    601601         }
    602602
     
    616616   my $vlan_name = shift;
    617617
    618    return $KLASK_CFG->{network}{$vlan_name}{interface};
     618   return $KLASK_CFG->{network}{$vlan_name}{'interface'};
    619619   }
    620620
     
    639639
    640640   for my $vlan_name (keys %{$KLASK_CFG->{network}}) {
    641       next if $KLASK_CFG->{network}{$vlan_name}{interface} ne $interface;
     641      next if $KLASK_CFG->{network}{$vlan_name}{'interface'} ne $interface;
    642642      return $vlan_name;
    643643      }
     
    723723   # First get the index, second get the name
    724724
    725    my $research_index = $OID_NUMBER{ifIndex} .'.'. $swport_num;
     725   my $research_index = $OID_NUMBER{'ifIndex'} .'.'. $swport_num;
    726726   my $result_index = $snmp_session->get_request(
    727727      -varbindlist => [$research_index]
     
    738738   my ($snmp_session, $swport_index) = @_;
    739739
    740    my $research_hr = $OID_NUMBER{ifName} .'.'. $swport_index;
     740   my $research_hr = $OID_NUMBER{'ifName'} .'.'. $swport_index;
    741741   my $result_hr = $snmp_session->get_request(
    742742      -varbindlist => [$research_hr]
     
    747747   # Aggregator port
    748748   if ($swport_hr =~ m/^(Trk|Br|Po)/) {
    749       my $research_index = $OID_NUMBER{ifAggregator}; # base OID
     749      my $research_index = $OID_NUMBER{'ifAggregator'}; # base OID
    750750      my @args = ( -varbindlist =>  [$research_index]);
    751751      LOOP_ON_OID_PORT:
     
    785785   return $swport_num if $swport_num =~ m/^\d+$/;
    786786
    787    my $research_index = $OID_NUMBER{ifIndex}; # base OID
     787   my $research_index = $OID_NUMBER{'ifIndex'}; # base OID
    788788   my @args = ( -varbindlist =>  [$research_index]);
    789789   LOOP_ON_OID_PORT:
     
    799799      @args = (-varbindlist => [$oid_current]);
    800800     
    801       my $oid_ifName = $OID_NUMBER{ifName} .'.'. $port_ifIndex;
     801      my $oid_ifName = $OID_NUMBER{'ifName'} .'.'. $port_ifIndex;
    802802      my $result = $snmp_session->get_request(-varbindlist => [$oid_ifName]);
    803803      next LOOP_ON_OID_PORT if not defined $result;
     
    823823   my %vlan = (); # Hash vlan number => vlan name
    824824
    825    my $research_index = $OID_NUMBER{vlanName}; # base OID
     825   my $research_index = $OID_NUMBER{'vlanName'}; # base OID
    826826   my @args = ( -varbindlist =>  [$research_index]);
    827827   LOOP_ON_VLAN:
     
    850850   for my $ip (keys %{$computerdb}) {
    851851
    852       next LOOP_ON_IP_ADDRESS if exists $computerdb->{$ip}{switch_port_hr} and defined $computerdb->{$ip}{switch_port_hr};
    853 
    854       $computerdb->{$ip}{switch_port_hr} = $computerdb->{$ip}{switch_port};
     852      next LOOP_ON_IP_ADDRESS if exists $computerdb->{$ip}{'switch_port_hr'} and defined $computerdb->{$ip}{'switch_port_hr'};
     853
     854      $computerdb->{$ip}{'switch_port_hr'} = $computerdb->{$ip}{'switch_port'};
    855855      }
    856856
     
    923923   for my $clientname (@computer) {
    924924      my %resol_arp = resolve_ip_arp_host($clientname);          #resolution arp
    925       my $vlan_name = get_current_vlan_name_for_interface($resol_arp{interface});
     925      my $vlan_name = get_current_vlan_name_for_interface($resol_arp{'interface'});
    926926      my $vlan_id   = get_current_vlan_id($vlan_name);
    927       my %where     = find_switch_port($resol_arp{mac_address}, '', $vlan_id); #retrouve l'emplacement
    928 
    929       next LOOP_ON_COMPUTER if $where{switch_description} eq 'unknow' or $resol_arp{hostname_fq} eq 'unknow' or $resol_arp{mac_address} eq 'unknow';
     927      my %where     = find_switch_port($resol_arp{'mac_address'}, '', $vlan_id); #retrouve l'emplacement
     928
     929      next LOOP_ON_COMPUTER if $where{'switch_description'} eq 'unknow' or $resol_arp{'hostname_fq'} eq 'unknow' or $resol_arp{'mac_address'} eq 'unknow';
    930930
    931931      printf '%-22s %2s %-30s %-15s %18s',
    932          $where{switch_hostname},
    933          $where{switch_port_hr},
    934          $resol_arp{hostname_fq},
    935          $resol_arp{ipv4_address},
    936          $resol_arp{mac_address}."\n";
     932         $where{'switch_hostname'},
     933         $where{'switch_port_hr'},
     934         $resol_arp{'hostname_fq'},
     935         $resol_arp{'ipv4_address'},
     936         $resol_arp{'mac_address'}."\n";
    937937      }
    938938   return;
     
    971971   for my $clientname (@computer) {
    972972      my %resol_arp = resolve_ip_arp_host($clientname);      #resolution arp
    973       my $ip = $resol_arp{ipv4_address};
     973      my $ip = $resol_arp{'ipv4_address'};
    974974
    975975      next LOOP_ON_COMPUTER unless exists $computerdb->{$ip};
    976976
    977       my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{timestamp};
     977      my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{'timestamp'};
    978978      $year += 1900;
    979979      $mon++;
     
    981981
    982982      printf "%-22s %2s %-30s %-15s %-18s %s\n",
    983          $computerdb->{$ip}{switch_hostname},
    984          $computerdb->{$ip}{switch_port_hr},
    985          $computerdb->{$ip}{hostname_fq},
     983         $computerdb->{$ip}{'switch_hostname'},
     984         $computerdb->{$ip}{'switch_port_hr'},
     985         $computerdb->{$ip}{'hostname_fq'},
    986986         $ip,
    987          $computerdb->{$ip}{mac_address},
     987         $computerdb->{$ip}{'mac_address'},
    988988         $date;
    989989      }
     
    10011001      LOOP_ON_COMPUTER:
    10021002      for my $ip (keys %{$computerdb}) {
    1003          next LOOP_ON_COMPUTER if $mac ne $computerdb->{$ip}{mac_address};
    1004 
    1005          my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{timestamp};
     1003         next LOOP_ON_COMPUTER if $mac ne $computerdb->{$ip}{'mac_address'};
     1004
     1005         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{'timestamp'};
    10061006         $year += 1900;
    10071007         $mon++;
     
    10091009
    10101010         printf "%-22s %2s %-30s %-15s %-18s %s\n",
    1011             $computerdb->{$ip}{switch_hostname},
    1012             $computerdb->{$ip}{switch_port_hr},
    1013             $computerdb->{$ip}{hostname_fq},
     1011            $computerdb->{$ip}{'switch_hostname'},
     1012            $computerdb->{$ip}{'switch_port_hr'},
     1013            $computerdb->{$ip}{'hostname_fq'},
    10141014            $ip,
    1015             $computerdb->{$ip}{mac_address},
     1015            $computerdb->{$ip}{'mac_address'},
    10161016            $date;
    10171017         #next LOOP_ON_MAC;
     
    10571057   { # Remplis le champs portignore des ports d'inter-connection pour chaque switch
    10581058   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    1059    my %db_switch_output_port       = %{$switch_connection->{output_port}};
    1060    my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}};
     1059   my %db_switch_output_port       = %{$switch_connection->{'output_port'}};
     1060   my %db_switch_connected_on_port = %{$switch_connection->{'connected_on_port'}};
    10611061   my %db_switch_chained_port = ();
    10621062   for my $swport (keys %db_switch_connected_on_port) {
     
    10651065      }
    10661066   for my $sw (@SWITCH_LIST) {
    1067       push @{$sw->{portignore}}, $db_switch_output_port{$sw->{hostname}}  if exists $db_switch_output_port{$sw->{hostname}};
    1068       if ( exists $db_switch_chained_port{$sw->{hostname}} ) {
    1069          chop $db_switch_chained_port{$sw->{hostname}};
    1070          push @{$sw->{portignore}}, split m/ : /xms, $db_switch_chained_port{$sw->{hostname}};
    1071          }
    1072 #      print "$sw->{hostname} ++ @{$sw->{portignore}}\n";
     1067      push @{$sw->{portignore}}, $db_switch_output_port{$sw->{'hostname'}}  if exists $db_switch_output_port{$sw->{'hostname'}};
     1068      if ( exists $db_switch_chained_port{$sw->{'hostname'}} ) {
     1069         chop $db_switch_chained_port{$sw->{'hostname'}};
     1070         push @{$sw->{portignore}}, split m/ : /xms, $db_switch_chained_port{$sw->{'hostname'}};
     1071         }
     1072#      print "$sw->{'hostname'} ++ @{$sw->{portignore}}\n";
    10731073      }
    10741074   }
     
    10791079   for my $one_router ( get_list_main_router(@network) ) {
    10801080      my %resol_arp = resolve_ip_arp_host($one_router);
    1081       $router_mac_ip{ $resol_arp{mac_address} } = $resol_arp{ipv4_address};
     1081      $router_mac_ip{ $resol_arp{'mac_address'} } = $resol_arp{'ipv4_address'};
    10821082      }
    10831083
     
    11121112
    11131113         # do not search on router connection (why ?)
    1114          if ( exists $router_mac_ip{$resol_arp{mac_address}}) {
     1114         if ( exists $router_mac_ip{$resol_arp{'mac_address'}}) {
    11151115            $computer_not_detected{$one_computer} = $current_net;
    11161116            next LOOP_ON_COMPUTER;
     
    11181118
    11191119         # do not search on switch inter-connection
    1120          if (exists $SWITCH_LEVEL{$resol_arp{hostname_fq}}) {
     1120         if (exists $SWITCH_LEVEL{$resol_arp{'hostname_fq'}}) {
    11211121            $computer_not_detected{$one_computer} = $current_net;
    11221122            next LOOP_ON_COMPUTER;
     
    11241124
    11251125         my $switch_proposal = q{};
    1126          if (exists $computerdb->{$resol_arp{ipv4_address}} and exists $computerdb->{$resol_arp{ipv4_address}}{switch_hostname}) {
    1127             $switch_proposal = $computerdb->{$resol_arp{ipv4_address}}{switch_hostname};
     1126         if (exists $computerdb->{$resol_arp{'ipv4_address'}} and exists $computerdb->{$resol_arp{'ipv4_address'}}{'switch_hostname'}) {
     1127            $switch_proposal = $computerdb->{$resol_arp{'ipv4_address'}}{'switch_hostname'};
    11281128            }
    11291129
    11301130         # do not have a mac address
    1131          if ($resol_arp{mac_address} eq 'unknow' or (exists $resol_arp{timestamps} and $resol_arp{timestamps} < ($timestamp - 3 * 3600))) {
     1131         if ($resol_arp{'mac_address'} eq 'unknow' or (exists $resol_arp{'timestamps'} and $resol_arp{'timestamps'} < ($timestamp - 3 * 3600))) {
    11321132            $computer_not_detected{$one_computer} = $current_net;
    11331133            next LOOP_ON_COMPUTER;
    11341134            }
    11351135
    1136          my $vlan_name = get_current_vlan_name_for_interface($resol_arp{interface});
     1136         my $vlan_name = get_current_vlan_name_for_interface($resol_arp{'interface'});
    11371137         my $vlan_id   = get_current_vlan_id($vlan_name);
    1138          my %where = find_switch_port($resol_arp{mac_address},$switch_proposal,$vlan_id);
     1138         my %where = find_switch_port($resol_arp{'mac_address'}, $switch_proposal,$vlan_id);
    11391139
    11401140         #192.168.24.156:
     
    11461146
    11471147         # do not have a mac address
    1148 #         if ($resol_arp{mac_address} eq 'unknow') {
     1148#         if ($resol_arp{'mac_address'} eq 'unknow') {
    11491149#            $computer_not_detected{$one_computer} = $current_interface;
    11501150#            next LOOP_ON_COMPUTER;
     
    11521152
    11531153         # detected on a switch
    1154          if ($where{switch_description} ne 'unknow') {
     1154         if ($where{'switch_description'} ne 'unknow') {
    11551155            $detected_computer++;
    1156             $computerdb->{$resol_arp{ipv4_address}} = {
    1157                hostname_fq        => $resol_arp{hostname_fq},
    1158                mac_address        => $resol_arp{mac_address},
    1159                switch_hostname    => $where{switch_hostname},
    1160                switch_description => $where{switch_description},
    1161                switch_port        => $where{switch_port},
    1162                switch_port_hr     => $where{switch_port_hr},
     1156            $computerdb->{$resol_arp{'ipv4_address'}} = {
     1157               hostname_fq        => $resol_arp{'hostname_fq'},
     1158               mac_address        => $resol_arp{'mac_address'},
     1159               switch_hostname    => $where{'switch_hostname'},
     1160               switch_description => $where{'switch_description'},
     1161               switch_port        => $where{'switch_port'},
     1162               switch_port_hr     => $where{'switch_port_hr'},
    11631163               timestamp          => $timestamp,
    11641164               network            => $current_net,
     
    11681168
    11691169         # new in the database but where it is ?
    1170          if (not exists $computerdb->{$resol_arp{ipv4_address}}) {
     1170         if (not exists $computerdb->{$resol_arp{'ipv4_address'}}) {
    11711171            $detected_computer++;
    1172             $computerdb->{$resol_arp{ipv4_address}} = {
    1173                hostname_fq        => $resol_arp{hostname_fq},
    1174                mac_address        => $resol_arp{mac_address},
    1175                switch_hostname    => $where{switch_hostname},
    1176                switch_description => $where{switch_description},
    1177                switch_port        => $where{switch_port},
    1178                switch_port_hr     => $where{switch_port_hr},
    1179                timestamp          => $resol_arp{timestamp},
     1172            $computerdb->{$resol_arp{'ipv4_address'}} = {
     1173               hostname_fq        => $resol_arp{'hostname_fq'},
     1174               mac_address        => $resol_arp{'mac_address'},
     1175               switch_hostname    => $where{'switch_hostname'},
     1176               switch_description => $where{'switch_description'},
     1177               switch_port        => $where{'switch_port'},
     1178               switch_port_hr     => $where{'switch_port_hr'},
     1179               timestamp          => $resol_arp{'timestamp'},
    11801180               network            => $current_net,
    11811181               };
     
    11831183
    11841184         # mise a jour du nom de la machine si modification dans le dns
    1185          $computerdb->{$resol_arp{ipv4_address}}{hostname_fq} = $resol_arp{hostname_fq};
     1185         $computerdb->{$resol_arp{'ipv4_address'}}{'hostname_fq'} = $resol_arp{'hostname_fq'};
    11861186
    11871187         # mise à jour de la date de détection si détection plus récente par arpwatch
    1188          $computerdb->{$resol_arp{ipv4_address}}{timestamp}   = $resol_arp{timestamp} if exists $resol_arp{timestamp} and $computerdb->{$resol_arp{ipv4_address}}{timestamp} < $resol_arp{timestamp};
     1188         $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'}   = $resol_arp{'timestamp'} if exists $resol_arp{'timestamp'} and $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $resol_arp{'timestamp'};
    11891189
    11901190         # relance un arping sur la machine si celle-ci n'a pas été détectée depuis plus d'une semaine
    1191 #         push @computer_not_detected, $resol_arp{ipv4_address} if $computerdb->{$resol_arp{ipv4_address}}{timestamp} < $timestamp_last_week;
    1192          $computer_not_detected{$resol_arp{ipv4_address}} = $current_net if $computerdb->{$resol_arp{ipv4_address}}{timestamp} < $timestamp_last_week;
     1191#         push @computer_not_detected, $resol_arp{'ipv4_address'} if $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week;
     1192         $computer_not_detected{$resol_arp{'ipv4_address'}} = $current_net if $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week;
    11931193
    11941194         }
     
    12301230      my %resol_arp = resolve_ip_arp_host($one_computer);
    12311231
    1232       delete $computerdb->{$resol_arp{ipv4_address}} if exists $computerdb->{$resol_arp{ipv4_address}};
     1232      delete $computerdb->{$resol_arp{'ipv4_address'}} if exists $computerdb->{$resol_arp{'ipv4_address'}};
    12331233      }
    12341234
     
    12751275            not exists $computerdb->{$ip};
    12761276
    1277             #&& $computerdb->{$ip}{timestamp} > $timestamp_barrier;
    1278          my $ip_timestamp   = $computerdb->{$ip}{timestamp};
    1279          my $ip_mac         = $computerdb->{$ip}{mac_address};
    1280          my $ip_hostname_fq = $computerdb->{$ip}{hostname_fq};
     1277            #&& $computerdb->{$ip}{'timestamp'} > $timestamp_barrier;
     1278         my $ip_timestamp   = $computerdb->{$ip}{'timestamp'};
     1279         my $ip_mac         = $computerdb->{$ip}{'mac_address'};
     1280         my $ip_hostname_fq = $computerdb->{$ip}{'hostname_fq'};
    12811281
    12821282         $mactimedb{$ip_mac} ||= {
     
    12881288
    12891289         if (
    1290             ( $mactimedb{$ip_mac}->{timestamp} - $ip_timestamp > $timestamp_barrier
     1290            ( $mactimedb{$ip_mac}->{'timestamp'} - $ip_timestamp > $timestamp_barrier
    12911291               or (
    1292                   $mactimedb{$ip_mac}->{timestamp} > $ip_timestamp
    1293                   and $timestamp - $mactimedb{$ip_mac}->{timestamp} > $timestamp_3month
     1292                  $mactimedb{$ip_mac}->{'timestamp'} > $ip_timestamp
     1293                  and $timestamp - $mactimedb{$ip_mac}->{'timestamp'} > $timestamp_3month
    12941294                  )
    12951295            )
    12961296            and (
    1297                not $mactimedb{$ip_mac}->{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/
     1297               not $mactimedb{$ip_mac}->{'hostname_fq'} =~ m/$RE_FLOAT_HOSTNAME/
    12981298               or $ip_hostname_fq =~ m/$RE_FLOAT_HOSTNAME/
    12991299               )) {
     
    13041304
    13051305         elsif (
    1306             ( $ip_timestamp - $mactimedb{$ip_mac}->{timestamp} > $timestamp_barrier
     1306            ( $ip_timestamp - $mactimedb{$ip_mac}->{'timestamp'} > $timestamp_barrier
    13071307               or (
    1308                   $ip_timestamp > $mactimedb{$ip_mac}->{timestamp}
     1308                  $ip_timestamp > $mactimedb{$ip_mac}->{'timestamp'}
    13091309                  and $timestamp - $ip_timestamp > $timestamp_3month
    13101310                  )
     
    13121312            and (
    13131313               not $ip_hostname_fq =~ m/$RE_FLOAT_HOSTNAME/
    1314                or $mactimedb{$ip_mac}->{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/
     1314               or $mactimedb{$ip_mac}->{'hostname_fq'} =~ m/$RE_FLOAT_HOSTNAME/
    13151315               )) {
    13161316            print "remove ip ".$mactimedb{$ip_mac}->{ip}."\n" if $verbose;
     
    13191319            }
    13201320
    1321          if ( $ip_timestamp > $mactimedb{$ip_mac}->{timestamp}) {
     1321         if ( $ip_timestamp > $mactimedb{$ip_mac}->{'timestamp'}) {
    13221322            $mactimedb{$ip_mac} = {
    13231323               ip          => $ip,
     
    13331333      LOOP_ON_IP_ADDRESS:
    13341334      for my $ip (keys %{$computerdb}) {
    1335          next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} ne 'unknow';
     1335         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} ne 'unknow';
    13361336
    13371337         my $packed_ip = scalar gethostbyname($ip);
     
    13411341         next LOOP_ON_IP_ADDRESS if not defined $hostname_fq;
    13421342
    1343          $computerdb->{$ip}{hostname_fq} = $hostname_fq;
     1343         $computerdb->{$ip}{'hostname_fq'} = $hostname_fq;
    13441344         $database_has_changed++;
    13451345         }
     
    13891389
    13901390      # to be improve in the future
    1391       next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}); # switch on himself !
    1392 
    1393       my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{timestamp};
     1391      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself !
     1392
     1393      my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{'timestamp'};
    13941394      $year += 1900;
    13951395      $mon++;
     
    14001400
    14011401      my $arrow ='<-----------';
    1402          $arrow ='<===========' if $computerdb->{$ip}{switch_port_hr} =~ m/^(Trk|Br|Po)/;
     1402         $arrow ='<===========' if $computerdb->{$ip}{'switch_port_hr'} =~ m/^(Trk|Br|Po)/;
    14031403
    14041404      printf "%-28s %8s %12s %-40s %-15s %-18s %-16s %s\n",
    1405          $computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description},
    1406          $computerdb->{$ip}{switch_port_hr},
     1405         $computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'},
     1406         $computerdb->{$ip}{'switch_port_hr'},
    14071407         $arrow,
    1408          $computerdb->{$ip}{hostname_fq},
     1408         $computerdb->{$ip}{'hostname_fq'},
    14091409         $ip,
    1410          $computerdb->{$ip}{mac_address},
     1410         $computerdb->{$ip}{'mac_address'},
    14111411         $date,
    14121412         $vlan;
     
    14591459
    14601460      # to be improve in the future
    1461       next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}); # switch on himself !
    1462 
    1463       $mac_count{$computerdb->{$ip}{mac_address}}++;
     1461      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself !
     1462
     1463      $mac_count{$computerdb->{$ip}{'mac_address'}}++;
    14641464      }
    14651465
     
    14701470
    14711471      # to be improve in the future
    1472       next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}); # switch on himself !
    1473 
    1474       my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{timestamp};
     1472      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself !
     1473
     1474      my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{'timestamp'};
    14751475      $year += 1900;
    14761476      $mon++;
     
    14821482
    14831483      my $arrow ='&#8592;';
    1484          $arrow ='&#8656;' if $computerdb->{$ip}{switch_port_hr} =~ m/^(Trk|Br|Po)/;
    1485 
    1486       my $switch_hostname = $computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description} || 'unkown';
     1484         $arrow ='&#8656;' if $computerdb->{$ip}{'switch_port_hr'} =~ m/^(Trk|Br|Po)/;
     1485
     1486      my $switch_hostname = $computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'} || 'unkown';
    14871487      chomp $switch_hostname;
    1488       my $switch_hostname_sort = sprintf '%s %3s' ,$switch_hostname, $computerdb->{$ip}{switch_port_hr};
     1488      my $switch_hostname_sort = sprintf '%s %3s' ,$switch_hostname, $computerdb->{$ip}{'switch_port_hr'};
    14891489
    14901490      my $ip_sort = sprintf '%03i%03i%03i%03i', split m/ \. /xms, $ip;
    14911491
    1492       my $mac_sort = sprintf '%04i-%s', 9999 - $mac_count{$computerdb->{$ip}{mac_address}}, $computerdb->{$ip}{mac_address};
    1493 
    1494       $computerdb->{$ip}{hostname_fq} = 'unknow' if $computerdb->{$ip}{hostname_fq} =~ m/^ \d+ \. \d+ \. \d+ \. \d+ $/xms;
    1495       my ( $host_short ) = split m/ \. /xms, $computerdb->{$ip}{hostname_fq};
     1492      my $mac_sort = sprintf '%04i-%s', 9999 - $mac_count{$computerdb->{$ip}{'mac_address'}}, $computerdb->{$ip}{'mac_address'};
     1493
     1494      $computerdb->{$ip}{'hostname_fq'} = 'unknow' if $computerdb->{$ip}{'hostname_fq'} =~ m/^ \d+ \. \d+ \. \d+ \. \d+ $/xms;
     1495      my ( $host_short ) = split m/ \. /xms, $computerdb->{$ip}{'hostname_fq'};
    14961496
    14971497      my $vlan = '';
    14981498      $vlan = $computerdb->{$ip}{network}.' ('.get_current_vlan_id($computerdb->{$ip}{network}).')' if $computerdb->{$ip}{network};
    14991499
    1500       my $parent_port_hr = format_aggregator4html($computerdb->{$ip}{switch_port_hr});
     1500      my $parent_port_hr = format_aggregator4html($computerdb->{$ip}{'switch_port_hr'});
    15011501
    15021502      print <<"END_HTML";
     
    15051505   <td class="bklask-port">$parent_port_hr</td>
    15061506   <td colspan="2">$arrow</td>
    1507    <td sorttable_customkey="$host_short">$computerdb->{$ip}{hostname_fq}</td>
     1507   <td sorttable_customkey="$host_short">$computerdb->{$ip}{'hostname_fq'}</td>
    15081508   <td sorttable_customkey="$ip_sort">$ip</td>
    1509    <td sorttable_customkey="$mac_sort">$computerdb->{$ip}{mac_address}</td>
     1509   <td sorttable_customkey="$mac_sort">$computerdb->{$ip}{'mac_address'}</td>
    15101510   <td>$vlan</td>
    15111511   <td>$date</td>
     
    15161516   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    15171517
    1518    my %db_switch_output_port       = %{$switch_connection->{output_port}};
    1519    my %db_switch_parent            = %{$switch_connection->{parent}};
    1520    my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}};
    1521    my %db_switch                   = %{$switch_connection->{switch_db}};
     1518   my %db_switch_output_port       = %{$switch_connection->{'output_port'}};
     1519   my %db_switch_parent            = %{$switch_connection->{'parent'}};
     1520   my %db_switch_connected_on_port = %{$switch_connection->{'connected_on_port'}};
     1521   my %db_switch                   = %{$switch_connection->{'switch_db'}};
    15221522
    15231523   for my $sw (sort keys %db_switch_output_port) {
     
    15311531
    15321532      if (exists $db_switch_parent{$sw}) {
    1533          my $mac_address = $db_switch{$db_switch_parent{$sw}->{'switch'}}->{mac_address};
    1534          my $ipv4_address = $db_switch{$db_switch_parent{$sw}->{'switch'}}->{ipv4_address};
    1535          my $timestamp = $db_switch{$db_switch_parent{$sw}->{'switch'}}->{timestamp};
     1533         my $mac_address  = $db_switch{$db_switch_parent{$sw}->{'switch'}}->{'mac_address'};
     1534         my $ipv4_address = $db_switch{$db_switch_parent{$sw}->{'switch'}}->{'ipv4_address'};
     1535         my $timestamp    = $db_switch{$db_switch_parent{$sw}->{'switch'}}->{'timestamp'};
    15361536
    15371537         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $timestamp;
     
    15441544         my $mac_sort = sprintf '%04i-%s', 9999, $mac_address;
    15451545
    1546          my ( $host_short ) = sprintf '%s %3s' , split(m/ \. /xms, $db_switch_parent{$sw}->{'switch'}, 1), $db_switch_parent{$sw}->{port_hr};
     1546         my ( $host_short ) = sprintf '%s %3s' , split(m/ \. /xms, $db_switch_parent{$sw}->{'switch'}, 1), $db_switch_parent{$sw}->{'port_hr'};
    15471547
    15481548         my $parent_port_hr = format_aggregator4html($db_switch_output_port{$sw});
    1549          my $child_port_hr  = format_aggregator4html($db_switch_parent{$sw}->{port_hr});
     1549         my $child_port_hr  = format_aggregator4html($db_switch_parent{$sw}->{'port_hr'});
    15501550
    15511551         print <<"END_HTML";
     
    15861586         my $switch_hostname_sort = sprintf '%s %3s' ,$sw_connect, $port_connect;
    15871587
    1588          my $mac_address = $db_switch{$sw}->{mac_address};
    1589          my $ipv4_address = $db_switch{$sw}->{ipv4_address};
    1590          my $timestamp = $db_switch{$sw}->{timestamp};
     1588         my $mac_address = $db_switch{$sw}->{'mac_address'};
     1589         my $ipv4_address = $db_switch{$sw}->{'ipv4_address'};
     1590         my $timestamp = $db_switch{$sw}->{'timestamp'};
    15911591
    15921592         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $timestamp;
     
    16701670   for my $ip (keys %{$computerdb}) {
    16711671      # to be improve in the future
    1672       next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}); # switch on himself !
    1673       next LOOP_ON_IP_ADDRESS if ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}) eq 'unknow';
    1674       next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{switch_port} eq '0';
    1675 
    1676       my $ip_timestamp   = $computerdb->{$ip}{timestamp};
    1677       my $ip_mac         = $computerdb->{$ip}{mac_address};
    1678       my $ip_hostname_fq = $computerdb->{$ip}{hostname_fq};
     1672      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself !
     1673      next LOOP_ON_IP_ADDRESS if ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}) eq 'unknow';
     1674      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'switch_port'} eq '0';
     1675
     1676      my $ip_timestamp   = $computerdb->{$ip}{'timestamp'};
     1677      my $ip_mac         = $computerdb->{$ip}{'mac_address'};
     1678      my $ip_hostname_fq = $computerdb->{$ip}{'hostname_fq'};
    16791679
    16801680      my $swpt = sprintf "%-28s  %2s",
    1681          $computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description},
    1682          $computerdb->{$ip}{switch_port_hr};
     1681         $computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'},
     1682         $computerdb->{$ip}{'switch_port_hr'};
    16831683      $switchportdb{$swpt} ||= {
    16841684         ip          => $ip,
     
    16911691      # if float computer, set date 15 day before warning...
    16921692      my $ip_timestamp_mod = $ip_timestamp;
    1693       my $ip_timestamp_ref = $switchportdb{$swpt}->{timestamp};
     1693      my $ip_timestamp_ref = $switchportdb{$swpt}->{'timestamp'};
    16941694      $ip_timestamp_mod -= $days_before_alert * 24 * 3600 if $ip_hostname_fq =~ m/$RE_FLOAT_HOSTNAME/;
    1695       $ip_timestamp_ref -= $days_before_alert * 24 * 3600 if $switchportdb{$swpt}->{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/;
     1695      $ip_timestamp_ref -= $days_before_alert * 24 * 3600 if $switchportdb{$swpt}->{'hostname_fq'} =~ m/$RE_FLOAT_HOSTNAME/;
    16961696
    16971697      if ($ip_timestamp_mod > $ip_timestamp_ref) {
     
    17091709   for my $swpt (keys %switchportdb) {
    17101710      next LOOP_ON_RECENT_COMPUTER if $swpt =~ m/^\s*0$/;
    1711       next LOOP_ON_RECENT_COMPUTER if $switchportdb{$swpt}->{hostname_fq} !~ m/$RE_FLOAT_HOSTNAME/;
     1711      next LOOP_ON_RECENT_COMPUTER if $switchportdb{$swpt}->{'hostname_fq'} !~ m/$RE_FLOAT_HOSTNAME/;
    17121712
    17131713      my $src_ip = $switchportdb{$swpt}->{ip};
     
    17151715      LOOP_ON_IP_ADDRESS:
    17161716      for my $ip (keys %{$computerdb}) {
    1717          next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{mac_address} ne  $switchportdb{$swpt}->{mac_address};
    1718          next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/;
    1719          next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{timestamp} < $src_timestamp;
     1717         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'mac_address'} ne  $switchportdb{$swpt}->{'mac_address'};
     1718         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} =~ m/$RE_FLOAT_HOSTNAME/;
     1719         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'timestamp'} < $src_timestamp;
    17201720
    17211721         $src_ip = $ip;
    1722          $src_timestamp = $computerdb->{$ip}{timestamp};
     1722         $src_timestamp = $computerdb->{$ip}{'timestamp'};
    17231723         }
    17241724
    17251725      # keep only if float computer is the most recent
    17261726      next LOOP_ON_RECENT_COMPUTER if $src_timestamp == 0;
    1727       next LOOP_ON_RECENT_COMPUTER if $switchportdb{$swpt}->{timestamp} < $src_timestamp;
    1728 
    1729       my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $switchportdb{$swpt}->{timestamp};
     1727      next LOOP_ON_RECENT_COMPUTER if $switchportdb{$swpt}->{'timestamp'} < $src_timestamp;
     1728
     1729      my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $switchportdb{$swpt}->{'timestamp'};
    17301730      $year += 1900;
    17311731      $mon++;
    17321732      my $date = sprintf '%04i-%02i-%02i/%02i:%02i', $year, $mon, $mday, $hour, $min;
    17331733
    1734       ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$src_ip}{timestamp};
     1734      ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$src_ip}{'timestamp'};
    17351735      $year += 1900;
    17361736      $mon++;
     
    17401740
    17411741      printf "%s / %-10s +-> %-10s(%i)  %s %s %s %s\n",
    1742          $swpt, $switchportdb{$swpt}->{vlan}, $computerdb->{$src_ip}{network}, $vlan_id,
     1742         $swpt, $switchportdb{$swpt}->{'vlan'}, $computerdb->{$src_ip}{network}, $vlan_id,
    17431743         $date,
    17441744         $src_date,
    1745          $computerdb->{$src_ip}{mac_address},
    1746          $computerdb->{$src_ip}{hostname_fq};
     1745         $computerdb->{$src_ip}{'mac_address'},
     1746         $computerdb->{$src_ip}{'hostname_fq'};
    17471747      }
    17481748   }
     
    18801880      }
    18811881
    1882    $switch_name = join(',', map {$_->{hostname}} @SWITCH_LIST ) if $switch_name eq q{*};
     1882   $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST ) if $switch_name eq q{*};
    18831883
    18841884   for my $sw_name (split /,/, $switch_name) {
     
    20102010      }
    20112011
    2012    $switch_name = join(',', map {$_->{hostname}} @SWITCH_LIST ) if $switch_name eq q{*};
     2012   $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST ) if $switch_name eq q{*};
    20132013
    20142014   for my $sw_name (split /,/, $switch_name) {
     
    20172017         }
    20182018
    2019       my $search_vlan_name = $OID_NUMBER{vlanName} . ".$vlan_id";
     2019      my $search_vlan_name = $OID_NUMBER{'vlanName'} . ".$vlan_id";
    20202020
    20212021      my $sw = $SWITCH_DB{$sw_name};
     
    20482048      }
    20492049
    2050    $switch_name = join(',', map {$_->{hostname}} @SWITCH_LIST ) if $switch_name eq q{*};
     2050   $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST ) if $switch_name eq q{*};
    20512051
    20522052   for my $sw_name (split /,/, $switch_name) {
     
    20772077   for my $ip (Net::Netmask::sort_by_ip_address(keys %{$computerdb})) {
    20782078
    2079       next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}); # switch on himself !
    2080 
    2081       my $sw_hostname = $computerdb->{$ip}{switch_hostname} || q{};
     2079      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself !
     2080
     2081      my $sw_hostname = $computerdb->{$ip}{'switch_hostname'} || q{};
    20822082      next LOOP_ON_IP_ADDRESS if $sw_hostname eq 'unknow';
    20832083
     
    20852085      LOOP_ON_ALL_SWITCH:
    20862086      for my $sw (@SWITCH_LIST) {
    2087          next LOOP_ON_ALL_SWITCH if $sw_hostname ne $sw->{hostname};
    2088          $sw_location = $sw->{location};
     2087         next LOOP_ON_ALL_SWITCH if $sw_hostname ne $sw->{'hostname'};
     2088         $sw_location = $sw->{'location'};
    20892089         last;
    20902090         }
     
    21362136
    21372137         if (exists $computerdb->{$ip}) {
    2138             next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{timestamp} > $timestamp_barrier;
    2139 
    2140             my $mac_address = $computerdb->{$ip}{mac_address};
     2138            next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'timestamp'} > $timestamp_barrier;
     2139
     2140            my $mac_address = $computerdb->{$ip}{'mac_address'};
    21412141            LOOP_ON_DATABASE:
    21422142            for my $ip_db (keys %{$computerdb}) {
    2143                next LOOP_ON_DATABASE if $computerdb->{$ip_db}{mac_address} ne $mac_address;
    2144                next LOOP_ON_IP_ADDRESS if $computerdb->{$ip_db}{timestamp} > $timestamp_barrier;
     2143               next LOOP_ON_DATABASE if $computerdb->{$ip_db}{'mac_address'} ne $mac_address;
     2144               next LOOP_ON_IP_ADDRESS if $computerdb->{$ip_db}{'timestamp'} > $timestamp_barrier;
    21452145               }
    21462146            }
     
    21482148         my $ip_date_last_detection = '';
    21492149         if (exists $computerdb->{$ip}) {
    2150             my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{timestamp};
     2150            my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{'timestamp'};
    21512151            $year += 1900;
    21522152            $mon++;
     
    21612161
    21622162         $result_ip{$ip} ||= {};
    2163          $result_ip{$ip}->{date_last_detection} = $ip_date_last_detection;
    2164          $result_ip{$ip}->{hostname_fq} = $hostname_fq;
    2165          $result_ip{$ip}->{vlan} = $vlan;
     2163         $result_ip{$ip}->{'date_last_detection'} = $ip_date_last_detection;
     2164         $result_ip{$ip}->{'hostname_fq'} = $hostname_fq;
     2165         $result_ip{$ip}->{'vlan'} = $vlan;
    21662166
    21672167         printf "VERBOSE_1: %-15s %-12s %s\n", $ip, $vlan, $hostname_fq if $verbose;
     
    21802180   LOOP_ON_IP_ADDRESS:
    21812181   for my $ip (Net::Netmask::sort_by_ip_address(keys %result_ip)) {
    2182          my $vlan_nameid = $result_ip{$ip}->{vlan}.'('.get_current_vlan_id($result_ip{$ip}->{vlan}).')';
    2183          printf "%-15s %-40s %-16s %s\n", $ip, $result_ip{$ip}->{hostname_fq}, $result_ip{$ip}->{date_last_detection}, $vlan_nameid;
     2182         my $vlan_nameid = $result_ip{$ip}->{'vlan'}.'('.get_current_vlan_id($result_ip{$ip}->{'vlan'}).')';
     2183         printf "%-15s %-40s %-16s %s\n", $ip, $result_ip{$ip}->{'hostname_fq'}, $result_ip{$ip}->{'date_last_detection'}, $vlan_nameid;
    21842184      }
    21852185   }
     
    22192219
    22202220      my $ip_sort = sprintf '%03i%03i%03i%03i', split m/ \. /xms, $ip;
    2221       my ( $host_short ) = split m/ \. /xms, $result_ip{$ip}->{hostname_fq};
    2222 
    2223       my $vlan_nameid = $result_ip{$ip}->{vlan}.'('.get_current_vlan_id($result_ip{$ip}->{vlan}).')';
     2221      my ( $host_short ) = split m/ \. /xms, $result_ip{$ip}->{'hostname_fq'};
     2222
     2223      my $vlan_nameid = $result_ip{$ip}->{'vlan'}.'('.get_current_vlan_id($result_ip{$ip}->{'vlan'}).')';
    22242224
    22252225      print <<"END_HTML";
    22262226  <tr class="$typerow">
    22272227   <td sorttable_customkey="$ip_sort">$ip</td>
    2228    <td sorttable_customkey="$host_short">$result_ip{$ip}->{hostname_fq}</td>
     2228   <td sorttable_customkey="$host_short">$result_ip{$ip}->{'hostname_fq'}</td>
    22292229   <td>$vlan_nameid</td>
    2230    <td>$result_ip{$ip}->{date_last_detection}</td>
     2230   <td>$result_ip{$ip}->{'date_last_detection'}</td>
    22312231  </tr>
    22322232END_HTML
     
    23922392
    23932393   $mac_address = normalize_mac_address($mac_address);
    2394    $switch_name = join(',', map {$_->{hostname}} @SWITCH_LIST ) if $switch_name eq q{*} or $switch_name eq q{all};
     2394   $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST ) if $switch_name eq q{*} or $switch_name eq q{all};
    23952395
    23962396   for my $sw_name (split /,/, $switch_name) {
     
    24542454      my %resol_arp = resolve_ip_arp_host($one_router, q{*}, q{low}); # resolution arp
    24552455
    2456       next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow';
    2457       print "VERBOSE_1: Router detected $resol_arp{ipv4_address} - $resol_arp{mac_address}\n" if $verbose;
    2458 
    2459       my $vlan_name = get_current_vlan_name_for_interface($resol_arp{interface});
     2456      next DETECT_ALL_ROUTER if $resol_arp{'mac_address'} eq 'unknow';
     2457      print "VERBOSE_1: Router detected $resol_arp{'ipv4_address'} - $resol_arp{'mac_address'}\n" if $verbose;
     2458
     2459      my $vlan_name = get_current_vlan_name_for_interface($resol_arp{'interface'});
    24602460      my $vlan_id   = get_current_vlan_id($vlan_name);
    2461       $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address},$vlan_id); # retrouve les emplacements des routeurs
     2461      $where{$resol_arp{'ipv4_address'}} = find_all_switch_port($resol_arp{'mac_address'},$vlan_id); # retrouve les emplacements des routeurs
    24622462      }
    24632463
     
    24742474         next ALL_SWITCH_CONNECTED if $switch->{port} eq '0';
    24752475
    2476          $db_switch_output_port{$switch->{hostname}} = $switch->{port_hr};
    2477          print "VERBOSE_2: output port $switch->{hostname} : $switch->{port_hr}\n" if $verbose;
     2476         $db_switch_output_port{$switch->{'hostname'}} = $switch->{'port_hr'};
     2477         print "VERBOSE_2: output port $switch->{'hostname'} : $switch->{'port_hr'}\n" if $verbose;
    24782478         }
    24792479      }
     
    24842484   my @list_switch_ipv4 = ();
    24852485   for my $sw (@SWITCH_LIST) {
    2486       push @list_all_switch, $sw->{hostname};
     2486      push @list_all_switch, $sw->{'hostname'};
    24872487      }
    24882488
     
    24952495         my $fake_ip = $SWITCH_DB{$one_switch}{'fake-ip'};
    24962496         fast_ping($fake_ip);
    2497          print "WARNING: fake ip on switch $one_switch -> $fake_ip / $resol_arp{ipv4_address}\n" if $verbose;
     2497         print "WARNING: fake ip on switch $one_switch -> $fake_ip / $resol_arp{'ipv4_address'}\n" if $verbose;
    24982498         my %resol_arp_alt = resolve_ip_arp_host($fake_ip, q{*}, q{low}); # arp resolution
    2499          if ($resol_arp_alt{mac_address} ne 'unknow') {
    2500             $resol_arp{mac_address}   = $resol_arp_alt{mac_address};
    2501             $resol_arp{interface}     = $resol_arp_alt{interface};
    2502             $resol_arp{ipv4_address} .= '*';
     2499         if ($resol_arp_alt{'mac_address'} ne 'unknow') {
     2500            $resol_arp{'mac_address'}   = $resol_arp_alt{'mac_address'};
     2501            $resol_arp{'interface'}     = $resol_arp_alt{'interface'};
     2502            $resol_arp{'ipv4_address'} .= '*';
    25032503            # Force a MAC trace on switch
    2504             system "arping -c 1 -w 1 -rR -i $resol_arp_alt{interface} $fake_ip > /dev/null 2>&1";
     2504            system "arping -c 1 -w 1 -rR -i $resol_arp_alt{'interface'} $fake_ip > /dev/null 2>&1";
    25052505            }
    25062506         }
    25072507      print "Info: switch loop $one_switch\n" if $verbose;
    2508       next ALL_SWITCH if $resol_arp{mac_address} eq 'unknow';
    2509 
    2510       push @list_switch_ipv4, $resol_arp{ipv4_address};
    2511 
    2512       my $vlan_name = get_current_vlan_name_for_interface($resol_arp{interface});
     2508      next ALL_SWITCH if $resol_arp{'mac_address'} eq 'unknow';
     2509
     2510      push @list_switch_ipv4, $resol_arp{'ipv4_address'};
     2511
     2512      my $vlan_name = get_current_vlan_name_for_interface($resol_arp{'interface'});
    25132513      my $vlan_id   = get_current_vlan_id($vlan_name);
    2514       $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address},$vlan_id); # find port on all switch
     2514      $where{$resol_arp{'ipv4_address'}} = find_all_switch_port($resol_arp{'mac_address'},$vlan_id); # find port on all switch
    25152515
    25162516      if ($verbose) {
    2517          print "VERBOSE_3: $one_switch $resol_arp{ipv4_address} $resol_arp{mac_address}\n";
     2517         print "VERBOSE_3: $one_switch $resol_arp{'ipv4_address'} $resol_arp{'mac_address'}\n";
    25182518         print "VERBOSE_3: $one_switch --- ",
    2519             join(' + ', keys %{$where{$resol_arp{ipv4_address}}}),
     2519            join(' + ', keys %{$where{$resol_arp{'ipv4_address'}}}),
    25202520            "\n";
    25212521         }
    25222522
    2523       $db_switch_ip_hostnamefq{$resol_arp{ipv4_address}} = $resol_arp{hostname_fq};
    2524       print "VERBOSE_4: db_switch_ip_hostnamefq $resol_arp{ipv4_address} -> $resol_arp{hostname_fq}\n" if $verbose;
    2525 
    2526       $SWITCH_DB{$one_switch}->{ipv4_address} = $resol_arp{ipv4_address};
    2527       $SWITCH_DB{$one_switch}->{mac_address}  = $resol_arp{mac_address};
    2528       $SWITCH_DB{$one_switch}->{timestamp}    = $timestamp;
     2523      $db_switch_ip_hostnamefq{$resol_arp{'ipv4_address'}} = $resol_arp{'hostname_fq'};
     2524      print "VERBOSE_4: db_switch_ip_hostnamefq $resol_arp{'ipv4_address'} -> $resol_arp{'hostname_fq'}\n" if $verbose;
     2525
     2526      $SWITCH_DB{$one_switch}->{'ipv4_address'} = $resol_arp{'ipv4_address'};
     2527      $SWITCH_DB{$one_switch}->{'mac_address'}  = $resol_arp{'mac_address'};
     2528      $SWITCH_DB{$one_switch}->{'timestamp'}    = $timestamp;
    25292529      }
    25302530
     
    25422542
    25432543         my $switch = $where{$ip}->{$switch_detected};
    2544          print "VERBOSE_6: $db_switch_ip_hostnamefq{$ip} -> $switch->{hostname} : $switch->{port_hr}\n" if $verbose;
     2544         print "VERBOSE_6: $db_switch_ip_hostnamefq{$ip} -> $switch->{'hostname'} : $switch->{'port_hr'}\n" if $verbose;
    25452545
    25462546         next if $switch->{port}     eq '0';
    2547          next if $switch->{port_hr}  eq $db_switch_output_port{$switch->{hostname}};
    2548          next if $switch->{hostname} eq $db_switch_ip_hostnamefq{$ip}; # $computerdb->{$ip}{hostname};
     2547         next if $switch->{'port_hr'}  eq $db_switch_output_port{$switch->{'hostname'}};
     2548         next if $switch->{'hostname'} eq $db_switch_ip_hostnamefq{$ip}; # $computerdb->{$ip}{'hostname'};
    25492549
    25502550         $db_switch_link_with{ $db_switch_ip_hostnamefq{$ip} } ||= {};
    2551          $db_switch_link_with{ $db_switch_ip_hostnamefq{$ip} }->{ $switch->{hostname} } = $switch->{port_hr};
     2551         $db_switch_link_with{ $db_switch_ip_hostnamefq{$ip} }->{ $switch->{'hostname'} } = $switch->{'port_hr'};
    25522552         print "VERBOSE_7: +++++\n" if $verbose;
    25532553         }
     
    26222622   for my $sw (sort keys %db_switch_output_port) {
    26232623      if (exists $db_switch_parent{$sw}) {
    2624          printf "%-28s  %2s  +-->  %2s  %-25s\n", $sw, $db_switch_output_port{$sw}, $db_switch_parent{$sw}->{port_hr}, $db_switch_parent{$sw}->{'switch'};
     2624         printf "%-28s  %2s  +-->  %2s  %-25s\n", $sw, $db_switch_output_port{$sw}, $db_switch_parent{$sw}->{'port_hr'}, $db_switch_parent{$sw}->{'switch'};
    26252625         }
    26262626      else {
     
    26852685   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    26862686
    2687    my %db_switch_output_port       = %{$switch_connection->{output_port}};
    2688    my %db_switch_parent            = %{$switch_connection->{parent}};
    2689    my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}};
     2687   my %db_switch_output_port       = %{$switch_connection->{'output_port'}};
     2688   my %db_switch_parent            = %{$switch_connection->{'parent'}};
     2689   my %db_switch_connected_on_port = %{$switch_connection->{'connected_on_port'}};
    26902690
    26912691   print "Switch output port and parent port connection\n";
     
    26952695         $arrow ='==>' if $db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/;
    26962696      if (exists $db_switch_parent{$sw}) {
    2697          printf "%-28s %8s %3s %-8s %-25s\n", $sw, $db_switch_output_port{$sw}, $arrow, $db_switch_parent{$sw}->{port_hr}, $db_switch_parent{$sw}->{'switch'};
     2697         printf "%-28s %8s %3s %-8s %-25s\n", $sw, $db_switch_output_port{$sw}, $arrow, $db_switch_parent{$sw}->{'port_hr'}, $db_switch_parent{$sw}->{'switch'};
    26982698         }
    26992699      else {
     
    27262726   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    27272727
    2728    my %db_switch_output_port       = %{$switch_connection->{output_port}};
    2729    my %db_switch_parent            = %{$switch_connection->{parent}};
    2730    my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}};
    2731    my %db_switch_link_with         = %{$switch_connection->{link_with}};
    2732    my %db_switch_global            = %{$switch_connection->{switch_db}};
    2733    my $timestamp                   = $switch_connection->{'timestamp'};
     2728   my %db_switch_output_port       = %{$switch_connection->{'output_port'}};
     2729   my %db_switch_parent            = %{$switch_connection->{'parent'}};
     2730   my %db_switch_connected_on_port = %{$switch_connection->{'connected_on_port'}};
     2731   my %db_switch_link_with         = %{$switch_connection->{'link_with'}};
     2732   my %db_switch_global            = %{$switch_connection->{'switch_db'}};
     2733   my $timestamp                   =   $switch_connection->{'timestamp'};
    27342734
    27352735   my %db_building= ();
    27362736   for my $sw (@SWITCH_LIST) {
    2737       my ($building, $location) = split m/ \/ /xms, $sw->{location}, 2;
     2737      my ($building, $location) = split m/ \/ /xms, $sw->{'location'}, 2;
    27382738      $db_building{$building} ||= {};
    27392739      $db_building{$building}->{$location} ||= {};
    2740       $db_building{$building}->{$location}{ $sw->{hostname} } = 'y';
     2740      $db_building{$building}->{$location}{ $sw->{'hostname'} } = 'y';
    27412741      }
    27422742
Note: See TracChangeset for help on using the changeset viewer.