/[pxelator]/lib/PXElator/ping.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/ping.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 482 - (show annotations)
Sat Jan 23 18:31:14 2010 UTC (14 years, 3 months ago) by dpavlin
File size: 807 byte(s)
use store::audit proxy all over the place

1 package ping;
2
3 use warnings;
4 use strict;
5
6 use Net::Ping;
7 use Data::Dump qw/dump/;
8 use Time::HiRes;
9 use client;
10 use store;
11
12 sub host {
13 my $ip = shift;
14 my $status = fping($ip);
15 defined $status->{$ip};
16 }
17
18 sub fping {
19 my $p = Net::Ping->new('syn', 0.3);
20 $p->hires;
21
22 my $status;
23 my %syn;
24
25 foreach my $host ( @_ ) {
26 my ($ret,$nslookup_duration,$ip) = $p->ping($host);
27
28 if ( $ret ) {
29 $syn{$host} = $ip;
30 } else {
31 push @{ $status->{address_not_found} }, $host;
32 }
33 }
34
35 while (my ($host,$rtt,$ip) = $p->ack) {
36 warn "# $host $rtt $ip\n";
37 $rtt *= 1000; # ms
38 client::conf( $ip => 'hostname', default => $host ) if $host ne $ip;
39 $status->{$host} = { host => $host, rtt => $rtt, ip => $ip };
40 store::audit( $ip, $status->{$host});
41 }
42
43 warn "# fping ",dump($status);
44
45 return $status;
46
47 }
48
49 1;

  ViewVC Help
Powered by ViewVC 1.1.26