This repository was archived by the owner on May 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck_sms3status.pl
More file actions
executable file
·205 lines (133 loc) · 4.9 KB
/
Copy pathcheck_sms3status.pl
File metadata and controls
executable file
·205 lines (133 loc) · 4.9 KB
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
#!/usr/bin/perl -w
=pod
=head1 COPYRIGHT
This software is Copyright (c) 2007 NETWAYS GmbH, William Preston
<support@netways.de>
(Except where explicitly superseded by other copyright notices)
=head1 LICENSE
This work is made available to you under the terms of Version 2 of
the GNU General Public License. A copy of that license should have
been provided with this software, but in any event can be snarfed
from http://www.fsf.org.
This work is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 or visit their web page on the internet at
http://www.fsf.org.
CONTRIBUTION SUBMISSION POLICY:
(The following paragraph is not intended to limit the rights granted
to you to modify and distribute this software under the terms of
the GNU General Public License and is only of importance to you if
you choose to contribute your changes and enhancements to the
community by submitting them to NETWAYS GmbH.)
By intentionally submitting any modifications, corrections or
derivatives to this work, or any other work intended for use with
this Software, to NETWAYS GmbH, you confirm that
you are the copyright holder for those contributions and you grant
NETWAYS GmbH a nonexclusive, worldwide, irrevocable,
royalty-free, perpetual, license to use, copy, create derivative
works based on those contributions, and sublicense and distribute
those contributions and any derivatives thereof.
Nagios and the Nagios logo are registered trademarks of Ethan Galstad.
=head1 NAME
check_sms3status
=head1 SYNOPSIS
Retrieves the status of an SMS Modem via smstools3.
=head1 OPTIONS
check_sms3status [options] F<status_file>
=over
=item B<--warning>
warning level for percentage signal strength (default 40)
=item B<--critical>
critical level for percentage signal strength (default 20)
=item B<--timeout>
how long to wait for the file (default 30)
=item B<--age>
the maximum age of the file in seconds (default 300)
=back
=head1 DESCRIPTION
This plugin checks the status of an SMS modem using the regular_run functionality
provided in smstools3
It does not directly access the modem, but instead reads a status file generated
by smstools3.
In order to work the following options need to be set in smsd.conf
=over
=item
regular_run_interval = 60
=item
regular_run_cmd = AT+CREG?;+CSQ;+COPS?
=item
regular_run_statfile = F<status_file>
=back
The following performance data is returned
<signal dBm>;<% signal strength>;<Error rate>;<Network ID/Name>
=head1 FILES
F<status_file> the status file e.g. /dev/shm/sms_stat
=head1 HISTORY
16.11.2009 Perfdata Patch contributed by Gerd v. Egidy
=cut
use Getopt::Long;
use Pod::Usage;
use lib '/usr/local/nagios/libexec/';
use lib '/usr/lib/nagios/plugins/';
use utils qw(%ERRORS);
sub nagexit($$);
$warning = 40;
$critical = 20;
$tout = 30;
$maxage = 300;
# check the command line options
GetOptions('help|?' => \$help,
'age=i' => \$maxage,
't|timeout=i' => \$tout,
'w|warn|warning=i' => \$warning,
'c|crit|critical=i' => \$critical);
if ($#ARGV!=0) {$help=1;} # wrong number of command line options
# pod2usage( -verbose => 99, -sections => "NAME|COPYRIGHT|SYNOPSIS|OPTIONS") if $help;
pod2usage(1) if $help;
$file = shift;
while ($tout > 0) {
open (IN,"<".$file) and last;
sleep 1;
$tout -= 1 or nagexit('CRITICAL', "Cannot open $file");
}
$fileage = (stat(IN))[9];
$fileage_sec = (time() - $fileage);
if ($fileage_sec > $maxage) {
nagexit('CRITICAL', "Status file was last updated $fileage_sec seconds ago");
}
while (<IN>) {
if (/\+CSQ:\s*(\d+),(\d+)/) { $signal = $1; $sigber = $2 };
if (/\+COPS:\s*\d+,\d+,\"(.*)\"/) { $netz = $1 }
elsif (/\+COPS:\s*\d+,\d+,([^ ]*)/) { $netz = $1 };
if (!/\+CREG:\s*(\d,(1|5))/) { $unreg = TRUE };
$sigdb = ((2*$signal)-113);
$sigproc = (($signal*100)/31);
}
close (IN);
$unreg and nagexit('CRITICAL', "Modem not registered on network");
if ($signal > 31) {
nagexit('UNKNOWN', "Signal strength returned an invalid value");
}
$retstr = sprintf ("Registered on network '%5\$s' with signal strength %2\$.0f%% | dBm=%1\$d;;;; signal=%2\$.0f%%;%3\$.0f;%4\$.0f;;", $sigdb, $sigproc, $warning, $critical, $netz);
# bit error rate 99 means unknown, don't output it
if ($sigber != 99) {
$retstr = sprintf ("%1\$s bit_error_rate=%2\$d;;;;", $retstr, $sigber);
}
if ($sigproc < $critical) {
nagexit('CRITICAL', $retstr);
}
if ($sigproc < $warning) {
nagexit('WARNING', $retstr);
}
nagexit('OK', $retstr);
sub nagexit($$) {
my $errlevel = shift;
my $string = shift;
print "$errlevel: $string\n";
exit $ERRORS{$errlevel};
}