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

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 68 CC 4 SCAR 22.2
CC
4
Cov
0%
is_dead
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 9.2
1 package App::MadEye::Plugin::Agent::DJabberd;
2 use strict;
3 use warnings;
4 use App::MadEye::Plugin::Agent::Base;
5  
6 use Socket qw(IPPROTO_TCP TCP_NODELAY SOL_SOCKET SOCK_STREAM);
7 use IO::Socket::INET;
8 use IO::Select;
9  
10 sub is_dead {
11 my ($self, $host) = @_;
12  
13 my $conf = $self->config->{config};
14 my $admin_port = $conf->{admin_port} or die "missing admin port";
15 my $open_socket_timeout = $conf->{open_socket_timeout} || 10;
16 my $select_timeout = $conf->{select_timeout} || 3;
17  
18 my $sock = IO::Socket::INET->new(
19 PeerAddr => $host,
20 PeerPort => $admin_port,
21 Timeout => $open_socket_timeout,
22 );
23 unless ($sock) {
24 return "Cannot open Socket to $host:$admin_port : $!";
25 }
26 $sock->blocking(0);
27 $sock->setsockopt( IPPROTO_TCP, TCP_NODELAY, pack( "l", 1 ) ) or die;
28 $sock->autoflush(1);
29  
30 $sock->print("version\r\n");
31  
32 my $select = IO::Select->new;
33 $select->add($sock);
34  
35 my ( $can_read, ) = $select->can_read($select_timeout);
36 unless ($can_read) {
37 $sock->close;
38  
39 return "connection timeout : $host";
40 }
41  
42 my $line = <$sock>;
43 $sock->close();
44  
45 if ( $line =~ /\d+\.\d+/ ) {
46 return;
47 }
48 else {
49 return "djabberd response is invaild : $line";
50 }
51 }
52  
53 1;
54 __END__