| 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 $timeout = $self->config->{config}->{timeout}; | ||
| 12 | |||
| 13 | my $p = Net::Ping->new("tcp"); | ||
| 14 | $p->hires(1); | ||
| 15 | my ( $ret, ) = $p->ping( $host, $timeout ); | ||
| 16 | $p->close; | ||
| 17 | |||
| 18 | if ($ret) { | ||
| 19 | return; # success | ||
| 20 | } else { | ||
| 21 | return "dead"; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | 1; | ||
| 26 | __END__ |