/[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

Annotation of /lib/PXElator/ping.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 381 - (hide annotations)
Sun Aug 30 17:24:19 2009 UTC (13 years, 5 months ago) by dpavlin
File size: 811 byte(s)
store pings in couchdb
1 dpavlin 330 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 dpavlin 332 use client;
10 dpavlin 381 use CouchDB;
11 dpavlin 330
12     sub host {
13 dpavlin 381 my $ip = shift;
14     my $status = fping($ip);
15     defined $status->{$ip};
16 dpavlin 330 }
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 dpavlin 331 warn "# $host $rtt $ip\n";
37 dpavlin 381 $rtt *= 1000; # ms
38 dpavlin 331 client::conf( $ip => 'hostname', default => $host ) if $host ne $ip;
39 dpavlin 381 $status->{$host} = { host => $host, rtt => $rtt, ip => $ip };
40     CouchDB::audit( $ip, $status->{$host});
41 dpavlin 330 }
42    
43 dpavlin 334 warn "# fping ",dump($status);
44 dpavlin 330
45     return $status;
46    
47     }
48    
49     1;

  ViewVC Help
Powered by ViewVC 1.1.26