Changeset 370
- Timestamp:
- Dec 9, 2017, 4:19:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r369 r370 53 53 54 54 # SNMP parameter initialisation 55 my %session = ( -hostname => $sw->{'hostname'});55 my %session = (-hostname => $sw->{'hostname'}); 56 56 $session{-version} = $sw->{'version'} || 1; 57 $session{-port} = $sw->{'snmpport'} || $DEFAULT{'snmpport'} 57 $session{-port} = $sw->{'snmpport'} || $DEFAULT{'snmpport'} || 161; 58 58 if (exists $sw->{'version'} and $sw->{'version'} eq '3') { 59 59 $session{-username} = $sw->{'username'} || 'snmpadmin'; … … 323 323 # LANG=C ip neigh show to 194.254.66.62 324 324 # 194.254.66.62 dev eth331 lladdr 00:08:7c:bb:0f:c0 REACHABLE 325 # my $cmd_arp = shell_command "arp -a $param_ip_or_host -i $ret{'interface'}";326 # if ( $cmd_arp =~ m{ (\S*) \s \( ( $RE_IPv4_ADDRESS ) \) \s at \s ( $RE_MAC_ADDRESS ) }xms ) {327 # ( $ret{'hostname_fq'}, $ret{'ipv4_address'}, $ret{'mac_address'} ) = ($1, $2, $3);328 # }325 # my $cmd_arp = shell_command "arp -a $param_ip_or_host -i $ret{'interface'}"; 326 # if ( $cmd_arp =~ m{ (\S*) \s \( ( $RE_IPv4_ADDRESS ) \) \s at \s ( $RE_MAC_ADDRESS ) }xms ) { 327 # ( $ret{'hostname_fq'}, $ret{'ipv4_address'}, $ret{'mac_address'} ) = ($1, $2, $3); 328 # } 329 329 if ($ret{'mac_address'} eq 'unknow') { 330 330 # Last chance to have the mac_address … … 420 420 421 421 $sw->{'description'} = $result->{$OID_NUMBER{'sysName'}} || $sw->{'hostname'}; 422 $sw->{'model'} = get_switch_model($result->{$OID_NUMBER{'sysDescription'}});423 $sw->{'revision'} = get_switch_revision($result->{$OID_NUMBER{'sysDescription'}});422 $sw->{'model'} = get_switch_model($result->{$OID_NUMBER{'sysDescription'}}); 423 $sw->{'revision'} = get_switch_revision($result->{$OID_NUMBER{'sysDescription'}}); 424 424 printf "%-26s 0--------->>>> %-25s %s\n", $sw->{'hostname'}, $sw->{'description'}, $sw->{'model'}.'('.$sw->{'revision'}.')' if $verbose; 425 425 … … 459 459 ); 460 460 my @chars = split m//xms, $car; 461 return $table{$chars[-2]} *16 + $table{$chars[-1]};461 return $table{$chars[-2]} * 16 + $table{$chars[-1]}; 462 462 } 463 463 … … 475 475 } 476 476 477 return join q{:}, map { substr( uc("00$_"), -2)} split m/ [:-] /xms, $mac_address;477 return join q{:}, map {substr(uc("00$_"), -2)} split m/ [:-] /xms, $mac_address; 478 478 } 479 479 … … 540 540 sub fqdn_html_breakable { 541 541 my $ref_fqdn = \($_[0]); 542 542 543 543 # Add HTML <wbr> before every . to permit line break 544 544 $$ref_fqdn =~ s{\.}{.<wbr />}g; … … 550 550 my $mac_address = shift; 551 551 my $switch_proposal = shift || q{}; 552 my $vlan_id = shift || 0;552 my $vlan_id = shift || 0; 553 553 554 554 my %ret; 555 555 $ret{'switch_description'} = 'unknow'; 556 $ret{'switch_port_id'} = '0';557 558 return %ret if $mac_address eq 'unknow'; ;556 $ret{'switch_port_id'} = '0'; 557 558 return %ret if $mac_address eq 'unknow'; 559 559 560 560 my @switch_search = @SWITCH_LIST; … … 568 568 569 569 my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address); 570 my $oid_search_port2 = $OID_NUMBER{'searchPort2'} . '.'. $vlan_id . mac_address_hex2dec($mac_address);570 my $oid_search_port2 = $OID_NUMBER{'searchPort2'} . '.' . $vlan_id . mac_address_hex2dec($mac_address); 571 571 572 572 LOOP_ON_SWITCH: 573 573 for my $sw (@switch_search) { 574 my ($session, $error) = Net::SNMP->session( %{$sw->{'snmp_param_session'}});574 my ($session, $error) = Net::SNMP->session(%{$sw->{'snmp_param_session'}}); 575 575 print "$error \n" if $error; 576 576 … … 585 585 } 586 586 587 if (not 587 if (not(defined $result and $result->{$oid_search_port1} ne 'noSuchInstance')) { 588 588 $session->close; 589 589 next LOOP_ON_SWITCH; … … 629 629 630 630 my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address); 631 my $oid_search_port2 = $OID_NUMBER{'searchPort2'} . '.'. $vlan_id . mac_address_hex2dec($mac_address);631 my $oid_search_port2 = $OID_NUMBER{'searchPort2'} . '.' . $vlan_id . mac_address_hex2dec($mac_address); 632 632 LOOP_ON_ALL_SWITCH: 633 633 for my $sw (@SWITCH_LIST) { … … 653 653 if ($swport_hr eq $portignore) { 654 654 $session->close; 655 next LOOP_ON_ALL_SWITCH 655 next LOOP_ON_ALL_SWITCH; 656 656 } 657 657 } … … 715 715 716 716 for my $net (@vlan_name) { 717 my @line 717 my @line = @{$KLASK_CFG->{'network'}{$net}{'ip-subnet'}}; 718 718 for my $cmd (@line) { 719 719 for my $method (keys %{$cmd}) { … … 729 729 for my $ip (@{$net}) { 730 730 $ip =~ s{ /32 }{}xms; 731 push @res, 731 push @res, $ip; 732 732 } 733 733 } … … 752 752 #--------------------------------------------------------------- 753 753 sub normalize_port_human_readable { 754 my $sw_port_hr 754 my $sw_port_hr = shift; 755 755 756 756 # Manufacturer abbreviation … … 786 786 # First get the index, second get the name (port_hr) 787 787 788 my $oid_search_ix = $OID_NUMBER{'ifIndex'} . '.'. $swport_id;788 my $oid_search_ix = $OID_NUMBER{'ifIndex'} . '.' . $swport_id; 789 789 my $result_ix = $snmp_session->get_request( 790 790 -varbindlist => [$oid_search_ix] … … 811 811 if ($swport_hr =~ m/^(Trk|Br|Po)/) { 812 812 my $oid_search_index = $OID_NUMBER{'ifAggregator'}; # base OID 813 my @args = ( -varbindlist =>[$oid_search_index]);813 my @args = (-varbindlist => [$oid_search_index]); 814 814 LOOP_ON_OID_PORT: 815 while ( defined $snmp_session->get_next_request(@args)) {815 while (defined $snmp_session->get_next_request(@args)) { 816 816 my ($oid_current) = $snmp_session->var_bind_names; 817 last LOOP_ON_OID_PORT if 817 last LOOP_ON_OID_PORT if not Net::SNMP::oid_base_match($oid_search_index, $oid_current); 818 818 819 819 # IEEE8023-LAG-MIB::dot3adAggPortSelectedAggID.28 = INTEGER: 337 … … 849 849 850 850 my $oid_search_ix = $OID_NUMBER{'ifIndex'}; # base OID 851 my @args = ( -varbindlist =>[$oid_search_ix]);851 my @args = (-varbindlist => [$oid_search_ix]); 852 852 LOOP_ON_OID_PORT: 853 while ( defined $snmp_session->get_next_request(@args)) {853 while (defined $snmp_session->get_next_request(@args)) { 854 854 my ($oid_current) = $snmp_session->var_bind_names; 855 last LOOP_ON_OID_PORT if 855 last LOOP_ON_OID_PORT if not Net::SNMP::oid_base_match($oid_search_ix, $oid_current); 856 856 857 857 my $port_ifIndex = $snmp_session->var_bind_list->{$oid_current}; … … 862 862 @args = (-varbindlist => [$oid_current]); 863 863 864 my $oid_search_ifName = $OID_NUMBER{'ifName'} . '.'. $port_ifIndex;864 my $oid_search_ifName = $OID_NUMBER{'ifName'} . '.' . $port_ifIndex; 865 865 my $result = $snmp_session->get_request(-varbindlist => [$oid_search_ifName]); 866 866 next LOOP_ON_OID_PORT if not defined $result; … … 887 887 888 888 my $oid_search_index = $OID_NUMBER{'vlanName'}; # base OID 889 my @args = ( -varbindlist =>[$oid_search_index]);889 my @args = (-varbindlist => [$oid_search_index]); 890 890 LOOP_ON_VLAN: 891 while ( defined $snmp_session->get_next_request(@args)) {891 while (defined $snmp_session->get_next_request(@args)) { 892 892 my ($oid_current) = $snmp_session->var_bind_names; 893 893 last LOOP_ON_VLAN if not Net::SNMP::oid_base_match($oid_search_index, $oid_current); … … 950 950 @_); 951 951 952 init_switch_names('yes'); #nomme les switchs952 init_switch_names('yes'); # nomme les switchs 953 953 print "\n"; 954 954 … … 958 958 959 959 DETECT_ALL_ROUTER: 960 for my $one_router ( get_list_main_router(get_list_network())) {960 for my $one_router (get_list_main_router(get_list_network())) { 961 961 print "Info: router loop $one_router\n" if $args{'verbose'}; 962 962 my %resol_arp = resolve_ip_arp_host($one_router, q{*}, q{low}); # resolution arp … … 976 976 977 977 ALL_SWITCH_CONNECTED: 978 for my $switch_detected ( keys %{$where{$ip_router}}) {978 for my $switch_detected (keys %{$where{$ip_router}}) { 979 979 980 980 my $switch = $where{$ip_router}->{$switch_detected}; … … 989 989 my %db_switch_link_with = (); 990 990 991 my @list_all_switch = ();991 my @list_all_switch = (); 992 992 my @list_switch_ipv4 = (); 993 993 for my $sw (@SWITCH_LIST) { … … 1006 1006 my %resol_arp_alt = resolve_ip_arp_host($fake_ip, q{*}, q{low}); # arp resolution 1007 1007 if ($resol_arp_alt{'mac_address'} ne 'unknow') { 1008 $resol_arp{'mac_address'} 1009 $resol_arp{'interface'} 1008 $resol_arp{'mac_address'} = $resol_arp_alt{'mac_address'}; 1009 $resol_arp{'interface'} = $resol_arp_alt{'interface'}; 1010 1010 $resol_arp{'ipv4_address'} .= '*'; 1011 1011 # Force a MAC trace on switch … … 1040 1040 ALL_SWITCH_IP_ADDRESS: 1041 1041 for my $ip (@list_switch_ipv4) { 1042 # for my $ip (Net::Netmask::sort_by_ip_address(@list_switch_ipv4)) {1042 # for my $ip (Net::Netmask::sort_by_ip_address(@list_switch_ipv4)) { 1043 1043 1044 1044 print "VERBOSE_5: loop on $db_switch_ip_hostnamefq{$ip}\n" if $args{'verbose'}; 1045 1045 1046 1046 next ALL_SWITCH_IP_ADDRESS if not exists $where{$ip}; 1047 # next ALL_SWITCH_IP_ADDRESS if not exists $SWITCH_PORT_COUNT{ $db_switch_ip_hostnamefq{$ip} };1047 # next ALL_SWITCH_IP_ADDRESS if not exists $SWITCH_PORT_COUNT{ $db_switch_ip_hostnamefq{$ip} }; 1048 1048 1049 1049 DETECTED_SWITCH: 1050 for my $switch_detected ( keys %{$where{$ip}}) {1050 for my $switch_detected (keys %{$where{$ip}}) { 1051 1051 1052 1052 my $switch = $where{$ip}->{$switch_detected}; … … 1057 1057 next if $switch->{'hostname'} eq $db_switch_ip_hostnamefq{$ip}; # $computerdb->{$ip}{'hostname'}; 1058 1058 1059 $db_switch_link_with{ $db_switch_ip_hostnamefq{$ip}} ||= {};1060 $db_switch_link_with{ $db_switch_ip_hostnamefq{$ip} }->{ $switch->{'hostname'}} = $switch->{'port_hr'};1059 $db_switch_link_with{$db_switch_ip_hostnamefq{$ip}} ||= {}; 1060 $db_switch_link_with{$db_switch_ip_hostnamefq{$ip}}->{$switch->{'hostname'}} = $switch->{'port_hr'}; 1061 1061 print "VERBOSE_7: +++++\n" if $args{'verbose'}; 1062 1062 } … … 1064 1064 } 1065 1065 1066 my %db_switch_connected_on_port = ();1066 my %db_switch_connected_on_port = (); 1067 1067 my $maybe_more_than_one_switch_connected = 'yes'; 1068 my $cloop = 0;1068 my $cloop = 0; 1069 1069 1070 1070 while ($maybe_more_than_one_switch_connected eq 'yes' and $cloop < 100) { … … 1081 1081 } 1082 1082 1083 $maybe_more_than_one_switch_connected 1083 $maybe_more_than_one_switch_connected = 'no'; 1084 1084 1085 1085 SWITCH_AND_PORT: … … 1092 1092 my ($sw_connect, $port_connect) = split m/ $SEP_SWITCH_PORT /xms, $swport, 2; 1093 1093 my @sw_on_same_port = keys %{$db_switch_connected_on_port{$swport}}; 1094 print "VERBOSE_10: $swport -- " .$#sw_on_same_port." -- @sw_on_same_port\n" if $args{'verbose'};1094 print "VERBOSE_10: $swport -- " . $#sw_on_same_port . " -- @sw_on_same_port\n" if $args{'verbose'}; 1095 1095 1096 1096 CONNECTED: … … 1113 1113 } 1114 1114 1115 my %db_switch_parent = ();1115 my %db_switch_parent = (); 1116 1116 1117 1117 for my $sw (keys %db_switch_link_with) { … … 1174 1174 sub cmd_help { 1175 1175 1176 print <<'END';1176 print <<'END'; 1177 1177 klask - port and search manager for switches, map management 1178 1178 … … 1213 1213 sub cmd_version { 1214 1214 1215 print <<'END';1215 print <<'END'; 1216 1216 klask - port and search manager for switches, map management 1217 1217 Copyright (C) 2005-2017 Gabriel Moreau <Gabriel.Moreau(A)univ-grenoble-alpes.fr> … … 1228 1228 my @computer = @_; 1229 1229 1230 init_switch_names(); #nomme les switchs1230 init_switch_names(); # nomme les switchs 1231 1231 fast_ping(@computer); 1232 1232 1233 1233 LOOP_ON_COMPUTER: 1234 1234 for my $clientname (@computer) { 1235 my %resol_arp = resolve_ip_arp_host($clientname); #resolution arp1235 my %resol_arp = resolve_ip_arp_host($clientname); # resolution arp 1236 1236 my $vlan_name = get_current_vlan_name_for_interface($resol_arp{'interface'}); 1237 1237 my $vlan_id = get_current_vlan_id($vlan_name); 1238 my %where = find_switch_port($resol_arp{'mac_address'}, '', $vlan_id); # retrouve l'emplacement1238 my %where = find_switch_port($resol_arp{'mac_address'}, '', $vlan_id); # retrouve l'emplacement 1239 1239 1240 1240 next LOOP_ON_COMPUTER if $where{'switch_description'} eq 'unknow' or $resol_arp{'hostname_fq'} eq 'unknow' or $resol_arp{'mac_address'} eq 'unknow'; … … 1245 1245 $resol_arp{'hostname_fq'}, 1246 1246 $resol_arp{'ipv4_address'}, 1247 $resol_arp{'mac_address'} ."\n";1247 $resol_arp{'mac_address'} . "\n"; 1248 1248 } 1249 1249 return; … … 1252 1252 #--------------------------------------------------------------- 1253 1253 sub cmd_searchdb { 1254 my @ARGV 1254 my @ARGV = @_; 1255 1255 1256 1256 my $kind; … … 1261 1261 1262 1262 my %possible_search = ( 1263 host 1264 mac 1263 host => \&cmd_searchdb_host, 1264 mac => \&cmd_searchdb_mac, 1265 1265 ); 1266 1266 … … 1271 1271 } 1272 1272 1273 1274 1273 #--------------------------------------------------------------- 1275 1274 sub cmd_searchdb_host { … … 1281 1280 LOOP_ON_COMPUTER: 1282 1281 for my $clientname (@computer) { 1283 my %resol_arp = resolve_ip_arp_host($clientname); #resolution arp1284 my $ip = $resol_arp{'ipv4_address'};1282 my %resol_arp = resolve_ip_arp_host($clientname); # resolution arp 1283 my $ip = $resol_arp{'ipv4_address'}; 1285 1284 1286 1285 next LOOP_ON_COMPUTER unless exists $computerdb->{$ip}; 1287 1286 1288 my ($sec, $min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{'timestamp'};1287 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $computerdb->{$ip}{'timestamp'}; 1289 1288 $year += 1900; 1290 1289 $mon++; … … 1304 1303 #--------------------------------------------------------------- 1305 1304 sub cmd_searchdb_mac { 1306 my @mac = map { normalize_mac_address($_)} @_;1305 my @mac = map {normalize_mac_address($_)} @_; 1307 1306 1308 1307 my $computerdb = computerdb_load(); … … 1314 1313 next LOOP_ON_COMPUTER if $mac ne $computerdb->{$ip}{'mac_address'}; 1315 1314 1316 my ($sec, $min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{'timestamp'};1315 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $computerdb->{$ip}{'timestamp'}; 1317 1316 $year += 1900; 1318 1317 $mon++; … … 1348 1347 1349 1348 my @network = @ARGV; 1350 1349 @network = get_list_network() if not @network; 1351 1350 1352 1351 test_switchdb_environnement(); 1353 1352 1354 1353 my $computerdb = {}; 1355 1354 $computerdb = computerdb_load() if -e "$KLASK_DB_FILE"; 1356 1355 my $timestamp = time; 1357 1356 … … 1361 1360 my $number_of_computer = get_list_ip(@network); # + 1; 1362 1361 my $size_of_database = keys %{$computerdb}; 1363 $size_of_database= 1 if $size_of_database == 0;1364 my $i = 0;1362 $size_of_database = 1 if $size_of_database == 0; 1363 my $i = 0; 1365 1364 my $detected_computer = 0; 1366 1365 1367 init_switch_names('yes', $verb_description, $check_hostname, $check_location); #nomme les switchs1366 init_switch_names('yes', $verb_description, $check_hostname, $check_location); # nomme les switchs 1368 1367 1369 1368 { … … 1400 1399 my %router_mac_ip = (); 1401 1400 DETECT_ALL_ROUTER: 1402 # for my $one_router ('194.254.66.254') {1403 for my $one_router ( get_list_main_router(@network)) {1401 # for my $one_router ('194.254.66.254') { 1402 for my $one_router (get_list_main_router(@network)) { 1404 1403 my %resol_arp = resolve_ip_arp_host($one_router); 1405 $router_mac_ip{ $resol_arp{'mac_address'}} = $resol_arp{'ipv4_address'};1404 $router_mac_ip{$resol_arp{'mac_address'}} = $resol_arp{'ipv4_address'}; 1406 1405 } 1407 1406 … … 1409 1408 for my $current_net (@network) { 1410 1409 1411 my @computer = get_list_ip($current_net);1410 my @computer = get_list_ip($current_net); 1412 1411 my $current_interface = get_current_interface($current_net); 1413 1412 … … 1418 1417 $i++; 1419 1418 1420 my $total_percent = int (($i*100)/$number_of_computer);1419 my $total_percent = int(($i * 100) / $number_of_computer); 1421 1420 1422 1421 my $localtime = time - $timestamp; 1423 my ($sec, $min) = localtime $localtime;1422 my ($sec, $min) = localtime $localtime; 1424 1423 1425 1424 my $time_elapse = 0; 1426 $time_elapse = $localtime * (100 - $total_percent) / $total_percent if $total_percent != 0;1427 my ($sec_elapse, $min_elapse) = localtime $time_elapse;1428 1429 printf "\rComputer scanned: %4i/%i (%2i%%)", $i,$number_of_computer, $total_percent;1430 printf ', detected: %4i/%i (%2i%%)', $detected_computer, $size_of_database, int(($detected_computer*100)/$size_of_database);1431 printf ' [Time: %02i:%02i / %02i:%02i]', int($localtime /60), $localtime % 60, int($time_elapse/60), $time_elapse % 60;1425 $time_elapse = $localtime * (100 - $total_percent) / $total_percent if $total_percent != 0; 1426 my ($sec_elapse, $min_elapse) = localtime $time_elapse; 1427 1428 printf "\rComputer scanned: %4i/%i (%2i%%)", $i, $number_of_computer, $total_percent; 1429 printf ', detected: %4i/%i (%2i%%)', $detected_computer, $size_of_database, int(($detected_computer * 100) / $size_of_database); 1430 printf ' [Time: %02i:%02i / %02i:%02i]', int($localtime / 60), $localtime % 60, int($time_elapse / 60), $time_elapse % 60; 1432 1431 printf ' %-8s %-14s', $current_interface, $one_computer; 1433 1432 … … 1436 1435 1437 1436 # do not search on router connection (why ?) 1438 if ( 1437 if (exists $router_mac_ip{$resol_arp{'mac_address'}}) { 1439 1438 $computer_not_detected{$one_computer} = $current_net; 1440 1439 next LOOP_ON_COMPUTER; … … 1460 1459 my $vlan_name = get_current_vlan_name_for_interface($resol_arp{'interface'}); 1461 1460 my $vlan_id = get_current_vlan_id($vlan_name); 1462 my %where = find_switch_port($resol_arp{'mac_address'}, $switch_proposal, $vlan_id);1461 my %where = find_switch_port($resol_arp{'mac_address'}, $switch_proposal, $vlan_id); 1463 1462 1464 1463 #192.168.24.156: … … 1470 1469 1471 1470 # do not have a mac address 1472 # if ($resol_arp{'mac_address'} eq 'unknow') {1473 # $computer_not_detected{$one_computer} = $current_interface;1474 # next LOOP_ON_COMPUTER;1475 # }1471 # if ($resol_arp{'mac_address'} eq 'unknow') { 1472 # $computer_not_detected{$one_computer} = $current_interface; 1473 # next LOOP_ON_COMPUTER; 1474 # } 1476 1475 1477 1476 # detected on a switch … … 1513 1512 1514 1513 # relance un arping sur la machine si celle-ci n'a pas été détectée depuis plus d'une semaine 1515 #push @computer_not_detected, $resol_arp{'ipv4_address'} if $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week;1514 # push @computer_not_detected, $resol_arp{'ipv4_address'} if $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week; 1516 1515 $computer_not_detected{$resol_arp{'ipv4_address'}} = $current_net if $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week; 1517 1516 … … 1528 1527 1529 1528 for my $one_computer (keys %computer_not_detected) { 1530 my $current_net = $computer_not_detected{$one_computer};1529 my $current_net = $computer_not_detected{$one_computer}; 1531 1530 my $current_interface = get_current_interface($current_net); 1532 1531 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'; … … 1546 1545 for my $one_computer (@computer) { 1547 1546 1548 if ( 1549 and exists $computerdb->{$one_computer} 1547 if ($one_computer =~ m/^ $RE_IPv4_ADDRESS $/xms 1548 and exists $computerdb->{$one_computer}) { 1550 1549 delete $computerdb->{$one_computer}; 1551 1550 next; … … 1566 1565 #--------------------------------------------------------------- 1567 1566 sub cmd_cleandb { 1568 my @ARGV 1567 my @ARGV = @_; 1569 1568 1570 1569 my $days_to_clean = 15; … … 1574 1573 1575 1574 GetOptions( 1576 'day|d=i' => \$days_to_clean,1577 'verbose|v' => \$verbose,1575 'day|d=i' => \$days_to_clean, 1576 'verbose|v' => \$verbose, 1578 1577 'repair-dns|r' => \$repairdns, 1579 1578 ); … … 1582 1581 1583 1582 my $computerdb = computerdb_load(); 1584 my $timestamp = time;1583 my $timestamp = time; 1585 1584 1586 1585 my $timestamp_barrier = 3600 * 24 * $days_to_clean; … … 1591 1590 for my $vlan (shuffle @vlan_name) { 1592 1591 1593 my @ip_list 1592 my @ip_list = shuffle get_list_ip($vlan); 1594 1593 1595 1594 LOOP_ON_IP_ADDRESS: 1596 1595 for my $ip (@ip_list) { 1597 1596 1598 next LOOP_ON_IP_ADDRESS if1599 not exists $computerdb->{$ip};1600 1601 1597 next LOOP_ON_IP_ADDRESS 1598 if not exists $computerdb->{$ip}; 1599 1600 #&& $computerdb->{$ip}{'timestamp'} > $timestamp_barrier; 1602 1601 my $ip_timestamp = $computerdb->{$ip}{'timestamp'}; 1603 1602 my $ip_mac = $computerdb->{$ip}{'mac_address'}; … … 1643 1642 } 1644 1643 1645 if ( 1644 if ($ip_timestamp > $mactimedb{$ip_mac}->{'timestamp'}) { 1646 1645 $mactimedb{$ip_mac} = { 1647 1646 ip => $ip, … … 1670 1669 } 1671 1670 1672 if ( $database_has_changed) {1671 if ($database_has_changed) { 1673 1672 my $dirdb = $KLASK_DB_FILE; 1674 1673 $dirdb =~ s{ / [^/]* $}{}xms; … … 1729 1728 1730 1729 my $vlan = ''; 1731 $vlan = $computerdb->{$ip}{'network'} .'('.get_current_vlan_id($computerdb->{$ip}{'network'}).')' if $computerdb->{$ip}{'network'};1730 $vlan = $computerdb->{$ip}{'network'} . '(' . get_current_vlan_id($computerdb->{$ip}{'network'}).')' if $computerdb->{$ip}{'network'}; 1732 1731 1733 1732 my $arrow = '<---'; … … 1886 1885 1887 1886 my $vlan = $db_switch{$db_switch_parent{$sw}->{'switch'}}->{'network'}; 1888 $vlan .= ' (' .get_current_vlan_id($db_switch{$db_switch_parent{$sw}->{'switch'}}->{'network'}).')' if $db_switch{$db_switch_parent{$sw}->{'switch'}}->{'network'};1887 $vlan .= ' (' . get_current_vlan_id($db_switch{$db_switch_parent{$sw}->{'switch'}}->{'network'}) . ')' if $db_switch{$db_switch_parent{$sw}->{'switch'}}->{'network'}; 1889 1888 1890 1889 my $parent_port_hr = format_aggregator4html($db_switch_output_port{$sw}); … … 3288 3287 } 3289 3288 3290 3291 3289 ################################################################ 3292 3290 # documentation
Note: See TracChangeset
for help on using the changeset viewer.