NAME
Nagios::NRPE::Packet - Assembly and de-assembly 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_2
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 => QUERY_PACKET,
buffer => "check_load 1 2 3",
version => NRPE_PACKET_VERSION_2 );
my $data = <$socket>
my $response = $packet->deassemble($data);
print $response->{buffer};
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
FUNCTIONS
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 (currently only V2 is accepted).
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 a curios value as it seems to have no apparent affect on neither the server nor the client.
A set value is 2324.
deassemble
Takes a packet recieved by either client or server and deassembles them. The returned hashref contains the following values:
packet_type
crc32_value result_code buffer
validate($packet)
Validates the contents of a packet using CRC32 checksumming. Returns undef if not succesful.
CONSTANTS
These constants can be exported upon request with the 'use' pragma like this:
# Will only import the constant NRPE_PACKET_VERSION_2 into your namespace
use Nagios::NRPE::Packet qw(NRPE_PACKET_VERSION_2);
=over 2
NRPE_PACKET_VERSION_3 NRPE_PACKET_VERSION_2 NRPE_PACKET_VERSION_1
The value of the NRPE version you want/need to use.
QUERY_PACKET RESPONSE_PACKET
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
- crc32
-
Checksumming for the packet. Necessary for sending a valid Packet.
- packet_dump
-
Debugging function for hexdumping a binary string.
4 POD Errors
The following errors were encountered while parsing the POD:
- Around line 50:
You forgot a '=back' before '=head1'
- Around line 89:
Expected '=item *'
- Around line 110:
'=item' outside of any '=over'
- Around line 261:
'=item' outside of any '=over'
=over without closing =back