From a620bba59fa086c6662391b6c029ce92f602cb3f Mon Sep 17 00:00:00 2001 From: Johan Wassberg Date: Fri, 23 Nov 2018 10:51:23 +0100 Subject: [PATCH] Handle servers that responds with a v2 packet to a v3 request. Hi NSClient++! --- lib/Nagios/NRPE/Client.pm | 56 ++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/lib/Nagios/NRPE/Client.pm b/lib/Nagios/NRPE/Client.pm index b23a5cd..ce33a22 100644 --- a/lib/Nagios/NRPE/Client.pm +++ b/lib/Nagios/NRPE/Client.pm @@ -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); }