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