7 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
8 |
use Time::HiRes; |
use Time::HiRes; |
9 |
use client; |
use client; |
10 |
|
use CouchDB; |
11 |
|
|
12 |
sub host { |
sub host { |
13 |
Net::Ping->new->ping( shift, 0.7 ); |
my $ip = shift; |
14 |
|
my $status = fping($ip); |
15 |
|
defined $status->{$ip}; |
16 |
} |
} |
17 |
|
|
18 |
sub fping { |
sub fping { |
27 |
|
|
28 |
if ( $ret ) { |
if ( $ret ) { |
29 |
$syn{$host} = $ip; |
$syn{$host} = $ip; |
|
# $status->{dns}->{$ip} = $nslookup_duration * 1000; |
|
30 |
} else { |
} else { |
31 |
push @{ $status->{address_not_found} }, $host; |
push @{ $status->{address_not_found} }, $host; |
32 |
} |
} |
33 |
} |
} |
34 |
|
|
35 |
while (my ($host,$rtt,$ip) = $p->ack) { |
while (my ($host,$rtt,$ip) = $p->ack) { |
|
$status->{$ip}->{rtt} = $rtt * 1000; # ms |
|
36 |
warn "# $host $rtt $ip\n"; |
warn "# $host $rtt $ip\n"; |
37 |
|
$rtt *= 1000; # ms |
38 |
client::conf( $ip => 'hostname', default => $host ) if $host ne $ip; |
client::conf( $ip => 'hostname', default => $host ) if $host ne $ip; |
39 |
|
$status->{$host} = { host => $host, rtt => $rtt, ip => $ip }; |
40 |
|
CouchDB::audit( $ip, $status->{$host}); |
41 |
} |
} |
42 |
|
|
43 |
warn "# fping ",dump($status); |
warn "# fping ",dump($status); |