Changeset 114
- Timestamp:
- Oct 1, 2012, 5:36:13 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r113 r114 65 65 'ip-free' => \&cmd_ip_free, 66 66 'search-mac-on-switch' => \&cmd_search_mac_on_switch, 67 'bad-vlan-config' => \&cmd_bad_vlan_config, 67 68 ); 68 69 … … 1186 1187 } 1187 1188 1189 sub cmd_bad_vlan_config { 1190 test_maindb_environnement(); 1191 1192 my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE"); 1193 1194 my %swithportdb = (); 1195 LOOP_ON_IP_ADDRESS: 1196 foreach my $ip (keys %{$computerdb}) { 1197 # to be improve in the future 1198 next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} eq ($computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}); # switch on himself ! 1199 1200 my $ip_timestamp = $computerdb->{$ip}{timestamp}; 1201 my $ip_mac = $computerdb->{$ip}{mac_address}; 1202 my $ip_hostname_fq = $computerdb->{$ip}{hostname_fq}; 1203 1204 my $swpt = sprintf "%-28s %2s", $computerdb->{$ip}{switch_hostname}, $computerdb->{$ip}{switch_port}; 1205 $swithportdb{$swpt} ||= { 1206 ip => $ip, 1207 timestamp => $ip_timestamp, 1208 vlan => $computerdb->{$ip}{network}, 1209 hostname_fq => $ip_hostname_fq, 1210 mac_address => $ip_mac, 1211 }; 1212 1213 if ( 1214 ($ip_timestamp > $swithportdb{$swpt}->{timestamp}) 1215 and ( 1216 $ip_hostname_fq !~ m/^float/ 1217 or $ip_timestamp > ( $swithportdb{$swpt}->{timestamp} + (15 * 24 * 3600) ) 1218 ) 1219 ) { 1220 $swithportdb{$swpt} = { 1221 ip => $ip, 1222 timestamp => $ip_timestamp, 1223 vlan => $computerdb->{$ip}{network}, 1224 hostname_fq => $ip_hostname_fq, 1225 mac_address => $ip_mac, 1226 }; 1227 } 1228 } 1229 1230 foreach my $swpt (keys %swithportdb) { 1231 next if $swpt =~ m/^\s*0$/; 1232 next if $swithportdb{$swpt}->{hostname_fq} !~ m/^float/; 1233 1234 my $src_ip = $swithportdb{$swpt}->{ip}; 1235 my $src_timestamp = 0; 1236 foreach my $ip (keys %{$computerdb}) { 1237 next if $computerdb->{$ip}{mac_address} ne $swithportdb{$swpt}->{mac_address}; 1238 next if $computerdb->{$ip}{hostname_fq} =~ m/^float/; 1239 next if $computerdb->{$ip}{timestamp} < $src_timestamp; 1240 1241 $src_ip = $ip; 1242 $src_timestamp = $computerdb->{$ip}{timestamp}; 1243 } 1244 1245 next if $src_timestamp == 0; 1246 1247 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $swithportdb{$swpt}->{timestamp}; 1248 $year += 1900; 1249 $mon++; 1250 my $date = sprintf '%04i-%02i-%02i %02i:%02i', $year, $mon, $mday, $hour, $min; 1251 1252 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$src_ip}{timestamp}; 1253 $year += 1900; 1254 $mon++; 1255 my $src_date = sprintf '%04i-%02i-%02i %02i:%02i', $year, $mon, $mday, $hour, $min; 1256 1257 printf "%s / %-10s +-> %-10s %s / %s # %s\n", 1258 $swpt, $swithportdb{$swpt}->{vlan}, $computerdb->{$src_ip}{network}, 1259 $date, 1260 $src_date, 1261 $computerdb->{$src_ip}{hostname_fq}; 1262 } 1263 } 1264 1188 1265 sub cmd_ip_location { 1189 1266 my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
Note: See TracChangeset
for help on using the changeset viewer.