Changeset 196
- Timestamp:
- Jan 5, 2017, 11:32:18 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r195 r196 7 7 use strict; 8 8 use warnings; 9 use version; our $VERSION = qv('0.5. 6');9 use version; our $VERSION = qv('0.5.7'); 10 10 11 11 use Readonly; … … 34 34 my $KLASK_CFG = YAML::Syck::LoadFile("$KLASK_CFG_FILE"); 35 35 36 my %DEFAULT = %{ $KLASK_CFG->{default}};37 my @SWITCH = @{ $KLASK_CFG->{switch}};38 39 my % switch_level= ();36 my %DEFAULT = %{$KLASK_CFG->{default}}; 37 my @SWITCH_LIST = @{$KLASK_CFG->{switch}}; 38 39 my %SWITCH_LEVEL = (); 40 40 my %SWITCH_DB = (); 41 41 LEVEL_OF_EACH_SWITCH: 42 for my $sw (@SWITCH ){43 $ switch_level{$sw->{hostname}} = $sw->{level} || $DEFAULT{switch_level} || 2;42 for my $sw (@SWITCH_LIST){ 43 $SWITCH_LEVEL{$sw->{hostname}} = $sw->{level} || $DEFAULT{switch_level} || 2; 44 44 $SWITCH_DB{$sw->{hostname}} = $sw; 45 45 } 46 @SWITCH = reverse sort { $switch_level{$a->{hostname}} <=> $switch_level{$b->{hostname}} } @{$KLASK_CFG->{switch}};47 48 my %SWITCH_PORT_COUNT = ();46 @SWITCH_LIST = reverse sort { $SWITCH_LEVEL{$a->{hostname}} <=> $SWITCH_LEVEL{$b->{hostname}} } @{$KLASK_CFG->{switch}}; 47 48 #my %SWITCH_PORT_COUNT = (); 49 49 50 50 my %CMD_DB = ( … … 270 270 # } 271 271 if ($ret{mac_address} eq 'unknow') { 272 # Another chance to have mac_address272 # Last chance to have the mac_address 273 273 my $cmd_arp = shell_command "ip neigh show to $ret{ipv4_address} dev $ret{interface}"; 274 274 if ( $cmd_arp =~ m{ ^$RE_IPv4_ADDRESS \s lladdr \s ( $RE_MAC_ADDRESS ) \s }xms ) { … … 313 313 314 314 INIT_EACH_SWITCH: 315 for my $sw (@SWITCH ) {315 for my $sw (@SWITCH_LIST) { 316 316 my %session = ( -hostname => $sw->{hostname} ); 317 317 $session{-version} = $sw->{version} || 1; … … 337 337 ] 338 338 ); 339 if (!defined $result) { 340 printf {*STDERR} "ERROR: %s.\n", $session->error(); 341 $session->close(); 342 # Remove bad switch 343 @SWITCH_LIST = grep { $_->{hostname} ne $sw->{hostname} } @SWITCH_LIST; 344 delete $SWITCH_LEVEL{$sw->{hostname}} if exists $SWITCH_LEVEL{$sw->{hostname}}; 345 delete $SWITCH_DB{$sw->{hostname}} if exists $SWITCH_DB{$sw->{hostname}}; 346 next INIT_EACH_SWITCH; 347 } 348 339 349 $sw->{description} = $result->{$OID_NUMBER{sysName}} || $sw->{hostname}; 340 350 $sw->{model} = get_switch_model($result->{$OID_NUMBER{sysDescription}}); … … 358 368 359 369 # Ligne à virer car on récupère maintenant le modèle du switch 360 my ($desc, $type) = split m/ : /xms, $sw->{description}, 2;370 #my ($desc, $type) = split m/ : /xms, $sw->{description}, 2; 361 371 printf "%-26s 0--------->>>> %-25s %s\n", $sw->{hostname}, $desc, $sw->{model} if $verbose; 362 372 } … … 424 434 return %ret if $mac_address eq 'unknow';; 425 435 426 my @switch_search = @SWITCH ;436 my @switch_search = @SWITCH_LIST; 427 437 if ($switch_proposal ne q{}) { 428 for my $sw (@SWITCH ) {438 for my $sw (@SWITCH_LIST) { 429 439 next if $sw->{hostname} ne $switch_proposal; 430 440 unshift @switch_search, $sw; … … 495 505 my $research2 = $OID_NUMBER{searchPort2} .'.'. $vlan_id . mac_address_hex_to_dec($mac_address); 496 506 LOOP_ON_ALL_SWITCH: 497 for my $sw (@SWITCH ) {507 for my $sw (@SWITCH_LIST) { 498 508 my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} ); 499 509 print "$error \n" if $error; … … 949 959 $db_switch_chained_port{$sw_connect} .= "$port_connect:"; 950 960 } 951 for my $sw (@SWITCH ){961 for my $sw (@SWITCH_LIST){ 952 962 push @{$sw->{portignore}}, $db_switch_output_port{$sw->{hostname}} if exists $db_switch_output_port{$sw->{hostname}}; 953 963 if ( exists $db_switch_chained_port{$sw->{hostname}} ) { … … 1003 1013 1004 1014 # do not search on switch inter-connection 1005 if (exists $ switch_level{$resol_arp{hostname_fq}}) {1015 if (exists $SWITCH_LEVEL{$resol_arp{hostname_fq}}) { 1006 1016 $computer_not_detected{$one_computer} = $current_net; 1007 1017 next LOOP_ON_COMPUTER; … … 1616 1626 } 1617 1627 1618 $switch_name = join(',', map {$_->{hostname}} @SWITCH ) if $switch_name eq q{*};1628 $switch_name = join(',', map {$_->{hostname}} @SWITCH_LIST ) if $switch_name eq q{*}; 1619 1629 1620 1630 for my $sw_name (split /,/, $switch_name) { … … 1772 1782 } 1773 1783 1774 $switch_name = join(',', map {$_->{hostname}} @SWITCH ) if $switch_name eq q{*};1784 $switch_name = join(',', map {$_->{hostname}} @SWITCH_LIST ) if $switch_name eq q{*}; 1775 1785 1776 1786 for my $sw_name (split /,/, $switch_name) { … … 1825 1835 my $sw_location = q{}; 1826 1836 LOOP_ON_ALL_SWITCH: 1827 for my $sw (@SWITCH ) {1837 for my $sw (@SWITCH_LIST) { 1828 1838 next LOOP_ON_ALL_SWITCH if $sw_hostname ne $sw->{hostname}; 1829 1839 $sw_location = $sw->{location}; … … 2021 2031 2022 2032 $mac_address = normalize_mac_address($mac_address); 2023 $switch_name = join(',', map {$_->{hostname}} @SWITCH ) if $switch_name eq q{*};2033 $switch_name = join(',', map {$_->{hostname}} @SWITCH_LIST ) if $switch_name eq q{*}; 2024 2034 2025 2035 for my $sw_name (split /,/, $switch_name) { … … 2088 2098 2089 2099 DETECT_ALL_ROUTER: 2090 # for my $one_computer ('194.254.66.254') {2091 2100 for my $one_router ( get_list_main_router(get_list_network()) ) { 2101 print "Info: router loop $one_router\n" if $verbose; 2092 2102 my %resol_arp = resolve_ip_arp_host($one_router, q{*}, q{low}); # resolution arp 2093 2103 … … 2121 2131 my @list_all_switch = (); 2122 2132 my @list_switch_ipv4 = (); 2123 for my $sw (@SWITCH ){2133 for my $sw (@SWITCH_LIST){ 2124 2134 push @list_all_switch, $sw->{hostname}; 2125 2135 } … … 2130 2140 for my $one_computer (@list_all_switch) { 2131 2141 my %resol_arp = resolve_ip_arp_host($one_computer, q{*}, q{low}); # arp resolution 2142 print "Info: switch loop $one_computer\n" if $verbose; 2132 2143 next ALL_SWITCH if $resol_arp{mac_address} eq 'unknow'; 2133 2144 … … 2348 2359 2349 2360 my %db_building= (); 2350 for my $sw (@SWITCH ) {2361 for my $sw (@SWITCH_LIST) { 2351 2362 my ($building, $location) = split m/ \/ /xms, $sw->{location}, 2; 2352 2363 $db_building{$building} ||= {};
Note: See TracChangeset
for help on using the changeset viewer.