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