-
Notifications
You must be signed in to change notification settings - Fork 8
/
check_docsis
executable file
·316 lines (298 loc) · 8.41 KB
/
check_docsis
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/usr/bin/env php
<?php
/*
* check_docsis v1.0
* Nagios plugin to check the status of a DOCSIS-compliant Cable Modem
* Copyright 2009-2010 Jason Antman <http://www.jasonantman.com> <jason@jasonantman.com>
*
* The authoritative version of this script lives at:
* <https://github.com/jantman/nagios-scripts>
*
* Please submit bug/feature requests or questions using
* the issue tracker there. Feedback, and patches (preferred
* as a GitHub pull request, but emailed diffs are also
* accepted) are strongly encouraged.
*
* Licensed under GNU GPLv3 - see the LICENSE file in the git repository.
*
* CHANGELOG:
*
* 2010-03-10 jantman <jason@jasonantman.com>:
* - initial import into SVN repository
*
*/
// TESTED ON:
// Motorola SBV5120 - .1.3.6.1.2.1.1.1.0 = STRING: <<HW_REV: 1.0; VENDOR: Motorola Corporation; BOOTR: 8.2; SW_REV: SBV5120-17.5.4-SCM-01-SHPC; MODEL: SBV5120>>
// Arris CM900A - .1.3.6.1.2.1.1.1.0 ARRIS DOCSIS 3.0 / Touchstone Cable Modem <<HW_REV: 2; VENDOR: Arris Interactive, L.L.C.; BOOTR: 2.3.1; SW_REV: 7.10.120; MODEL: CM900A>>
// Arris CM820A - .1.3.6.1.2.1.1.1.0 ARRIS DOCSIS 3.0 Touchstone WideBand Cable Modem <<HW_REV: 1; VENDOR: Arris Interactive, L.L.C.; BOOTR: 1.2.1.62; SW_REV: 7.5.93; MODEL: CM820A>>
require_once('jantman_docsis_OIDs.php.inc');
require_once('jantman_snmp.php.inc');
// if we didn't get any args, exit with unknown
if(sizeof($argv) < 2)
{
fwrite(STDOUT, "UNKNOWN: No arguments Specified!\n");
exit(3);
}
// if we were called with -h, print help and exit 0
if(in_array("-h", $argv))
{
showUsage();
exit(0);
}
// see if we want verbose or not
if(in_array("-v", $argv))
{
$verbose = true;
}
else
{
$verbose = false;
}
// find the host IP
if(in_array("-ip", $argv))
{
$idx = array_search("-ip", $argv);
$IP = $argv[$idx+1];
}
else
{
fwrite(STDOUT, "UNKNOWN: IP not specified.\n");
exit(3);
}
// community string, default to public
if(in_array("-comm", $argv))
{
$idx = array_search("-comm", $argv);
$community = $argv[$idx+1];
}
else
{
$community = "public";
}
// check type
if(in_array("-type", $argv))
{
$idx = array_search("-type", $argv);
$type = $argv[$idx+1];
}
else
{
fwrite(STDOUT, "UNKNOWN: Check type not specified.\n");
exit(3);
}
// CALL FUNCTION to get the ball rolling...
doCheck($IP, $community, $type, $verbose);
// handle the check
function doCheck($ip, $community, $type, $verbose)
{
global $docsisOIDs, $IfCmStatusValue;
// Downstream Power
if($type == "debugvals")
{
showOIDvalues($ip, $community);
exit(0);
}
if($type == "downpower")
{
$val = jantman_snmp1_get_numeric($ip, $community, $docsisOIDs['docsIfDownChannelPower']);
if($verbose){ fwrite(STDERR, "checking downpower...\n");}
$val = (float)($val / 10.0);
if($val >= -10 && $val <= 10)
{
fwrite(STDOUT, "OK: Downstream Power ".$val."dBmV (-10 <X<10)) | downPowerdBmV=".$val."\n");
exit(0);
}
elseif($val >= -12 && $val <= 12)
{
fwrite(STDOUT, "WARN: Downstream Power ".$val."dBmV (-12<X<12) | downPowerdBmV=".$val."\n");
exit(1);
}
else
{
fwrite(STDOUT, "CRIT: Downstream Power ".$val."dBmV (X> +/-12)| downPowerdBmV=".$val."\n");
exit(1);
}
}
// Upstream Power
elseif($type == "uppower")
{
$val = jantman_snmp1_get_numeric($ip, $community, $docsisOIDs['docsIfCmStatusTxPower']);
$val = (float)($val / 10.0);
if($val < 45)
{
fwrite(STDOUT, "OK: Upstream Power ".$val."dBmV (< 45)| upPowerdBmV=".$val."\n");
exit(0);
}
elseif($val < 55)
{
fwrite(STDOUT, "WARN: Upstream Power ".$val."dBmV (< 55) | upPowerdBmV=".$val."\n");
exit(1);
}
else
{
fwrite(STDOUT, "CRIT: Upstream Power ".$val."dBmV (>=55) | upPowerdBmV=".$val."\n");
exit(1);
}
}
// downstream SNR
elseif($type == "downsnr")
{
$val = jantman_snmp1_get_numeric($ip, $community, $docsisOIDs['docsIfSigQSignalNoise']);
$val = (float)($val / 10.0);
if($val >= 30)
{
fwrite(STDOUT, "OK: Downstream SNR ".$val."dBmV (>=30) | downSNRdBmV=".$val."\n");
exit(0);
}
elseif($val >= 25)
{
fwrite(STDOUT, "WARN: Downstream SNR ".$val."dBmV (>=25) | downSNRdBmV=".$val."\n");
exit(1);
}
else
{
fwrite(STDOUT, "CRIT: Downstream SNR ".$val."dBmV (<25) | downSNRdBmV=".$val."\n");
exit(1);
}
}
// microreflections
elseif($type == "microref")
{
$val = jantman_snmp1_get_numeric($ip, $community, $docsisOIDs['docsIfSigQMicroreflections']);
if($val <= 25)
{
fwrite(STDOUT, "OK: Microreflections ".$val."dBc (<=25) | downSNRdBc=".$val."\n");
exit(0);
}
elseif($val <= 35)
{
fwrite(STDOUT, "WARN: Microreflections ".$val."dBc (<=35) | downSNRdBc=".$val."\n");
exit(1);
}
else
{
fwrite(STDOUT, "CRIT: Microreflections ".$val."dBc (>35) | downSNRdBc=".$val."\n");
exit(2);
}
}
elseif($type == "downwidth")
{
$val = jantman_snmp1_get_numeric($ip, $community, $docsisOIDs['docsIfDownChannelWidth']);
$val = (float)($val/1000000.0);
if($val < 4.5)
{
fwrite(STDOUT, "CRIT: Downstream Channel Width ".$val."MHz (<4.5) | downChannelWidthMHz=".$val."\n");
exit(2);
}
elseif($val < 5.5)
{
fwrite(STDOUT, "WARN: Downstream Channel Width ".$val."MHz (<4.5) | downChannelWidthMHz=".$val."\n");
exit(1);
}
fwrite(STDOUT, "OK: Downstream Channel Width ".$val."MHz | downChannelWidthMHz=".$val."\n");
exit(0);
}
elseif($type == "upwidth")
{
$val = jantman_snmp1_get_numeric($ip, $community, $docsisOIDs['docsIfUpChannelWidth']);
$val = (float)($val/1000000.0);
if($val < 5)
{
fwrite(STDOUT, "CRIT: Upstream Channel Width ".$val."MHz (<4.5) | upChannelWidthMHz=".$val."\n");
exit(2);
}
elseif($val < 6)
{
fwrite(STDOUT, "WARN: Upstream Channel Width ".$val."MHz (<4.5) | upChannelWidthMHz=".$val."\n");
exit(1);
}
fwrite(STDOUT, "OK: Upstream Channel Width ".$val."MHz | upChannelWidthMHz=".$val."\n");
exit(0);
}
elseif($type == "status")
{
$val = jantman_snmp1_get_numeric($ip, $community, $docsisOIDs['docsIfCmStatusValue']);
if($val != 12)
{
fwrite(STDOUT, "CRIT: Modem Status: '".$IfCmStatusValue[$val]."' (".$val.")\n");
exit(2);
}
fwrite(STDOUT, "OK: Modem Status 'operational' (12)\n");
exit(0);
}
}
function showUsage()
{
fwrite(STDOUT, "check_docsis\n");
fwrite(STDOUT, "Nagios script to check status of a DOCSIS-compliant cable modem via SNMP.\n");
fwrite(STDOUT, "\n");
fwrite(STDOUT, "Usage: check_docsis [-hv] -ip <ip address> -type <check type> [-comm <community string>]\n");
fwrite(STDOUT, "\n");
fwrite(STDOUT, "[-h] show this summary\n");
fwrite(STDOUT, "[-v] verbose output\n");
fwrite(STDOUT, "-ip <ip addr> the IP/hostname of the modem to check\n");
fwrite(STDOUT, "[-comm <string>] the RO community string for SNMP (default: public)\n");
fwrite(STDOUT, "-type <check type> which value to check\n");
fwrite(STDOUT, "\tdownpower\tDownstream Power (OK within +/-10db, WARN at +/-12db, CRIT at +/-15db)\n");
fwrite(STDOUT, "\tuppower\t\tUpstream Power (OK < 45, WARN 45<=val<55, CRIT at 55)\n");
fwrite(STDOUT, "\tdownsnr\t\tDownstream SNR (OK >=30, WARN >=25, CRIT <25)\n");
fwrite(STDOUT, "\tmicroref\tMicroreflections (OK <=25, WARN <=35, CRIT >35)\n");
fwrite(STDOUT, "\tupwidth\t\tUpstream Channel Width (should be ~6.5MHz)\n");
fwrite(STDOUT, "\tdownwidth\tDownstream Channel Width (should be ~6MHz)\n");
fwrite(STDOUT, "\tdebugvals\tPrint out values for all OIDs used by the script.\n");
fwrite(STDOUT, "\tstatus\t\tCurrent cable modem status\n");
fwrite(STDOUT, "(all thresholds defaults are derived from the DOCSIS documentation\n");
fwrite(STDOUT, "\n");
}
function prettyAge($seconds)
{
$age = "";
if($seconds > 86400)
{
$days = (int)($seconds / 86400);
$seconds = $seconds - ($days * 86400);
$age .= $days."d";
}
if($seconds > 3600)
{
$hours = (int)($seconds / 3600);
$seconds = $seconds - ($hours * 3600);
$age .= $hours."h";
}
if($seconds > 60)
{
$minutes = (int)($seconds / 60);
$seconds = $seconds - ($minutes * 60);
$age .= $minutes."m";
}
return $age;
}
function prettySize($bytes)
{
$val = "";
$suffix = "";
if($bytes < 1024) // 1 kB
{
$val = $bytes;
$suffix = "b";
}
else if($bytes < 1048576) // 1 MB
{
$val = $bytes / 1024;
$suffix = "kB";
}
else if($bytes < 1073741824) // 1 GB
{
$val = $bytes / 1048576;
$suffix = "MB";
}
else
{
$val = $bytes / 1073741824;
$suffix = "GB";
}
// round to 2 decimal places
$val = round($val,2);
return $val.$suffix;
}
?>