| 1 | package App::MadEye::Plugin::Agent::DNS; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use App::MadEye::Plugin::Agent::Base; | ||
| 5 | use Net::DNS; | ||
| 6 | |||
| 7 | sub is_dead { | ||
| 8 | my ($self, $target) = @_; | ||
| 9 | |||
| 10 | my $host = $target->{host} or die "missing host"; | ||
| 11 | my $name = $target->{name} or die "missing name"; | ||
| 12 | my $ip = $target->{ip} or die "missing ip"; | ||
| 13 | my $timeout = $target->{timeout} || 10; | ||
| 14 | |||
| 15 | my $dns = Net::DNS::Resolver->new( | ||
| 16 | recurse => 0, | ||
| 17 | nameservers => ref($host) eq 'ARRAY' ? $host : [$host], | ||
| 18 | ); | ||
| 19 | $dns->tcp_timeout($timeout); | ||
| 20 | $dns->udp_timeout($timeout); | ||
| 21 | my $packet = $dns->search($name); | ||
| 22 | if ($packet) { | ||
| 23 | if ($packet->string =~ /$ip/) { | ||
| 24 | return; # alive. | ||
| 25 | } else { | ||
| 26 | return "invalid IP : " . $packet->string; | ||
| 27 | } | ||
| 28 | } else { | ||
| 29 | return 'DEAD'; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | 1; |