NAME

Nagios::NRPE::Packet - Assembly and disassembly of an NRPE packet

SYNOPSIS

use IO::Socket;
use IO::Socket::INET;
# Import necessary constants into Namespace
use Nagios::NRPE::Packet qw(NRPE_PACKET_VERSION_3
                            NRPE_PACKET_QUERY
                            MAX_PACKETBUFFER_LENGTH
                            STATE_UNKNOWN
                            STATE_CRITICAL
                            STATE_WARNING
                            STATE_OK);

my $packet = Nagios::NRPE::Packet->new();

my $socket = IO::Socket::INET->new(
                   PeerAddr => $host,
                   PeerPort => $port,
                   Proto    => 'tcp',
                   Type     => SOCK_STREAM) or die "ERROR: $@ \n";

print $socket $packet->assemble(type => NRPE_PACKET_QUERY,
                             buffer => "check_load 1 2 3",
                             version => NRPE_PACKET_VERSION_3 );

my $data = <$socket>;
my $response = $packet->disassemble($data);

print $response->{buffer};
exit $response->{result_code};

DESCRIPTION

This class is meant to be used when an active connection exists and is ready to send the packet.

CONSTRUCTION

new

Takes the following options as a hashref

SUBROUTINES

Following functions can be used after the creation of the packet

assemble()

Takes a hash of options defining the packet to be sent and returns the assembled packet. You can print this to an open socket and send it to either a server or the client depending on your situation.

* check

A string defining the check to be run or the output of a check eg: "check_cpu" NOTE: Nagios can accept arguments appended to the check in the form: "check_somecheck!ARG1!ARG2!ARG..."

* version

The NRPE version you want to use (only V2 and V3 work V1 is not supported, deafult is V3).

See CONSTANTS for options here.

* type

The TYPE of packet you wish to send, which is either QUERY or RESPONSE.

See "CONSTANTS" for options here.

* result_code

This is the exit code of the check script that is run, and check_nrpe.pl will exit with this value from the RESPONSE packet.

A set value for the QUERY type packet is 2324.

assemble_v2()

A helper function to assemble a V2 packet.

assemble_v3()

A helper function to assemble a V3 packet.

disassemble()

Takes a packet recieved by either client or server and disassembles them. The returned hashref contains the following values for a V3 packet:

packet_version 
packet_type    
crc32_value    
result_code    
alignment      
buffer_length  
buffer

and the following values for a V2 packet:

packet_version 
packet_type    
crc32_value    
result_code    
buffer
disassemble_v2()

Helper function for disassembleing a V2 packet

disassemble_v3()

Helper function for disassembleing a V3 packet

validate($packet)

Validates the contents of a packet using CRC32 checksumming. Returns undef if not succesful.

packet_dump

Debugging function for hexdumping a binary string.

CONSTANTS

These constants can be exported upon request with the 'use' pragma like this:

# Will only import the constant NRPE_PACKET_VERSION_3 into your namespace
use Nagios::NRPE::Packet qw(NRPE_PACKET_VERSION_3);
  • NRPE_PACKET_VERSION_3 NRPE_PACKET_VERSION_2 NRPE_PACKET_VERSION_1

    The value of the NRPE version you want/need to use.

  • NRPE_PACKET_QUERY NRPE_PACKET_RESPONSE

    The packet type you want to send or recieve

  • MAX_PACKETBUFFER_LENGTH MAX_COMMAND_ARGUMENTS

    A threshhold on the send data

  • NRPE_HELLO_COMMAND

    unknown

  • DEFAULT_SOCKET_TIMEOUT DEFAULT_CONNECTION_TIMEOUT

    The default timeout for a connection and its corresponding socket

  • STATE_UNKNOWN STATE_CRITICAL STATE_WARNING STATE_OK

    States returned by the check

COPYRIGHT AND LICENSE

This software is copyright (c) 2013-2018 by the authors (see AUTHORS file).

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.