|
Revision 7553, 456 bytes
(checked in by tokuhirom, 5 years ago)
|
|
bug fixed.
|
| Line | |
|---|
| 1 | package App::MadEye::Plugin::Agent::Ping; |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use App::MadEye::Plugin::Agent::Base; |
|---|
| 5 | |
|---|
| 6 | use Net::Ping; |
|---|
| 7 | |
|---|
| 8 | sub is_dead { |
|---|
| 9 | my ($self, $host) = @_; |
|---|
| 10 | |
|---|
| 11 | my $conf = $self->config->{config}; |
|---|
| 12 | my $timeout = $conf->{timeout} || 5; |
|---|
| 13 | |
|---|
| 14 | my $p = Net::Ping->new("tcp"); |
|---|
| 15 | $p->hires(1); |
|---|
| 16 | my ( $ret, ) = $p->ping( $host, $timeout ); |
|---|
| 17 | $p->close; |
|---|
| 18 | |
|---|
| 19 | if ($ret) { |
|---|
| 20 | return; # success |
|---|
| 21 | } else { |
|---|
| 22 | return "dead"; |
|---|
| 23 | } |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | 1; |
|---|
| 27 | |
|---|