| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Nagios::NRPE - A Nagios NRPE implementation in pure perl | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | # Executing a check on an NRPE-Server | ||
| 8 | use Nagios::NRPE::Client; | ||
| 9 | |||
| 10 | my $client = Nagios::NRPE::Client->new( host => "localhost", check => 'check_cpu'); | ||
| 11 | my $response = $client->run(); | ||
| 12 | if(defined $response->{error}) { | ||
| 13 | print "ERROR: Couldn't run check ".$client->check()." because of: ".$response->{reason}."\n"; | ||
| 14 | } else { | ||
| 15 | print $response->{status}."\n"; | ||
| 16 | } | ||
| 17 | |||
| 18 | # Reading and Writing Nagios NRPE Packets | ||
| 19 | |||
| 20 | use IO::Socket; | ||
| 21 | use IO::Socket::INET; | ||
| 22 | # Import necessary constants into Namespace | ||
| 23 | use Nagios::NRPE::Packet qw(NRPE_PACKET_VERSION_3 | ||
| 24 | NRPE_PACKET_QUERY | ||
| 25 | STATE_UNKNOWN | ||
| 26 | STATE_CRITICAL | ||
| 27 | STATE_WARNING | ||
| 28 | STATE_OK); | ||
| 29 | |||
| 30 | my $packet = Nagios::NRPE::Packet->new(); | ||
| 31 | |||
| 32 | my $socket = IO::Socket::INET->new( | ||
| 33 | PeerAddr => $host, | ||
| 34 | PeerPort => $port, | ||
| 35 | Proto => 'tcp', | ||
| 36 | Type => SOCK_STREAM) or die "ERROR: $@ \n"; | ||
| 37 | |||
| 38 | print $socket $packet->assemble(type => NRPE_PACKET_QUERY, | ||
| 39 | buffer => "check_load 1 2 3", | ||
| 40 | version => NRPE_PACKET_VERSION_3 ); | ||
| 41 | |||
| 42 | my $data = <$socket>; | ||
| 43 | my $response = $packet->disassemble($data); | ||
| 44 | |||
| 45 | print $response->{buffer}; | ||
| 46 | |||
| 47 | =head1 DESCRIPTION | ||
| 48 | |||
| 49 | This file currently only serves as a stub so Build.PL will find it. For more information on | ||
| 50 | the submodules please read L<Nagios::NRPE::Client> or L<Nagios::NRPE::Packet> or L<Nagios::NRPE::Daemon>. | ||
| 51 | |||
| 52 | =head1 COPYRIGHT AND LICENSE | ||
| 53 | |||
| 54 | This software is copyright (c) 2013-2018 by the authors (see L<AUTHORS|https://github.com/stockholmuniversity/Nagios-NRPE/blob/master/AUTHORS> file). | ||
| 55 | |||
| 56 | This is free software; you can redistribute it and/or modify it under | ||
| 57 | the same terms as the Perl 5 programming language system itself. | ||
| 58 | |||
| 59 | =cut | ||
| 60 | |||
| 61 | package Nagios::NRPE; | ||
| 62 | |||
| 63 | use strict; | ||
| 64 | use warnings; | ||
| 65 | |||
| 66 | our $VERSION = '2.0.13'; | ||
| 67 | |||
| 68 | 1; |