use Time::HiRes qw(time);
use Data::Dump qw(dump);
use Redis;
+use Net::Ping;
with 'APKPM::Gearman::Client';
with 'APKPM::Gearman';
$redis->sadd('poll.queued' => $ip);
}
+ undef $entries;
+ undef $ip_username;
+
warn "# wait";
$taskset->wait;
$poll->{$n} = eval { $redis->scard($k) } || $redis->get($k);
}
- warn dump $poll;
+ warn "# poll = ",dump $poll;
$self->do_background_json('Store_insert', { _table => 'poll', %$poll });
- return { ldap => $ip_username, results => $results, poll => $poll };
+ warn "# results = ", dump $results;
+ return $results;
}
sub poll_ip_username : Job : Decode(d_array) : Encode(e_json) {
my ( $ip, $username ) = @$workload;
return { error => "invalid workload", expected => "ip username" } unless $ip && $username;
- my $ping = $self->do('ping', $ip);
+
+ my $p = Net::Ping->new;
+ $p->hires;
my $redis = Redis->new;
+
+ my ( $ok, $rtt, $ping_ip ) = $p->ping( $ip );
- if ( exists $ping->{error} ) {
-warn "XXX error: $ip";
- $redis->sadd( 'poll.ping.error' => $ip );
- return $ping;
- } else {
+ if ( $ok ) {
$redis->sadd( 'poll.ping.ok' => $ip );
+ } else {
+ $redis->sadd( 'poll.ping.error' => $ip );
+ return { error => "ping $ip" };
}
- $ping->{username} = $username;
- $ping->{timestamp} = $self->datetime_now;
$self->do_background_json( 'Store_insert', {
_table => 'ping',
username => $username,
timestamp => $self->datetime_now,
- %$ping
+ ip => $ping_ip,
+ rtt => $rtt,
});
$self->do_background( 'Davolink_info', "$ip $username adsl" );
- return $ping;
+ return { ip => $ip, rtt => $rtt };
}
1;