Changeset 13
- Timestamp:
- Jan 31, 2008, 11:37:27 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r12 r13 13 13 # libcrypt-des-perl libcrypt-hcesha-perl libdigest-hmac-perl 14 14 15 my $KLASK_DB = '/var/cache/klask/klaskdb';16 my $KLASK_SW = '/var/cache/klask/switchdb';17 my $KLASK_CFG = '/etc/klask.conf';18 19 my $KLASK_CFG = YAML::LoadFile("$KLASK_CFG ");15 my $KLASK_DB_FILE = '/var/cache/klask/klaskdb'; 16 my $KLASK_SW_FILE = '/var/cache/klask/switchdb'; 17 my $KLASK_CFG_FILE = '/etc/klask.conf'; 18 19 my $KLASK_CFG = YAML::LoadFile("$KLASK_CFG_FILE"); 20 20 21 21 my %DEFAULT = %{$KLASK_CFG->{default}}; … … 317 317 318 318 my $ret = {}; 319 # $ret->{unknow} = {};320 # $ret->{unknow}{description} = "unknow";321 # $ret->{unknow}{port} = "0";322 319 323 320 return $ret if $arp eq 'unknow'; … … 325 322 for my $sw (@SWITCH) { 326 323 $switch_port_count{$sw->{hostname}} = {} if not exists $switch_port_count{$sw->{hostname}}; 327 # $sw->{_port} = {} if not exists $sw->{_port};328 324 } 329 325 330 326 my $research = "1.3.6.1.2.1.17.4.3.1.2".arp_hex_to_dec($arp); 331 #print " $arp -> $research\n";332 327 LOOP_ON_ALL_SWITCH: 333 328 for my $sw (@SWITCH) { 334 329 my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} ); 335 print "$error \n" if $error; 336 # -hostname => $sw->{hostname}, 337 # -community => $sw->{community} || $DEFAULT{community} || 'public', 338 # -port => $sw->{snmpport} || $DEFAULT{snmpport} || 161 339 # ); 340 #print "$sw->{hostname} -- $research \n"; 330 print "$error \n" if $error; 331 341 332 my $result = $session->get_request( 342 333 -varbindlist => [$research] 343 334 ); 335 344 336 if(defined($result) and $result->{$research} ne 'noSuchInstance'){ 345 #print "+++ $sw->{hostname} -> $result->{$research}\n" ;346 337 my $swport = $result->{$research}; 347 338 … … 352 343 353 344 $switch_port_count{$sw->{hostname}}->{$swport}++; 354 # $sw->{_port}{$swport}++;355 }356 else {357 #print "$sw->{hostname} -- $research --".$session->error()."\n";358 345 } 359 346 360 347 $session->close; 361 348 } 362 #print "end \n";363 349 return $ret; 364 350 } … … 482 468 483 469 fastping(@computer); 484 my $computerdb = YAML::LoadFile("$KLASK_DB ");470 my $computerdb = YAML::LoadFile("$KLASK_DB_FILE"); 485 471 486 472 LOOP_ON_COMPUTER: … … 510 496 @network = get_list_network() if not @network; 511 497 512 my $computerdb = YAML::LoadFile("$KLASK_DB ");498 my $computerdb = YAML::LoadFile("$KLASK_DB_FILE"); 513 499 my $timestamp = time; 514 500 … … 647 633 printf "\n"; 648 634 649 my $dirdb = $KLASK_DB ;635 my $dirdb = $KLASK_DB_FILE; 650 636 $dirdb =~ s#/[^/]*$##; 651 637 mkdir "$dirdb", 0755 unless -d "$dirdb"; 652 YAML::DumpFile("$KLASK_DB ", $computerdb);638 YAML::DumpFile("$KLASK_DB_FILE", $computerdb); 653 639 654 640 for my $one_computer (keys %computer_not_detected) { … … 662 648 my @computer = @_; 663 649 664 my $computerdb = YAML::LoadFile("$KLASK_DB ");650 my $computerdb = YAML::LoadFile("$KLASK_DB_FILE"); 665 651 666 652 LOOP_ON_COMPUTER: … … 672 658 } 673 659 674 my $dirdb = $KLASK_DB ;660 my $dirdb = $KLASK_DB_FILE; 675 661 $dirdb =~ s#/[^/]*$##; 676 662 mkdir "$dirdb", 0755 unless -d "$dirdb"; 677 YAML::DumpFile("$KLASK_DB ", $computerdb);663 YAML::DumpFile("$KLASK_DB_FILE", $computerdb); 678 664 } 679 665 680 666 sub cmd_exportdb { 681 my $computerdb = YAML::LoadFile("$KLASK_DB ");667 my $computerdb = YAML::LoadFile("$KLASK_DB_FILE"); 682 668 683 669 printf "%-24s %-4s %-30s %-15s %-18s %-s\n", qw(Switch Port Hostname IPv4-Address MAC-Address Date); … … 711 697 712 698 sub cmd_iplocation { 713 my $computerdb = YAML::LoadFile("$KLASK_DB ");699 my $computerdb = YAML::LoadFile("$KLASK_DB_FILE"); 714 700 715 701 LOOP_ON_IP_ADDRESS: … … 768 754 # for my $one_computer ('194.254.66.254') { 769 755 for my $one_router ( get_list_main_router(get_list_network()) ) { 770 my %resol_arp = resolve_ip_arp_host($one_router,'*','low'); # resolution arp756 my %resol_arp = resolve_ip_arp_host($one_router,'*','low'); # resolution arp 771 757 next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow'; 772 758 773 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements759 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements des routeurs 774 760 } 775 761 776 762 ALL_ROUTER_IP_ADDRESS: 777 for my $ip (Net::Netmask::sort_by_ip_address( '194.254.66.254')) {778 779 next ALL_ROUTER_IP_ADDRESS if not exists $where{$ip}; 763 for my $ip (Net::Netmask::sort_by_ip_address(keys %where)) { # '194.254.66.254')) { 764 765 next ALL_ROUTER_IP_ADDRESS if not exists $where{$ip}; # /a priori/ idiot car ne sers à rien... 780 766 781 767 ALL_SWITCH_CONNECTED: … … 932 918 }; 933 919 934 YAML::DumpFile("$KLASK_SW ", $switch_connection);920 YAML::DumpFile("$KLASK_SW_FILE", $switch_connection); 935 921 } 936 922 … … 957 943 sub cmd_exportsw_txt { 958 944 959 my $switch_connection = YAML::LoadFile("$KLASK_SW ");945 my $switch_connection = YAML::LoadFile("$KLASK_SW_FILE"); 960 946 961 947 my %db_switch_output_port = %{$switch_connection->{output_port}}; … … 992 978 sub cmd_exportsw_dot { 993 979 994 my $switch_connection = YAML::LoadFile("$KLASK_SW ");980 my $switch_connection = YAML::LoadFile("$KLASK_SW_FILE"); 995 981 996 982 my %db_switch_output_port = %{$switch_connection->{output_port}};
Note: See TracChangeset
for help on using the changeset viewer.