Nagios-NRPE
view release on metacpan or search on metacpan
lib/Nagios/NRPE/Client.pm view on Meta::CPAN
=back
=cut
sub new
{
my ($class, %hash) = @_;
my $self = {};
$self->{arglist} = delete $hash{arglist} || [];
$self->{bindaddr} = delete $hash{bindaddr} || 0;
$self->{check} = delete $hash{check} || "";
$self->{host} = delete $hash{host} || "localhost";
$self->{ipv4} = delete $hash{ipv4} || 0;
$self->{ipv6} = delete $hash{ipv6} || 0;
$self->{port} = delete $hash{port} || 5666;
$self->{ssl} = delete $hash{ssl} || 0;
$self->{timeout} = delete $hash{timeout} || 30;
bless $self, $class;
}
=pod
=over 2
=item create_socket()
Helper function that can create either an INET socket or a SSL socket
=back
=cut
sub create_socket
{
my ($self) = @_;
my $reason;
my $socket;
my %socket_opts = (
# where to connect
PeerHost => $self->{host},
PeerPort => $self->{port},
Timeout => $self->{timeout}
);
if ($self->{bindaddr})
{
$socket_opts{LocalAddr} = $self->{bindaddr};
}
if ($self->{ipv4})
{
$socket_opts{Domain} = AF_INET;
}
if ($self->{ipv6})
{
$socket_opts{Domain} = AF_INET6;
}
if ($self->{ssl})
{
eval {
# required for new IO::Socket::SSL versions
use IO::Socket::SSL;
};
$socket_opts{SSL_cipher_list} = $self->{SSL_cipher_list}
|| 'ALL:!MD5:@STRENGTH:@SECLEVEL=0';
$socket_opts{SSL_verify_mode} = SSL_VERIFY_NONE;
$socket_opts{SSL_version} = 'TLSv1';
$socket = IO::Socket::SSL->new(%socket_opts);
if ($SSL_ERROR)
{
$reason = "$!,$SSL_ERROR";
return return_error($reason);
}
}
else
{
$socket_opts{Proto} = 'tcp';
$socket_opts{Type} = SOCK_STREAM;
$socket = IO::Socket::INET6->new(%socket_opts);
$reason = $@;
}
if (!$socket)
{
return return_error($reason);
}
return $socket;
}
=pod
=over 2
=item run()
Runs the communication to the server and returns a hash of the form:
my $response = $client->run();
The output should be a hashref of this form for NRPE V3:
{
version => NRPE_VERSION,
type => RESPONSE_TYPE,
crc32 => CRC32_CHECKSUM,
code => RESPONSE_CODE,
alignment => PACKET_ALIGNMENT,
buffer_length => OUTPUT_LENGTH,
buffer => CHECK_OUTPUT
}
and this for for NRPE V2:
{
version => NRPE_VERSION,
type => RESPONSE_TYPE,
crc32 => CRC32_CHECKSUM,
code => RESPONSE_CODE,
buffer => CHECK_OUTPUT
}
=back
=cut
( run in 1.537 second using v1.01-cache-2.11-cpan-99c4e6809bf )