Changeset 44
- Timestamp:
- Apr 20, 2009, 3:11:17 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r43 r44 9 9 10 10 use Net::SNMP; 11 use YAML; 11 #use YAML; 12 use YAML::Syck; 12 13 use Net::Netmask; 13 14 use Net::CIDR::Lite; … … 26 27 test_running_environnement(); 27 28 28 my $KLASK_CFG = YAML:: LoadFile("$KLASK_CFG_FILE");29 my $KLASK_CFG = YAML::Syck::LoadFile("$KLASK_CFG_FILE"); 29 30 30 31 my %DEFAULT = %{$KLASK_CFG->{default}}; … … 84 85 J9022A => { model => 'HP2810-48G', match => 'ProCurve J9022A Switch 2810-48G' }, 85 86 J4903A => { model => 'HP2824', match => 'J4903A.+?Switch 2824,' }, 86 J8692A => { model => 'HP3500-24G', match => 'J8692A' },87 87 J4110A => { model => 'HP8000M', match => 'HP J4110A ProCurve Switch 8000M' }, 88 88 BS350T => { model => 'BS350T', match => 'BayStack 350T HW' }, … … 145 145 146 146 # my $cmdarping = `arping -c 1 -w 1 -rR $param 2>/dev/null`; 147 if (not $param_ip_or_host =~ m/^\d+\.\d+\.\d+\.\d+$/) { 148 $param_ip_or_host =~ s/\..*//; 149 } 147 150 148 151 # controler que arpwatch tourne ! … … 150 153 # /var/lib/arpwatch/arp.dat 151 154 # 0:13:d3:e1:92:d0 192.168.24.109 1163681980 theo8sv109 152 # my $cmd = "grep -e '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/arp.dat | sort +2rn | head -1";153 #my $cmd = "grep -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1";154 my $cmd = "grep -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/$interface.dat | sort -rn -k 2| head -1";155 # my $cmd = "grep -e '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/arp.dat | sort +2rn | head -1"; 156 # my $cmd = "grep -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1"; 157 my $cmd = "grep -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1"; 155 158 my $cmd_arpwatch = `$cmd`; 156 159 chomp $cmd_arpwatch; 157 160 my ($arp, $ip, $timestamp, $host) = split /\s+/, $cmd_arpwatch; 161 158 162 #print "OOO $cmd\n"; 159 163 #print "TTT arp $arp -> $ip pour host $host\n"; 164 160 165 $ret{ipv4_address} = $ip if $ip; 161 166 $ret{mac_address} = $arp if $arp; … … 171 176 # resultat de la commande arp 172 177 # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0 178 # sw2-batF0-legi.hmg.priv (192.168.22.112) at 00:30:c1:76:9c:01 [ether] on eth0.37 173 179 my $cmd_arp = `arp -a $param_ip_or_host 2>/dev/null`; 174 180 chomp $cmd_arp; … … 177 183 $ret{ipv4_address} = $2 if(defined($2)); 178 184 $ret{mac_address} = $3 if(defined($3)); 185 #print "RET1 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n"; 179 186 180 187 # if ($ret{ipv4_address} eq '0.0.0.0' and $ret{mac_address} eq 'unknow'and $ret{hostname_fq} eq 'unknow') { … … 188 195 # resultat de la commande host si parametre est hostname 189 196 # tech7meylan.hmg.inpg.fr has address 194.254.66.240 190 $cmd_host =~ m/\shas\saddress\s([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/; 191 $ret{ipv4_address} = $1 if defined $1; 197 $cmd_host =~ m/(\S*)\shas\saddress\s([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/; 198 $ret{hostname_fq} = $1 if defined $1; 199 $ret{ipv4_address} = $2 if defined $2; 192 200 193 201 $cmd_host =~ m/\b([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.in-addr\.arpa\s/; … … 196 204 # } 197 205 206 #print "RET2 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n"; 198 207 unless ($ret{mac_address} eq 'unknow') { 199 208 my @paquets = (); … … 205 214 } 206 215 216 #print "RET3 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n"; 207 217 return %ret; 208 218 } … … 533 543 534 544 fastping(@computer); 535 my $computerdb = YAML:: LoadFile("$KLASK_DB_FILE");545 my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE"); 536 546 537 547 LOOP_ON_COMPUTER: … … 564 574 565 575 my $computerdb = {}; 566 $computerdb = YAML:: LoadFile("$KLASK_DB_FILE") if -e "$KLASK_DB_FILE";576 $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE") if -e "$KLASK_DB_FILE"; 567 577 my $timestamp = time; 568 578 … … 579 589 580 590 { # Remplis le champs portignore des ports d'inter-connection pour chaque switch 581 my $switch_connection = YAML:: LoadFile("$KLASK_SW_FILE");591 my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE"); 582 592 my %db_switch_output_port = %{$switch_connection->{output_port}}; 583 593 my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}}; … … 724 734 $dirdb =~ s#/[^/]*$##; 725 735 mkdir "$dirdb", 0755 unless -d "$dirdb"; 726 YAML:: DumpFile("$KLASK_DB_FILE", $computerdb);736 YAML::Syck::DumpFile("$KLASK_DB_FILE", $computerdb); 727 737 728 738 for my $one_computer (keys %computer_not_detected) { … … 738 748 test_maindb_environnement(); 739 749 740 my $computerdb = YAML:: LoadFile("$KLASK_DB_FILE");750 my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE"); 741 751 742 752 LOOP_ON_COMPUTER: … … 751 761 $dirdb =~ s#/[^/]*$##; 752 762 mkdir "$dirdb", 0755 unless -d "$dirdb"; 753 YAML:: DumpFile("$KLASK_DB_FILE", $computerdb);763 YAML::Syck::DumpFile("$KLASK_DB_FILE", $computerdb); 754 764 } 755 765 … … 757 767 test_maindb_environnement(); 758 768 759 my $computerdb = YAML:: LoadFile("$KLASK_DB_FILE");769 my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE"); 760 770 761 771 printf "%-24s %-4s %-30s %-15s %-18s %-s\n", qw(Switch Port Hostname IPv4-Address MAC-Address Date); … … 789 799 790 800 sub cmd_iplocation { 791 my $computerdb = YAML:: LoadFile("$KLASK_DB_FILE");801 my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE"); 792 802 793 803 LOOP_ON_IP_ADDRESS: … … 889 899 # for my $one_computer ('194.254.66.254') { 890 900 for my $one_router ( get_list_main_router(get_list_network()) ) { 901 print "TT$one_router\n"; 891 902 my %resol_arp = resolve_ip_arp_host($one_router,'*','low'); # resolution arp 892 903 next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow'; 893 904 print "$one_router\n"; 894 905 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements des routeurs 895 906 } … … 1054 1065 }; 1055 1066 1056 YAML:: DumpFile("$KLASK_SW_FILE", $switch_connection);1067 YAML::Syck::DumpFile("$KLASK_SW_FILE", $switch_connection); 1057 1068 } 1058 1069 … … 1080 1091 sub cmd_exportsw_txt { 1081 1092 1082 my $switch_connection = YAML:: LoadFile("$KLASK_SW_FILE");1093 my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE"); 1083 1094 1084 1095 my %db_switch_output_port = %{$switch_connection->{output_port}}; … … 1115 1126 sub cmd_exportsw_dot { 1116 1127 1117 my $switch_connection = YAML:: LoadFile("$KLASK_SW_FILE");1128 my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE"); 1118 1129 1119 1130 my %db_switch_output_port = %{$switch_connection->{output_port}};
Note: See TracChangeset
for help on using the changeset viewer.