Skip to content

Commit

Permalink
Merge pull request #27 from stockholmuniversity/v3withv2respond
Browse files Browse the repository at this point in the history
Handle servers that responds with a v2 packet to a v3 request.
  • Loading branch information
mickenordin authored Nov 23, 2018
2 parents 1b8590f + a620bba commit 1546e65
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions lib/Nagios/NRPE/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -253,34 +253,48 @@ sub run
}
close($socket);

if (!$response)
if($response)
{
$socket = $self->create_socket();
if (ref $socket eq "REF")
my $responsePacket = $packet->disassemble($response);
if ($responsePacket->{packet_version})
{
return ($socket);
if ($responsePacket->{packet_version} == 3)
{
return $responsePacket;
}
}
$packet = Nagios::NRPE::Packet->new();
$response = undef;
$assembled = $packet->assemble(
type => NRPE_PACKET_QUERY,
check => $check,
version => NRPE_PACKET_VERSION_2
);

print $socket $assembled;
while (<$socket>)
else
{
$response .= $_;
}
close($socket);

if (!$response)
{
my $reason = "No output from remote host";
my $reason = "Unknown response";
return return_error($reason);
}
}

$socket = $self->create_socket();
if (ref $socket eq "REF")
{
return ($socket);
}
$packet = Nagios::NRPE::Packet->new();
$response = undef;
$assembled = $packet->assemble(
type => NRPE_PACKET_QUERY,
check => $check,
version => NRPE_PACKET_VERSION_2
);

print $socket $assembled;
while (<$socket>)
{
$response .= $_;
}
close($socket);

if (!$response)
{
my $reason = "No output from remote host";
return return_error($reason);
}
return $packet->disassemble($response);
}

Expand Down

0 comments on commit 1546e65

Please sign in to comment.