forked from jantman/nagios-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_802dot11.php
executable file
·291 lines (272 loc) · 6.38 KB
/
check_802dot11.php
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
#!/usr/bin/env php
<?php
/*
* check_802dot11.php v1.0
* Nagios check plugin to check IEEE802DOT11-MIB
* Copyright 2009-2010 Jason Antman <http://www.jasonantman.com> <[email protected]>
*
* 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 <[email protected]>:
* - initial import into SVN repository
*
*/
require_once('jantman_802dot11_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";
}
// value
if(in_array("-val", $argv))
{
$idx = array_search("-val", $argv);
$argVal = $argv[$idx+1];
}
// last OID octet
if(in_array("-lastOID", $argv))
{
$idx = array_search("-lastOID", $argv);
$lastOID = $argv[$idx+1];
}
else
{
fwrite(STDOUT, "UNKNOWN: lastOID not specified.\n");
exit(3);
}
// 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 $ieee802dot11OIDs, $argVal, $lastOID;
if($type == "privacy")
{
$val = jantman_snmp1_get_numeric($ip, $community, $ieee802dot11OIDs['dot11PrivacyOptionImplemented'].$lastOID);
if($val == 1)
{
fwrite(STDOUT, "OK: 802.11 Privacy Option Implemented.\n");
exit(0);
}
else
{
fwrite(STDOUT, "CRIT: 802.11 Privacy Option NOT Implemented.\n");
exit(2);
}
}
elseif($type == "ssid")
{
checkargval('ssid');
$val = jantman_snmp1_get_string($ip, $community, $ieee802dot11OIDs['dot11DesiredSSID'].$lastOID);
if(trim($val) == trim($argVal))
{
echo "OK: SSID is '$val'\n";
exit(0);
}
else
{
echo "CRIT: Expected SSID of '$argVal', found '$val'\n";
exit(2);
}
}
elseif($type == "bsstype")
{
$val = jantman_snmp1_get_numeric($ip, $community, $ieee802dot11OIDs['dot11DesiredBSSType'].$lastOID);
if($val == 1)
{
fwrite(STDOUT, "OK: BSS Type 'Infrastructure'.\n");
exit(0);
}
elseif($val == 2)
{
fwrite(STDOUT, "CRIT: Found 'Independent', expected 'Infrastructure'.\n");
exit(2);
}
elseif($val == 3)
{
fwrite(STDOUT, "CRIT: Found 'Any', expected 'Infrastructure'.\n");
exit(2);
}
else
{
fwrite(STDOUT, "UNKNOWN: Unknown BSS Type found.\n");
exit(2);
}
}
elseif($type == "mfrver")
{
checkargval('mfrver');
$val = jantman_snmp1_get_string($ip, $community, $ieee802dot11OIDs['dot11manufacturerProductVersion'].$lastOID);
if(trim($val) == trim($argVal))
{
echo "OK: Manufacturer Version is '$val'\n";
exit(0);
}
else
{
echo "CRIT: Expected '$argVal', found '$val'\n";
exit(2);
}
}
elseif($type == "chan")
{
checkargval('chan');
$val = jantman_snmp1_get_numeric($ip, $community, $ieee802dot11OIDs['dot11CurrentChannel'].$lastOID);
$argVal = (int)$argVal;
if($val == $argVal)
{
echo "OK: Channel $val\n";
exit(0);
}
else
{
echo "CRIT: Expected channel $argVal, found $val\n";
exit(2);
}
}
else
{
fwrite(STDOUT, "UNKNOWN: Unknown check type\n");
exit(3);
}
}
function showUsage()
{
fwrite(STDOUT, "check_802dot11\n");
fwrite(STDOUT, "Nagios script to check IEEE-802dot11-MIB.\n");
fwrite(STDOUT, "\n");
fwrite(STDOUT, "Usage: check_802dot11 [-hv] -ip <ip address> -lastOID <int> -type <check type> [-comm <community string>] [-val <value>]\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, "-lastOID <int> the last integer in the OID 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, "\tprivacy\tCheck for Privacy Option Implemented\n");
fwrite(STDOUT, "\tssid\tCheck that SSID is same as string (-val)\n");
fwrite(STDOUT, "\tbsstype\tCheck that BSS Type is Infrastructure\n");
fwrite(STDOUT, "\tmfrver\tCheck that manufacturer product version matches string (-val)\n");
fwrite(STDOUT, "\tchan\tCheck that AP is on channel (integer, -val)\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;
}
function checkargval($type)
{
global $argVal;
if(! isset($argVal) || trim($argVal) == "")
{
echo "UNKNOWN: -val argument must be specified for '$type' check type.\n";
exit(3);
}
}
?>