-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSPS_Check_Auth.pl
executable file
·124 lines (101 loc) · 2.77 KB
/
SPS_Check_Auth.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
#! /usr/bin/perl
use strict;
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 work with any modern Trimble high precision GNSS receiver with the programatic interface enabled";
use constant EXTRA => "Extra";
my $np = Monitoring::Plugin->new(
usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] [-h Help] [-A|--auth yes|anonymous|no] ",
version => VERSION,
blurb => BLURB,
extra => EXTRA,
url => URL,
plugin => basename $0,
timeout => 15,
);
if (open (PROXY, '/usr/lib/nagios/plugins/proxy.perl')) {
if (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 => 'Auth|A=s',
help => [
"Authorization",
"Expected Authorization",
],
label => [ 'Authorization', 'Auth' ],
required => 1,
);
$np->getopts;
my $opts=$np->opts;
my $host=$opts->hostname();
my $auth=$opts->Auth();
my $verbose=$opts->verbose();
my $got_opt=1;
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?PdopMask");
#print "After Get\n";
#print $result->code."\n";
if ($result->code == 403) {
$np->nagios_exit(UNKNOWN, 'Error Connecting to Server');
}
if ($result->code == 401) {
if ($auth eq "yes") {
$np->nagios_exit(OK, 'AUTHORIZATION is set as expected');
}
else {
$np->nagios_exit(CRITICAL, 'AUTHORIZATION is required but should not be');
}
}
my $PDOP=-99;
my @fields = split(/\n/,$mech->content);
if (@fields[0] =~ /^PdopMask mask=(.*)$/) {
# print "@fields[0] *$1*\n";
$PDOP=$1;
# print $PDOP;
}
else
{
$np->nagios_exit(UNKNOWN, 'Invalid PDOP Reply.');
}
$result=$mech->get("http://$host/prog/set?PdopMask&mask=$PDOP");
my @fields = split(/\n/,$mech->content);
#print Dumper(@fields);
if (@fields[0] =~ /^ERROR/)
{
if ($auth eq "anonymous") {
$np->nagios_exit(OK, 'AUTHORIZATION is anonymous as expected');
}
else {
$np->nagios_exit(CRITICAL, "AUTHORIZATION is anonymous but should be $auth");
}
}
else
{
if ($auth eq "no") {
$np->nagios_exit(OK, 'AUTHORIZATION is none as expected');
}
else {
$np->nagios_exit(CRITICAL, "AUTHORIZATION is none should be $auth");
}
}
$np->nagios_exit(UNKNOWN, "Internal Error");