r3097 - merged SNMP code for switches and PDUs in one tab
[racktables] / inc / snmp.php
CommitLineData
2ffd5a2a
DO
1<?php
2
74aee2dc 3$iftable_processors = array();
6be06cbb
DO
4
5$iftable_processors['catalyst-4948-mgmt'] = array
6(
7 'pattern' => '@^FastEthernet1$@',
8 'replacement' => 'fa1',
9 'dict_key' => 19,
10 'label' => 'mgmt',
11 'try_next_proc' => FALSE,
12);
13
14$iftable_processors['catalyst-chassis-any-100TX'] = array
74aee2dc 15(
6be06cbb
DO
16 'pattern' => '@^FastEthernet([[:digit:]]+/)?([[:digit:]]+)$@',
17 'replacement' => 'fa\\1\\2',
74aee2dc 18 'dict_key' => 19,
6be06cbb 19 'label' => '\\2X',
56a797ef
DO
20 'try_next_proc' => FALSE,
21);
22
6be06cbb 23$iftable_processors['catalyst-chassis-25-to-26-100FX/MT-RJ'] = array
56a797ef 24(
6be06cbb
DO
25 'pattern' => '@^FastEthernet([[:digit:]]+/)?(25|26)$@',
26 'replacement' => 'fa\\1\\2',
56a797ef 27 'dict_key' => 1083,
6be06cbb
DO
28 'label' => '\\2',
29 'try_next_proc' => FALSE,
30);
31
32$iftable_processors['catalyst-chassis-any-1000T'] = array
33(
34 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?([[:digit:]]+)$@',
35 'replacement' => 'gi\\1\\2',
36 'dict_key' => 24,
37 'label' => '\\2X',
56a797ef 38 'try_next_proc' => FALSE,
74aee2dc
DO
39);
40
6be06cbb 41$iftable_processors['catalyst-chassis-uplinks-1000T'] = array
74aee2dc 42(
6be06cbb
DO
43 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?([[:digit:]]+)$@',
44 'replacement' => 'gi\\1\\2',
74aee2dc 45 'dict_key' => 24,
6be06cbb 46 'label' => '\\2',
56a797ef
DO
47 'try_next_proc' => FALSE,
48);
49
50$iftable_processors['catalyst-any-bp/1000T'] = array
51(
6be06cbb
DO
52 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?([[:digit:]]+)$@',
53 'replacement' => 'gi\\1\\2',
56a797ef
DO
54 'dict_key' => 1087,
55 'label' => '',
56 'try_next_proc' => FALSE,
74aee2dc
DO
57);
58
6be06cbb 59$iftable_processors['catalyst-chassis-any-1000SFP'] = array
74aee2dc 60(
6be06cbb
DO
61 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?([[:digit:]]+)$@',
62 'replacement' => 'gi\\1\\2',
8536e20a 63 'dict_key' => '4-1077',
6be06cbb 64 'label' => '\\2',
56a797ef
DO
65 'try_next_proc' => FALSE,
66);
67
6be06cbb 68$iftable_processors['catalyst-chassis-any-1000GBIC'] = array
56a797ef 69(
6be06cbb
DO
70 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?([[:digit:]]+)$@',
71 'replacement' => 'gi\\1\\2',
8536e20a 72 'dict_key' => '3-1078',
6be06cbb 73 'label' => '\\2',
56a797ef
DO
74 'try_next_proc' => FALSE,
75);
76
6be06cbb 77$iftable_processors['catalyst-chassis-21-to-24-combo-1000SFP'] = array
56a797ef 78(
6be06cbb
DO
79 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?(21|22|23|24)$@',
80 'replacement' => 'gi\\1\\2',
8536e20a 81 'dict_key' => '4-1077',
6be06cbb 82 'label' => '\\2',
56a797ef
DO
83 'try_next_proc' => TRUE,
84);
85
6be06cbb 86$iftable_processors['catalyst-chassis-45-to-48-combo-1000SFP'] = array
56a797ef 87(
6be06cbb
DO
88 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?(45|46|47|48)$@',
89 'replacement' => 'gi\\1\\2',
8536e20a 90 'dict_key' => '4-1077',
6be06cbb 91 'label' => '\\2',
56a797ef
DO
92 'try_next_proc' => TRUE,
93);
94
6be06cbb 95$iftable_processors['catalyst-chassis-uplinks-10000X2'] = array
56a797ef 96(
6be06cbb
DO
97 'pattern' => '@^TenGigabitEthernet([[:digit:]]+/)?([[:digit:]]+)$@',
98 'replacement' => 'te\\1\\2',
8536e20a 99 'dict_key' => '6-1080',
6be06cbb 100 'label' => '\\2',
56a797ef 101 'try_next_proc' => FALSE,
74aee2dc
DO
102);
103
6be06cbb 104$iftable_processors['catalyst-chassis-25-to-28-1000SFP'] = array
74aee2dc 105(
6be06cbb
DO
106 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?(25|26|27|28)$@',
107 'replacement' => 'gi\\1\\2',
8536e20a 108 'dict_key' => '4-1077',
6be06cbb 109 'label' => '\\2',
56a797ef 110 'try_next_proc' => FALSE,
74aee2dc
DO
111);
112
6be06cbb 113$iftable_processors['catalyst-chassis-49-to-52-1000SFP'] = array
74aee2dc 114(
6be06cbb
DO
115 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?(49|50|51|52)$@',
116 'replacement' => 'gi\\1\\2',
8536e20a 117 'dict_key' => '4-1077',
6be06cbb 118 'label' => '\\2',
56a797ef 119 'try_next_proc' => FALSE,
74aee2dc
DO
120);
121
122$iftable_processors['catalyst-13-to-16-1000SFP'] = array
123(
6be06cbb
DO
124 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?(13|14|15|16)$@',
125 'replacement' => 'gi\\1\\2',
8536e20a 126 'dict_key' => '4-1077',
6be06cbb 127 'label' => '\\2',
56a797ef 128 'try_next_proc' => FALSE,
74aee2dc
DO
129);
130
131$iftable_processors['catalyst-21-to-24-1000SFP'] = array
132(
6be06cbb
DO
133 'pattern' => '@^GigabitEthernet([[:digit:]]+/)?(21|22|23|24)$@',
134 'replacement' => 'gi\\1\\2',
8536e20a 135 'dict_key' => '4-1077',
6be06cbb 136 'label' => '\\2',
56a797ef 137 'try_next_proc' => FALSE,
74aee2dc
DO
138);
139
140$iftable_processors['nexus-any-10000SFP+'] = array
141(
56a797ef 142 'pattern' => '@^Ethernet([[:digit:]]/[[:digit:]]+)$@',
74aee2dc 143 'replacement' => 'e\\1',
8536e20a 144 'dict_key' => '9-1084',
56a797ef
DO
145 'label' => '\\1',
146 'try_next_proc' => FALSE,
74aee2dc
DO
147);
148
56a797ef 149$iftable_processors['procurve-chassis-100TX'] = array
74aee2dc 150(
56a797ef 151 'pattern' => '@^([[:digit:]]+)$@',
74aee2dc
DO
152 'replacement' => '\\1',
153 'dict_key' => 19,
56a797ef
DO
154 'label' => '\\1',
155 'try_next_proc' => FALSE,
156);
157
158$iftable_processors['procurve-chassis-1000T'] = array
159(
160 'pattern' => '@^([[:digit:]]+)$@',
161 'replacement' => '\\1',
162 'dict_key' => 24,
163 'label' => '\\1',
164 'try_next_proc' => FALSE,
165);
166
167$iftable_processors['procurve-modular-100TX'] = array
168(
169 'pattern' => '@^([A-Z][[:digit:]]+)$@',
170 'replacement' => '\\1',
171 'dict_key' => 19,
172 'label' => '\\1',
173 'try_next_proc' => FALSE,
74aee2dc
DO
174);
175
176$iftable_processors['procurve-25-to-26-1000T'] = array
177(
56a797ef 178 'pattern' => '@^(25|26)$@',
74aee2dc
DO
179 'replacement' => '\\1',
180 'dict_key' => 24,
56a797ef
DO
181 'label' => '\\1',
182 'try_next_proc' => FALSE,
74aee2dc
DO
183);
184
185$iftable_processors['procurve-49-to-50-1000T'] = array
186(
56a797ef 187 'pattern' => '@^(49|50)$@',
74aee2dc
DO
188 'replacement' => '\\1',
189 'dict_key' => 24,
56a797ef
DO
190 'label' => '\\1',
191 'try_next_proc' => FALSE,
74aee2dc
DO
192);
193
6be06cbb 194$iftable_processors['netgear-chassis-any-1000T'] = array
74aee2dc 195(
56a797ef
DO
196 'pattern' => '@^Unit: 1 Slot: 0 Port: ([[:digit:]]+) Gigabit - Level$@',
197 'replacement' => '\\1',
198 'dict_key' => 24,
199 'label' => '\\1',
200 'try_next_proc' => FALSE,
201);
202
6be06cbb
DO
203$iftable_processors['netgear-chassis-21-to-24-1000Tcombo'] = array
204(
205 'pattern' => '@^Unit: 1 Slot: 0 Port: ([[:digit:]]+) Gigabit - Level$@',
206 'replacement' => '\\1',
207 'dict_key' => 24,
208 'label' => '\\1T',
209 'try_next_proc' => FALSE,
210);
211
212$iftable_processors['netgear-chassis-21-to-24-1000SFP'] = array
213(
214 'pattern' => '@^Unit: 1 Slot: 0 Port: ([[:digit:]]+) Gigabit - Level$@',
215 'replacement' => '\\1',
8536e20a 216 'dict_key' => '4-1077',
6be06cbb
DO
217 'label' => '\\1F',
218 'try_next_proc' => TRUE,
219);
220
56a797ef
DO
221$iftable_processors['nortel-any-1000T'] = array
222(
223 'pattern' => '@^Ethernet Port on unit 1, port ([[:digit:]]+)$@',
74aee2dc
DO
224 'replacement' => '\\1',
225 'dict_key' => 24,
56a797ef
DO
226 'label' => '\\1',
227 'try_next_proc' => FALSE,
74aee2dc
DO
228);
229
230$known_switches = array // key is system OID w/o "enterprises" prefix
231(
232 '9.1.324' => array
233 (
234 'dict_key' => 380,
235 'text' => 'WS-C2950-24: 24 RJ-45/10-100TX',
6be06cbb 236 'processors' => array ('catalyst-chassis-any-100TX'),
74aee2dc
DO
237 ),
238 '9.1.325' => array
239 (
240 'dict_key' => 382,
241 'text' => 'WS-C2950C-24: 24 RJ-45/10-100TX + 2 MT-RJ/100FX fiber',
6be06cbb 242 'processors' => array ('catalyst-chassis-25-to-26-100FX/MT-RJ', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
243 ),
244 '9.1.696' => array
245 (
246 'dict_key' => 167,
247 'text' => 'WS-C2960G-24TC-L: 20 RJ-45/10-100-1000T(X) + 4 combo-gig',
6be06cbb 248 'processors' => array ('catalyst-chassis-21-to-24-combo-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
249 ),
250 '9.1.697' => array
251 (
252 'dict_key' => 166,
253 'text' => 'WS-C2960G-48TC-L: 44 RJ-45/10-100-1000T(X) + 4 combo-gig',
6be06cbb 254 'processors' => array ('catalyst-chassis-45-to-48-combo-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
255 ),
256 '9.1.716' => array
257 (
258 'dict_key' => 164,
259 'text' => 'WS-C2960-24TT-L: 24 RJ-45/10-100TX + 2 RJ-45/10-100-1000T(X)',
6be06cbb 260 'processors' => array ('catalyst-chassis-any-100TX', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
261 ),
262 '9.1.717' => array
263 (
264 'dict_key' => 162,
265 'text' => 'WS-C2960-48TT-L: 48 RJ-45/10-100TX + 2 RJ-45/10-100-1000T(X)',
6be06cbb 266 'processors' => array ('catalyst-chassis-any-100TX', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
267 ),
268 '9.1.527' => array
269 (
270 'dict_key' => 210,
271 'text' => 'WS-C2970G-24T: 24 RJ-45/10-100-1000T(X)',
6be06cbb 272 'processors' => array ('catalyst-chassis-any-1000T'),
74aee2dc
DO
273 ),
274 '9.1.561' => array
275 (
276 'dict_key' => 115,
277 'text' => 'WS-C2970G-24TS: 24 RJ-45/10-100-1000T(X) + 4 SFP/1000',
6be06cbb 278 'processors' => array ('catalyst-chassis-25-to-28-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
279 ),
280 '9.1.633' => array
281 (
282 'dict_key' => 169,
283 'text' => 'WS-C3560-24TS: 24 RJ-45/10-100TX + 2 SFP/1000',
6be06cbb 284 'processors' => array ('catalyst-chassis-any-1000SFP', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
285 ),
286 '9.1.634' => array
287 (
288 'dict_key' => 170,
289 'text' => 'WS-C3560-48TS: 48 RJ-45/10-100TX + 4 SFP/1000',
6be06cbb 290 'processors' => array ('catalyst-chassis-any-1000SFP', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
291 ),
292 '9.1.563' => array
293 (
294 'dict_key' => 171,
295 'text' => 'WS-C3560-24PS: 24 RJ-45/10-100TX + 2 SFP/1000',
6be06cbb 296 'processors' => array ('catalyst-chassis-any-1000SFP', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
297 ),
298 '9.1.564' => array
299 (
300 'dict_key' => 172,
301 'text' => 'WS-C3560-48PS: 48 RJ-45/10-100TX + 4 SFP/1000',
6be06cbb 302 'processors' => array ('catalyst-chassis-any-1000SFP', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
303 ),
304 '9.1.614' => array
305 (
306 'dict_key' => 175,
307 'text' => 'WS-C3560G-24PS: 24 RJ-45/10-100-1000T(X) + 4 SFP/1000',
6be06cbb 308 'processors' => array ('catalyst-chassis-25-to-28-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
309 ),
310 '9.1.615' => array
311 (
312 'dict_key' => 173,
313 'text' => 'WS-C3560G-24TS: 24 RJ-45/10-100-1000T(X) + 4 SFP/1000',
6be06cbb 314 'processors' => array ('catalyst-chassis-25-to-28-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
315 ),
316 '9.1.616' => array
317 (
318 'dict_key' => 176,
319 'text' => 'WS-C3560G-48PS: 48 RJ-45/10-100-1000T(X) + 4 SFP/1000',
6be06cbb 320 'processors' => array ('catalyst-chassis-49-to-52-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
321 ),
322 '9.1.617' => array
323 (
324 'dict_key' => 174,
325 'text' => 'WS-C3560G-48TS: 48 RJ-45/10-100-1000T(X) + 4 SFP/1000',
6be06cbb 326 'processors' => array ('catalyst-chassis-49-to-52-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
327 ),
328 '9.1.626' => array
329 (
330 'dict_key' => 147,
56a797ef 331 'text' => 'WS-C4948: 48 RJ-45/10-100-1000T(X) + 4 SFP/1000 + 1 RJ-45/100TX (OOB mgmt)',
6be06cbb 332 'processors' => array ('catalyst-chassis-49-to-52-1000SFP', 'catalyst-chassis-uplinks-1000T', 'catalyst-4948-mgmt'),
74aee2dc
DO
333 ),
334 '9.1.659' => array
335 (
336 'dict_key' => 377,
56a797ef 337 'text' => 'WS-C4948-10GE: 48 RJ-45/10-100-1000T(X) + 2 X2/10000 + 1 RJ-45/100TX (OOB mgmt)',
6be06cbb 338 'processors' => array ('catalyst-chassis-uplinks-10000X2', 'catalyst-chassis-uplinks-1000T', 'catalyst-4948-mgmt'),
74aee2dc
DO
339 ),
340 '9.1.428' => array
341 (
342 'dict_key' => 389,
343 'text' => 'WS-C2950G-24: 24 RJ-45/10-100TX + 2 GBIC/1000',
6be06cbb 344 'processors' => array ('catalyst-chassis-any-1000GBIC', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
345 ),
346 '9.1.429' => array
347 (
348 'dict_key' => 390,
349 'text' => 'WS-C2950G-48: 48 RJ-45/10-100TX + 2 GBIC/1000',
6be06cbb 350 'processors' => array ('catalyst-chassis-any-1000GBIC', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
351 ),
352 '9.1.559' => array
353 (
354 'dict_key' => 387,
355 'text' => 'WS-C2950T-48: 48 RJ-45/10-100TX + 2 RJ-45/10-100-1000T(X)',
6be06cbb 356 'processors' => array ('catalyst-chassis-uplinks-1000T', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
357 ),
358 '9.1.749' => array
359 (
360 'dict_key' => 989,
361 'text' => 'WS-CBS3030-DEL: 10 internal/10-100-1000T(X) + 2 RJ-45/10-100-1000T(X) + 4 SFP/1000',
56a797ef 362 'processors' => array ('catalyst-11-to-12-1000T', 'catalyst-13-to-16-1000SFP', 'catalyst-any-bp/1000T'),
74aee2dc
DO
363 ),
364 '9.1.920' => array
365 (
366 'dict_key' => 795,
367 'text' => 'WS-CBS3032-DEL: 16 internal/10-100-1000T(X) + 4 RJ-45/10-100-1000T(X) + 4 SFP/1000',
56a797ef 368 'processors' => array ('catalyst-17-to-20-1000T', 'catalyst-21-to-24-1000SFP', 'catalyst-any-bp/1000T'),
74aee2dc
DO
369 ),
370 '9.12.3.1.3.719' => array
371 (
372 'dict_key' => 960,
373 'text' => 'N5K-C5020: 40 SFP+/10000',
374 'processors' => array ('nexus-any-10000SFP+'),
375 ),
56a797ef
DO
376 '11.2.3.7.11.32' => array
377 (
378 'dict_key' => 871,
379 'text' => 'J4904A: 48 RJ-45/10-100-1000T(X)',
380 'processors' => array ('procurve-chassis-1000T'),
381 ),
74aee2dc
DO
382 '11.2.3.7.11.36' => array
383 (
384 'dict_key' => 865,
385 'text' => 'J8164A: 24 RJ-45/10-100TX + 2 RJ-45/10-100-1000T(X)',
56a797ef 386 'processors' => array ('procurve-25-to-26-1000T', 'procurve-chassis-100TX'),
74aee2dc
DO
387 ),
388 '11.2.3.7.11.35' => array
389 (
390 'dict_key' => 867,
391 'text' => 'J8165A: 48 RJ-45/10-100TX + 2 RJ-45/10-100-1000T(X)',
56a797ef
DO
392 'processors' => array ('procurve-49-to-50-1000T', 'procurve-chassis-100TX'),
393 ),
394 '11.2.3.7.11.9' => array
395 (
396 'dict_key' => 1086,
397 'text' => 'J4121A: modular system',
398 'processors' => array ('procurve-modular-100TX'),
74aee2dc
DO
399 ),
400 '4526.100.2.2' => array
401 (
402 'dict_key' => 562,
6be06cbb
DO
403 'text' => 'GSM7224: 20 RJ-45/10-100-1000T(X) + 4 combo-gig',
404 'processors' => array ('netgear-chassis-21-to-24-1000SFP', 'netgear-chassis-21-to-24-1000Tcombo', 'netgear-chassis-any-1000T'),
74aee2dc 405 ),
56a797ef
DO
406 '45.3.68.5' => array
407 (
408 'dict_key' => 1085,
409 'text' => 'BES50GE-12T PWR: 12 RJ-45/10-100-1000T(X)',
410 'processors' => array ('nortel-any-1000T'),
411 ),
74aee2dc
DO
412);
413
74aee2dc
DO
414function updateStickerForCell ($cell, $attr_id, $new_value)
415{
416 if (!strlen ($cell['attrs'][$attr_id]['value']) && strlen ($new_value))
417 commitUpdateAttrValue ($cell['id'], $attr_id, $new_value);
418}
419
8536e20a
DO
420$msgcode['doSNMPmining']['ERR1'] = 161;
421$msgcode['doSNMPmining']['ERR2'] = 162;
422$msgcode['doSNMPmining']['ERR3'] = 188;
423$msgcode['doSNMPmining']['ERR4'] = 189;
424$msgcode['doSNMPmining']['OK'] = 81;
56a797ef 425function doSNMPmining ($object_id, $community)
74aee2dc 426{
74aee2dc
DO
427 $objectInfo = spotEntity ('object', $object_id);
428 $objectInfo['attrs'] = getAttrValues ($object_id);
429 $endpoints = findAllEndpoints ($object_id, $objectInfo['name']);
430 if (count ($endpoints) == 0)
8536e20a 431 return buildRedirectURL (__FUNCTION__, 'ERR1'); // endpoint not found
74aee2dc 432 if (count ($endpoints) > 1)
8536e20a 433 return buildRedirectURL (__FUNCTION__, 'ERR2'); // can't pick an address
4848a7e3
DO
434
435 switch ($objectInfo['objtype_id'])
436 {
437 case 8:
438 return doSwitchSNMPmining ($objectInfo, $endpoints[0], $community);
439 case 2:
440 return doPDUSNMPmining ($objectInfo, $endpoints[0], $community);
441 }
442}
443
444function doSwitchSNMPmining ($object, $hostname, $comminuty)
445{
446 $log = emptyLog();
447 global $known_switches, $iftable_processors;
74aee2dc 448
8536e20a
DO
449 if (FALSE === ($sysObjectID = @snmpget ($endpoints[0], $community, 'sysObjectID.0')))
450 return buildRedirectURL (__FUNCTION__, 'ERR3'); // // fatal SNMP failure
74aee2dc 451 $sysObjectID = ereg_replace ('^.*(enterprises\.)([\.[:digit:]]+)$', '\\2', $sysObjectID);
8536e20a
DO
452 $sysName = substr (@snmpget ($endpoints[0], $community, 'sysName.0'), strlen ('STRING: '));
453 $sysDescr = substr (@snmpget ($endpoints[0], $community, 'sysDescr.0'), strlen ('STRING: '));
74aee2dc
DO
454 $sysDescr = str_replace (array ("\n", "\r"), " ", $sysDescr); // Make it one line
455 if (!isset ($known_switches[$sysObjectID]))
8536e20a 456 return buildRedirectURL (__FUNCTION__, 'ERR4', array ($sysObjectID)); // unknown OID
56a797ef 457 updateStickerForCell ($objectInfo, 2, $known_switches[$sysObjectID]['dict_key']);
74aee2dc 458 updateStickerForCell ($objectInfo, 3, $sysName);
56a797ef 459 $log = mergeLogs ($log, oneLiner (81, array ('generic')));
74aee2dc
DO
460 switch (1)
461 {
56a797ef 462 case preg_match ('/^9\.1\./', $sysObjectID): // Catalyst
74aee2dc
DO
463 $exact_release = ereg_replace ('^.*, Version ([^ ]+), .*$', '\\1', $sysDescr);
464 $major_line = ereg_replace ('^([[:digit:]]+\.[[:digit:]]+)[^[:digit:]].*', '\\1', $exact_release);
465 $ios_codes = array
466 (
467 '12.0' => 244,
468 '12.1' => 251,
469 '12.2' => 252,
470 );
471 updateStickerForCell ($objectInfo, 5, $exact_release);
6be06cbb
DO
472 if (array_key_exists ($major_line, $ios_codes))
473 updateStickerForCell ($objectInfo, 4, $ios_codes[$major_line]);
8536e20a 474 $sysChassi = @snmpget ($endpoints[0], $community, '1.3.6.1.4.1.9.3.6.3.0');
74aee2dc
DO
475 if ($sysChassi !== FALSE or $sysChassi !== NULL)
476 updateStickerForCell ($objectInfo, 1, str_replace ('"', '', substr ($sysChassi, strlen ('STRING: '))));
6be06cbb 477 commitAddPort ($object_id, 'con0', 29, 'console', ''); // RJ-45 RS-232 console
56a797ef 478 $log = mergeLogs ($log, oneLiner (81, array ('catalyst-generic')));
74aee2dc 479 break;
56a797ef 480 case preg_match ('/^9\.12\.3\.1\.3\./', $sysObjectID): // Nexus
74aee2dc
DO
481 $exact_release = ereg_replace ('^.*, Version ([^ ]+), .*$', '\\1', $sysDescr);
482 $major_line = ereg_replace ('^([[:digit:]]+\.[[:digit:]]+)[^[:digit:]].*', '\\1', $exact_release);
483 $nxos_codes = array
484 (
485 '4.0' => 963,
486 '4.1' => 964,
487 );
6be06cbb
DO
488 if (array_key_exists ($major_line, $nxos_codes))
489 updateStickerForCell ($objectInfo, 4, $nxos_codes[$major_line]);
74aee2dc 490 updateStickerForCell ($objectInfo, 5, $exact_release);
56a797ef 491 $log = mergeLogs ($log, oneLiner (81, array ('nexus-generic')));
74aee2dc 492 break;
56a797ef 493 case preg_match ('/^11\.2\.3\.7\.11\./', $sysObjectID): // ProCurve
74aee2dc
DO
494 $exact_release = ereg_replace ('^.* revision ([^ ]+), .*$', '\\1', $sysDescr);
495 updateStickerForCell ($objectInfo, 5, $exact_release);
56a797ef 496 $log = mergeLogs ($log, oneLiner (81, array ('procurve-generic')));
74aee2dc 497 break;
6be06cbb
DO
498 case preg_match ('/^4526\.100\.2\./', $sysObjectID): // NETGEAR
499 commitAddPort ($object_id, 'console', 681, 'console', ''); // DB-9 RS-232 console
500 $log = mergeLogs ($log, oneLiner (81, array ('netgear-generic')));
501 break;
56a797ef 502 default: // Nortel, NETGEAR...
74aee2dc
DO
503 break;
504 }
56a797ef
DO
505 $ifInfo = array();
506 $tablename = 'ifDescr';
507 foreach (snmpwalkoid ($endpoints[0], $community, $tablename) as $oid => $value)
508 {
509 $randomindex = ereg_replace ("^.*${tablename}\.(.+)\$", '\\1', $oid);
510 $value = trim (ereg_replace ('^.+: (.+)$', '\\1', $value), '"');
511 $ifInfo[$randomindex][$tablename] = $value;
512 }
513 $tablename = 'ifPhysAddress';
514 foreach (snmpwalkoid ($endpoints[0], $community, $tablename) as $oid => $value)
515 {
516 $randomindex = ereg_replace ("^.*${tablename}\.(.+)\$", '\\1', $oid);
517 $value = trim ($value);
518 // NET-SNMP may return MAC addresses in one of two (?) formats depending on
519 // DISPLAY-HINT internal database. The best we can do about it is to accept both.
520 // Bug originally reported by Walery Wysotsky against openSUSE 11.0.
521 if (preg_match ('/^string: /i', $value)) // STRING: x:yy:z:xx:y:zz
522 {
523 list ($dummy, $value) = explode (' ', $value);
524 $addrbytes = explode (':', $value);
525 foreach ($addrbytes as $bidx => $bytestr)
526 if (strlen ($bytestr) == 1)
527 $addrbytes[$bidx] = '0' . $bytestr;
528 }
529 elseif (preg_match ('/^hex-string: /i', $value)) // Hex-STRING: xx yy zz xx yy zz
530 $addrbytes = explode (' ', substr ($value, -17));
531 else
532 continue; // martian format
533 $ifInfo[$randomindex][$tablename] = implode ('', $addrbytes);
534 }
535 // process each interface only once regardless of how many processors we have to run
536 foreach ($ifInfo as $iface)
537 foreach ($known_switches[$sysObjectID]['processors'] as $processor_name)
538 {
56a797ef
DO
539 $newname = preg_replace ($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['replacement'], $iface['ifDescr'], 1, $count);
540 if (!$count)
541 continue; // try next processor on current port
542 $newlabel = preg_replace ($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['label'], $iface['ifDescr'], 1, $count);
543 commitAddPort ($object_id, $newname, $iftable_processors[$processor_name]['dict_key'], $newlabel, $iface['ifPhysAddress']);
544 if (!$iftable_processors[$processor_name]['try_next_proc']) // done with this port
545 continue 2;
546 }
547 foreach ($known_switches[$sysObjectID]['processors'] as $processor_name)
548 $log = mergeLogs ($log, oneLiner (81, array ($processor_name)));
8536e20a
DO
549 // No failure up to this point, thus leave current tab for the "Ports" one.
550 return buildWideRedirectURL ($log, NULL, 'ports');
74aee2dc
DO
551}
552
38e05b77 553
4848a7e3
DO
554$msgcode['doPDUSNMPmining']['OK'] = 0;
555function doPDUSNMPmining ($objectInfo, $hostname, $community)
38e05b77 556{
4848a7e3
DO
557 $switch = new APCPowerSwitch ($hostname, $community);
558 updateStickerForCell ($objectInfo, 3, $switch->getName());
559 $portno = 1;
560 foreach ($switch->getPorts() as $name => $port)
561 commitAddPort ($objectInfo['id'], $portno, 16, $portno++, '');
562 return buildRedirectURL (__FUNCTION__, 'OK', array ('Added ' . ($portno - 1) . ' port(s)'));
38e05b77
DO
563}
564
4848a7e3 565// APC SNMP code by Russ Garrett
38e05b77
DO
566define('APC_STATUS_ON', 1);
567define('APC_STATUS_OFF', 2);
568define('APC_STATUS_REBOOT', 3);
569
570class SNMPDevice {
571 protected $hostname;
572 protected $community;
573
574 function __construct($hostname, $community) {
575 $this->hostname = $hostname;
576 $this->community = $community;
577 }
578
579 function getName() {
580 return $this->getString('sysName.0');
581 }
582
583 function getDescription() {
584 return $this->getString('sysDescr.0');
585 }
586
587 protected function snmpSet($oid, $type, $value) {
588 return snmpset($this->hostname, $this->community, $oid, $type, $value);
589 }
590
591 protected function getString($oid) {
592 return trim(str_replace('STRING: ', '', snmpget($this->hostname, $this->community, $oid)), '"');
593 }
594}
595
596class APCPowerSwitch extends SNMPDevice {
597 protected $snmpMib = 'SNMPv2-SMI::enterprises.318';
598
599 function getPorts() {
600 $data = snmpwalk($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.3.3.1.1.2");
601 $status = snmpwalk($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.3.3.1.1.4");
602 $out = array();
603 foreach ($data as $id => $d) {
604 $out[$id + 1] = array(trim(str_replace('STRING: ', '', $d), '"'), str_replace('INTEGER: ', '', $status[$id]));
605 }
606 return $out;
607 }
608
609 function getPortStatus($id) {
610 return trim(snmpget($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.3.3.1.1.4.$id"), 'INTEGER: ');
611 }
612
613 function getPortName($id) {
614 return trim(str_replace('STRING: ', '', snmpget($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.3.3.1.1.2.$id")), '"');
615 }
616
617 function setPortName($id, $name) {
618 return snmpset($this->hostname, $this->community, "{$this->snmpMib}.1.1.4.5.2.1.3.$id", 's', $name);
619 }
620
621 function portOff($id) {
622 return $this->snmpSet("{$this->snmpMib}.1.1.12.3.3.1.1.4.$id", 'i', APC_STATUS_OFF);
623 }
624
625 function portOn($id) {
626 return $this->snmpSet("{$this->snmpMib}.1.1.12.3.3.1.1.4.$id", 'i', APC_STATUS_ON);
627 }
628
629 function portReboot($id) {
630 return $this->snmpSet("{$this->snmpMib}.1.1.12.3.3.1.1.4.$id", 'i', APC_STATUS_REBOOT);
631 }
632}
633
2ffd5a2a 634?>