-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSPS_Check_Port.pl
executable file
·286 lines (239 loc) · 7.21 KB
/
SPS_Check_Port.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#! /usr/bin/perl
use strict;
use warnings;
use Monitoring::Plugin;
use WWW::Mechanize;
use File::Basename;
use Data::Dumper;
use constant VERSION => "1.0.0";
use constant URL => "http://jcmbsoft.com";
use constant BLURB => "NAGIOS Plug in for montitoring Trimble SPS receivers, will with any modern high precision Trimble GNSS receiver with the programatic interface enabled";
use constant EXTRA => "Extra";
my $np = Monitoring::Plugin->new(
usage => "Usage: %s [ -v|--verbose ] [-P --Port=INTEGER the Port[ [-H <host>] [-t <timeout>] [-U|--User User:Pass] [-h|--Help]" .
"[--CMR:format] [--RTCM] [--NMEA:format,rate] ".
"[[-t|--TCP] [-u|--UDP] [-S|--Server] [-C|--Caster] [--outputOnly]] ".
"[[-s|--serial] [--Baud=baud] [--Flow=flow] [--Parity=parity]]",
version => VERSION,
blurb => BLURB,
extra => EXTRA,
url => URL,
plugin => basename $0,
timeout => 15,
);
if (open (PROXY, '<','usr/lib/nagios/plugins/proxy.perl')) {
if (defined (<PROXY>) and my $proxy = <PROXY>) {
chomp($proxy);
$np->mech->proxy(['http', 'ftp'], $proxy);
}
close PROXY;
}
$np->add_arg(
spec => 'hostname|H=s',
help => [
"Hostname to query",
"IP address to query",
],
label => [ 'HOSTNAME', 'IP' ],
required => 1,
);
$np->add_arg(
spec => 'User|U=s',
help => [
"User name and password, if security is enabled. Format user:password"
],
label => [ 'User_Password'],
required => 0
);
$np->add_arg(
spec => 'TCP|t',
help => 'If the port is a TCP port, the default',
);
$np->add_arg(
spec => 'UDP|u',
help => 'If the port is a UDP port',
);
$np->add_arg(
spec => 'Server|S',
help => 'If the port is a NTRIP Server',
);
$np->add_arg(
spec => 'Caster|C',
help => 'If the port is a NTRIP Caster',
);
$np->add_arg(
spec => 'Serial|s',
help => 'If the port is a Serial port',
);
$np->add_arg(
spec => 'Port|P=s',
help => '-P --Port=INTEGER Number of the Port, for example 2101',
required => 1
);
$np->add_arg(
spec => 'Baud=s',
help => 'Baud Rate of the Serial Port',
);
$np->add_arg(
spec => 'Parity=s',
help => 'Parity of the Serial Port',
);
$np->add_arg(
spec => 'Flow=s',
help => 'Flow Control of the Serial Port',
);
$np->add_arg(
spec => 'outputOnly',
help => 'If the port is output only, IP Streams only',
);
$np->add_arg(
spec => 'Input',
help => 'If the port is Input and Output, TCP or Input only UDP. IP Streams only',
);
$np->add_arg(
spec => 'remotePort:s',
help => 'If the port in client mode IP Streams only',
);
$np->add_arg(
spec => 'CMR:s',
help => 'If the stream has CMR enabled, optionally what type of CMR. '.
'Options are: standard cmrPlus cmrX cmr5Hz cmr10Hz cmr20Hz' ,
required => 0
);
$np->add_arg(
spec => 'RTCM',
help => 'If the stream has RTCM enabled ',
required => 0
);
$np->add_arg(
spec => 'NMEA:s',
help => 'If the stream has NMEA enabled. Optional Parameter is TYPE,Rate',
required => 0
);
$np->getopts;
my $opts=$np->opts;
my $host=$opts->hostname();
my $user=$opts->User();
if ($user) {
$host=$user."@".$host;
}
my $verbose=$opts->verbose();
my $port_type="Tcp";
$port_type="Udp" if $opts->UDP();
$port_type="NtripServer" if $opts->Server();
$port_type="NtripCaster" if $opts->Caster();
$port_type="Serial" if $opts->Serial();
my $Port="";
if ($opts->Server() or $opts->Caster()) {
$Port= $port_type.$opts->Port();
}
else
{
$Port= $port_type."Port".$opts->Port();
}
print "Port:$Port\n" if $opts->verbose();
my $code;
my $message;
my $mech = WWW::Mechanize->new(autocheck=>0, timeout=>$opts->timeout());
print "Host: $host\n" if $verbose>1;
my $result =$mech->get("http://$host/prog/show?IoPort&port=$Port");
my $Stream = $mech->content;
#print $Stream;
chomp($Stream);
if (!($Stream =~ /^IoPort/)) {
$np->nagios_exit(CRITICAL, "Invalid Port Number, or port not configured: $Port");
}
if ($port_type eq "Serial") {
if ($opts->Flow()) {
print "Checking Flow Control\n" if $opts->verbose();
my $flow_setting=$opts->Flow();
if (!($Stream =~ /flow=$flow_setting/)) {
($Stream =~ /flow=(\w*)/);
$np->add_message('CRITICAL',"Flow Control is $1 not " . $flow_setting);
}
}
if ($opts->Baud()) {
print "Checking Baud Control\n" if $opts->verbose();
my $Baud_setting=$opts->Baud();
if (!($Stream =~ /baud=$Baud_setting/)) {
($Stream =~ /baud=(\w*)/);
$np->add_message('CRITICAL',"Baud rate is $1 not " . $Baud_setting);
}
}
if ($opts->Parity()) {
print "Checking Parity \n" if $opts->verbose();
my $Parity_setting=$opts->Parity();
if (!($Stream =~ /parity=$Parity_setting/)) {
($Stream =~ /parity=(\w*)/);
$np->add_message('CRITICAL',"Parity is $1 not " . $Parity_setting);
}
}
}
if ($port_type eq "Tcp" || $port_type eq "Udp") {
if ($opts->outputOnly()) {
print "Checking outputOnly \n" if $opts->verbose();
if (!($Stream =~ /outputOnly/)) {
$np->add_message('CRITICAL',"Stream is not outputOnly");
}
}
if (defined ($opts->remotePort())) {
print "Checking remotePort \n" if $opts->verbose();
if (!($Stream =~ /remotePort=/)) {
$np->add_message('CRITICAL',"Stream is not in remotePort mode");
}
else {
if ($opts->remotePort()) {
my $remote=$opts->remotePort();
if (!($Stream =~ /remotePort=$remote/)) {
($Stream =~ /remotePort=([\.\:\w]*)/);
$np->add_message('CRITICAL',"Stream is not remotePort to $remote, it is to $1");
}
}
}
}
}
if ($opts->RTCM()) {
print "Checking RTCM\n" if $opts->verbose();
if (!($Stream =~ /rtcm/)) {
$np->add_message('CRITICAL',"Stream is not RTCM");
}
}
if (defined ($opts->CMR())) {
print "Checking CMR\n" if $opts->verbose();
if (!($Stream =~ /Cmr=/)) {
$np->add_message('CRITICAL',"Stream is not CMR");
}
else {
if ($opts->CMR()) {
my $CMR=$opts->CMR();
if (!($Stream =~ /Cmr=$CMR/i)) {
($Stream =~ /Cmr=(\w*)/);
$np->add_message('CRITICAL',"Stream is not Cmr format $CMR it is $1");
}
}
}
}
if (defined ($opts->NMEA())) {
print "Checking NMEA\n" if $opts->verbose();
if (!($Stream =~ /Nmea\w*=/)) {
$np->add_message('CRITICAL',"Stream is not Nmea");
}
else {
if ($opts->NMEA()) {
my @NMEA=split(/,/,$opts->NMEA());
$NMEA[1]="" unless defined $NMEA[1];
if (!($Stream =~ /Nmea$NMEA[0]=/i)) {
$np->add_message('CRITICAL',"Stream is not NMEA format $NMEA[0]");
}
else
{
if (!($Stream =~ /Nmea$NMEA[0]=$NMEA[1]/)) {
($Stream =~ /Nmea$NMEA[0]=(\w*)/);
$np->add_message('CRITICAL',"Stream is not NMEA format $NMEA[0] at $NMEA[1] it is at $1");
}
}
}
}
}
($code,$message) = $np->check_messages;
$np->nagios_exit($code, $message);