/[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 381 - (show annotations)
Sun Aug 30 17:24:19 2009 UTC (13 years, 3 months ago) by dpavlin
File size: 811 byte(s)
store pings in couchdb
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 CouchDB;
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 CouchDB::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