script/check_nrpe.pl untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 79 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 =head1 NAME
4  
5 check_nrpe.pl - An implemetation of the check_nrpe command in pure perl
6  
7 =head1 SYNOPSIS
8  
9 Usage: check_nrpe -H <host> -c <command> [ -b <bindaddr> ] [-4] [-6] [-n] [-u] [-p <port>] [-t <timeout>] [-a <arglist...>]
10  
11 Options:
12 -4 = use ipv4 only
13 -6 = use ipv6 only
14 -H <host> = The address of the host running the NRPE daemon
15 -b <bindaddr> = bind to local address
16 -c command = The name of the command that the remote daemon should run
17 -n = Do no use SSL
18 -p [port] = The port on which the daemon is running (default=5666)
19 -t [timeout] = Number of seconds before connection times out (default=10)
20 -u = Make socket timeouts return an UNKNOWN state instead of CRITICAL
21 -a [arglist] = Optional arguments that should be passed to the command. Multiple
22 arguments should be separated by a space. If provided, this must be
23 the last option supplied on the command line.
24  
25 =head1 DESCRIPTION
26  
27 Using this script you can request the current status of checks on your remote hosts
28  
29 It takes the following options
30  
31 =head2 -4
32  
33 Use ipv4 only
34  
35 =head2 -6
36  
37 Use ipv6 only
38  
39 =head2 -H -host <some host>
40  
41 The remote host running NRPE-Server (default localhost)
42  
43 =head2 -b --bindaddr <some local address>
44  
45 Bind to this local address
46  
47 =head2 -p --port <some port>
48  
49 The remote port on which the NRPE-server listens
50  
51 =head2 -n --nossl
52  
53 Don't use SSL
54  
55 =head2 -c --command <some command> (--check is deprecated)
56  
57 The check command defined in the nrpe.cfg file you would like to trigger
58  
59 =head2 -h --help
60  
61 This help.
62  
63 =head1 COPYRIGHT AND LICENSE
64  
65 This software is copyright (c) 2013-2018 by the authors (see AUTHORS file).
66  
67 This is free software; you can redistribute it and/or modify it under
68 the same terms as the Perl 5 programming language system itself.
69  
70 =cut
71  
72 use 5.010_000;
73  
74 use strict;
75 use warnings;
76  
77 use Getopt::Long;
78 use Pod::Usage;
79 use Data::Dumper;
80 use Nagios::NRPE::Client;
81  
82 our $VERSION = '2.0.13';
83  
84 my (
85 $arglist, $bindaddr, $check, $host, $ipv4, $cipherlist,
86 $ipv6, $port, $ssl, $timeout, $unknown
87 );
88  
89 Getopt::Long::Configure('no_ignore_case');
90 my $result = GetOptions(
91 "4" => \$ipv4,
92 "6" => \$ipv6,
93 "H|host=s" => \$host,
94 "a|arglist" => \$arglist,
95 "b|bindadr=s" => \$bindaddr,
96 "c|command|check=s" => \$check,
97 "n|nossl" => \$ssl,
98 "L|cipher-list=s" => \$cipherlist,
99 "p|port=s" => \$port,
100 "t|timeout=i" => \$timeout,
101 "u|unknown" => \$unknown,
102 "h|help" => sub {
103 pod2usage(
104 -exitval => 0,
105 -verbose => 99,
106 -noperldoc => 1
107 );
108 }
109 );
110  
111 if ($ssl)
112 {
113 $ssl = 0;
114 }
115 else
116 {
117 $ssl = 1;
118 }
119 $bindaddr = 0 unless defined $bindaddr;
120 $cipherlist = 'ALL:!MD5:@STRENGTH:@SECLEVEL=0' unless defined $bindaddr;
121 $ipv4 = 0 unless defined $ipv4;
122 $ipv6 = 0 unless defined $ipv6;
123 $unknown = 0 unless defined $unknown;
124 $host = "localhost" unless defined $host;
125 $port = 5666 unless defined $port;
126 $timeout = 20 unless defined $timeout;
127  
128 die "Error: No check was given" unless defined $check;
129 my $client = Nagios::NRPE::Client->new(
130 arglist => \@ARGV,
131 bindaddr => $bindaddr,
132 check => $check,
133 host => $host,
134 ipv4 => $ipv4,
135 ipv6 => $ipv6,
136 port => $port,
137 ssl => $ssl,
138 SSL_cipher_list => $cipherlist,
139 timeout => $timeout,
140 unknown => $unknown
141 );
142 my $response = $client->run();
143  
144 if ($response->{error})
145 {
146 if ($unknown)
147 {
148 print "Socket error: $response->{reason}\n";
149 exit 3;
150 }
151 print "Socket error: $response->{reason}\n";
152 exit 2;
153 }
154 print $response->{buffer} . "\n";
155 exit $response->{result_code};