lib/App/MadEye/Plugin/Agent/DNS.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 51 CC 4 SCAR 24.0
CC
4
Cov
0%
is_dead
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 11.0
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;