-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSPS_Check_Temp.pl
executable file
·121 lines (98 loc) · 2.82 KB
/
SPS_Check_Temp.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
#! /usr/bin/perl
use strict;
use Monitoring::Plugin;
use WWW::Mechanize;
use File::Basename;
use Data::Dumper;
use constant VERSION => "0.1.0";
use constant URL => "http://jcmbsoft.dyndns.info";
use constant BLURB => "NAGIOS Plug in for montitoring Trimble SPS receivers, will with any modern high precision GNSS receiver with web interface 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] [ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ] ",
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 => 'User|U=s',
help => [
"User name and password, if security is enabled. Format user:password"
],
label => [ 'User_Password'],
required => 0
);
$np->add_arg(
spec => 'warning|w=s',
default => '-10:50',
help => '-w, --warning=INTEGER:INTEGER . See '
. 'http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT '
. 'for the threshold format. ',
);
$np->add_arg(
spec => 'critical|c=s',
default => '-30:60',
help => '-c, --critical=INTEGER:INTEGER . See '
. 'http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT '
. 'for the threshold format. ',
);
$np->getopts;
my $opts=$np->opts;
my $host=$opts->hostname();
my $user=$opts->User();
if ($user) {
$host=$user."@".$host;
}
my $verbose=$opts->verbose();
#print $verbose;
#my $xs = XML::Simple->new();
#print "hello";
#print "there";
#exit;
my $got_opt=1;
my $code;
my $message;
my $warning_threshold = $opts->warning();
my $critical_threshold= $opts->critical();
#print "$warning_threshold\n";
my $mech = WWW::Mechanize->new(autocheck=>0, timeout=>$np->opts->timeout());
$mech->get("http://$host/prog/show?Temperature");
my $temp=-99;
my @fields = split(/\n/,$mech->content);
#print Dumper(@fields);
if (@fields[0] =~ /^Temperature temp=(.*)$/) {
# print "@fields[0] *$1*\n";
$temp=$1;
}
else
{
$np->nagios_exit(UNKNOWN, 'Invalid Temperature Reply.');
}
#print $expected_pos."\n";
#print $opts->Pos()."\n";
print "Host: $host\n" if $verbose>1;
$code = $np->check_threshold(
check => $temp,
warning => $warning_threshold,
critical => $critical_threshold,
);
$np->nagios_exit($code, "Temperature is $temp");