r3119 - enable "OEM S/N", "FQDN" and "SW version" stickers for PDUs
[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
e7662d90
DO
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
56a797ef 158$iftable_processors['procurve-chassis-100TX'] = array
74aee2dc 159(
56a797ef 160 'pattern' => '@^([[:digit:]]+)$@',
74aee2dc
DO
161 'replacement' => '\\1',
162 'dict_key' => 19,
56a797ef
DO
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,
74aee2dc
DO
183);
184
185$iftable_processors['procurve-25-to-26-1000T'] = array
186(
56a797ef 187 'pattern' => '@^(25|26)$@',
74aee2dc
DO
188 'replacement' => '\\1',
189 'dict_key' => 24,
56a797ef
DO
190 'label' => '\\1',
191 'try_next_proc' => FALSE,
74aee2dc
DO
192);
193
194$iftable_processors['procurve-49-to-50-1000T'] = array
195(
56a797ef 196 'pattern' => '@^(49|50)$@',
74aee2dc
DO
197 'replacement' => '\\1',
198 'dict_key' => 24,
56a797ef
DO
199 'label' => '\\1',
200 'try_next_proc' => FALSE,
74aee2dc
DO
201);
202
6be06cbb 203$iftable_processors['netgear-chassis-any-1000T'] = array
74aee2dc 204(
56a797ef
DO
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
6be06cbb
DO
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',
8536e20a 225 'dict_key' => '4-1077',
6be06cbb
DO
226 'label' => '\\1F',
227 'try_next_proc' => TRUE,
228);
229
56a797ef
DO
230$iftable_processors['nortel-any-1000T'] = array
231(
232 'pattern' => '@^Ethernet Port on unit 1, port ([[:digit:]]+)$@',
74aee2dc
DO
233 'replacement' => '\\1',
234 'dict_key' => 24,
56a797ef
DO
235 'label' => '\\1',
236 'try_next_proc' => FALSE,
74aee2dc
DO
237);
238
91389980
DO
239$iftable_processors['juniper-DPCE-R-4XGE-XFP'] = array
240(
7d69a266
DO
241 'pattern' => '@^xe-([[:digit:]]+)/([[:digit:]]+/[[:digit:]]+)$@',
242 'replacement' => '\\0',
91389980 243 'dict_key' => '8-1082', // XFP/empty
7d69a266
DO
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',
91389980
DO
281 'try_next_proc' => FALSE,
282);
283
74aee2dc
DO
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',
6be06cbb 290 'processors' => array ('catalyst-chassis-any-100TX'),
74aee2dc
DO
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',
6be06cbb 296 'processors' => array ('catalyst-chassis-25-to-26-100FX/MT-RJ', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
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',
6be06cbb 302 'processors' => array ('catalyst-chassis-21-to-24-combo-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
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',
6be06cbb 308 'processors' => array ('catalyst-chassis-45-to-48-combo-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
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)',
6be06cbb 314 'processors' => array ('catalyst-chassis-any-100TX', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
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)',
6be06cbb 320 'processors' => array ('catalyst-chassis-any-100TX', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
321 ),
322 '9.1.527' => array
323 (
324 'dict_key' => 210,
325 'text' => 'WS-C2970G-24T: 24 RJ-45/10-100-1000T(X)',
6be06cbb 326 'processors' => array ('catalyst-chassis-any-1000T'),
74aee2dc
DO
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',
6be06cbb 332 'processors' => array ('catalyst-chassis-25-to-28-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
333 ),
334 '9.1.633' => array
335 (
336 'dict_key' => 169,
337 'text' => 'WS-C3560-24TS: 24 RJ-45/10-100TX + 2 SFP/1000',
6be06cbb 338 'processors' => array ('catalyst-chassis-any-1000SFP', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
339 ),
340 '9.1.634' => array
341 (
342 'dict_key' => 170,
343 'text' => 'WS-C3560-48TS: 48 RJ-45/10-100TX + 4 SFP/1000',
6be06cbb 344 'processors' => array ('catalyst-chassis-any-1000SFP', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
345 ),
346 '9.1.563' => array
347 (
348 'dict_key' => 171,
349 'text' => 'WS-C3560-24PS: 24 RJ-45/10-100TX + 2 SFP/1000',
6be06cbb 350 'processors' => array ('catalyst-chassis-any-1000SFP', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
351 ),
352 '9.1.564' => array
353 (
354 'dict_key' => 172,
355 'text' => 'WS-C3560-48PS: 48 RJ-45/10-100TX + 4 SFP/1000',
6be06cbb 356 'processors' => array ('catalyst-chassis-any-1000SFP', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
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',
6be06cbb 362 'processors' => array ('catalyst-chassis-25-to-28-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
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',
6be06cbb 368 'processors' => array ('catalyst-chassis-25-to-28-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
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',
6be06cbb 374 'processors' => array ('catalyst-chassis-49-to-52-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
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',
6be06cbb 380 'processors' => array ('catalyst-chassis-49-to-52-1000SFP', 'catalyst-chassis-any-1000T'),
74aee2dc
DO
381 ),
382 '9.1.626' => array
383 (
384 'dict_key' => 147,
56a797ef 385 'text' => 'WS-C4948: 48 RJ-45/10-100-1000T(X) + 4 SFP/1000 + 1 RJ-45/100TX (OOB mgmt)',
6be06cbb 386 'processors' => array ('catalyst-chassis-49-to-52-1000SFP', 'catalyst-chassis-uplinks-1000T', 'catalyst-4948-mgmt'),
74aee2dc
DO
387 ),
388 '9.1.659' => array
389 (
390 'dict_key' => 377,
56a797ef 391 'text' => 'WS-C4948-10GE: 48 RJ-45/10-100-1000T(X) + 2 X2/10000 + 1 RJ-45/100TX (OOB mgmt)',
6be06cbb 392 'processors' => array ('catalyst-chassis-uplinks-10000X2', 'catalyst-chassis-uplinks-1000T', 'catalyst-4948-mgmt'),
74aee2dc
DO
393 ),
394 '9.1.428' => array
395 (
396 'dict_key' => 389,
397 'text' => 'WS-C2950G-24: 24 RJ-45/10-100TX + 2 GBIC/1000',
6be06cbb 398 'processors' => array ('catalyst-chassis-any-1000GBIC', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
399 ),
400 '9.1.429' => array
401 (
402 'dict_key' => 390,
403 'text' => 'WS-C2950G-48: 48 RJ-45/10-100TX + 2 GBIC/1000',
6be06cbb 404 'processors' => array ('catalyst-chassis-any-1000GBIC', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
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)',
6be06cbb 410 'processors' => array ('catalyst-chassis-uplinks-1000T', 'catalyst-chassis-any-100TX'),
74aee2dc
DO
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',
56a797ef 416 'processors' => array ('catalyst-11-to-12-1000T', 'catalyst-13-to-16-1000SFP', 'catalyst-any-bp/1000T'),
74aee2dc
DO
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',
56a797ef 422 'processors' => array ('catalyst-17-to-20-1000T', 'catalyst-21-to-24-1000SFP', 'catalyst-any-bp/1000T'),
74aee2dc
DO
423 ),
424 '9.12.3.1.3.719' => array
425 (
426 'dict_key' => 960,
427 'text' => 'N5K-C5020: 40 SFP+/10000',
e7662d90 428 'processors' => array ('nexus-any-10000SFP+', 'nexus-mgmt'),
74aee2dc 429 ),
56a797ef
DO
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 ),
74aee2dc
DO
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)',
56a797ef 440 'processors' => array ('procurve-25-to-26-1000T', 'procurve-chassis-100TX'),
74aee2dc
DO
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)',
56a797ef
DO
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'),
74aee2dc
DO
453 ),
454 '4526.100.2.2' => array
455 (
456 'dict_key' => 562,
6be06cbb
DO
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'),
74aee2dc 459 ),
56a797ef
DO
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 ),
91389980
DO
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 ),
7d69a266
DO
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 ),
74aee2dc
DO
478);
479
74aee2dc
DO
480function 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
8536e20a
DO
486$msgcode['doSNMPmining']['ERR1'] = 161;
487$msgcode['doSNMPmining']['ERR2'] = 162;
488$msgcode['doSNMPmining']['ERR3'] = 188;
489$msgcode['doSNMPmining']['ERR4'] = 189;
490$msgcode['doSNMPmining']['OK'] = 81;
56a797ef 491function doSNMPmining ($object_id, $community)
74aee2dc 492{
74aee2dc
DO
493 $objectInfo = spotEntity ('object', $object_id);
494 $objectInfo['attrs'] = getAttrValues ($object_id);
495 $endpoints = findAllEndpoints ($object_id, $objectInfo['name']);
496 if (count ($endpoints) == 0)
8536e20a 497 return buildRedirectURL (__FUNCTION__, 'ERR1'); // endpoint not found
74aee2dc 498 if (count ($endpoints) > 1)
8536e20a 499 return buildRedirectURL (__FUNCTION__, 'ERR2'); // can't pick an address
4848a7e3
DO
500
501 switch ($objectInfo['objtype_id'])
502 {
503 case 8:
504 return doSwitchSNMPmining ($objectInfo, $endpoints[0], $community);
505 case 2:
506 return doPDUSNMPmining ($objectInfo, $endpoints[0], $community);
507 }
508}
509
510function doSwitchSNMPmining ($object, $hostname, $comminuty)
511{
512 $log = emptyLog();
513 global $known_switches, $iftable_processors;
74aee2dc 514
8536e20a
DO
515 if (FALSE === ($sysObjectID = @snmpget ($endpoints[0], $community, 'sysObjectID.0')))
516 return buildRedirectURL (__FUNCTION__, 'ERR3'); // // fatal SNMP failure
74aee2dc 517 $sysObjectID = ereg_replace ('^.*(enterprises\.)([\.[:digit:]]+)$', '\\2', $sysObjectID);
8536e20a
DO
518 $sysName = substr (@snmpget ($endpoints[0], $community, 'sysName.0'), strlen ('STRING: '));
519 $sysDescr = substr (@snmpget ($endpoints[0], $community, 'sysDescr.0'), strlen ('STRING: '));
74aee2dc
DO
520 $sysDescr = str_replace (array ("\n", "\r"), " ", $sysDescr); // Make it one line
521 if (!isset ($known_switches[$sysObjectID]))
8536e20a 522 return buildRedirectURL (__FUNCTION__, 'ERR4', array ($sysObjectID)); // unknown OID
56a797ef 523 updateStickerForCell ($objectInfo, 2, $known_switches[$sysObjectID]['dict_key']);
74aee2dc 524 updateStickerForCell ($objectInfo, 3, $sysName);
56a797ef 525 $log = mergeLogs ($log, oneLiner (81, array ('generic')));
74aee2dc
DO
526 switch (1)
527 {
56a797ef 528 case preg_match ('/^9\.1\./', $sysObjectID): // Catalyst
74aee2dc
DO
529 $exact_release = ereg_replace ('^.*, Version ([^ ]+), .*$', '\\1', $sysDescr);
530 $major_line = ereg_replace ('^([[:digit:]]+\.[[:digit:]]+)[^[:digit:]].*', '\\1', $exact_release);
531 $ios_codes = array
532 (
533 '12.0' => 244,
534 '12.1' => 251,
535 '12.2' => 252,
536 );
537 updateStickerForCell ($objectInfo, 5, $exact_release);
6be06cbb
DO
538 if (array_key_exists ($major_line, $ios_codes))
539 updateStickerForCell ($objectInfo, 4, $ios_codes[$major_line]);
8536e20a 540 $sysChassi = @snmpget ($endpoints[0], $community, '1.3.6.1.4.1.9.3.6.3.0');
74aee2dc
DO
541 if ($sysChassi !== FALSE or $sysChassi !== NULL)
542 updateStickerForCell ($objectInfo, 1, str_replace ('"', '', substr ($sysChassi, strlen ('STRING: '))));
6be06cbb 543 commitAddPort ($object_id, 'con0', 29, 'console', ''); // RJ-45 RS-232 console
56a797ef 544 $log = mergeLogs ($log, oneLiner (81, array ('catalyst-generic')));
74aee2dc 545 break;
56a797ef 546 case preg_match ('/^9\.12\.3\.1\.3\./', $sysObjectID): // Nexus
74aee2dc
DO
547 $exact_release = ereg_replace ('^.*, Version ([^ ]+), .*$', '\\1', $sysDescr);
548 $major_line = ereg_replace ('^([[:digit:]]+\.[[:digit:]]+)[^[:digit:]].*', '\\1', $exact_release);
549 $nxos_codes = array
550 (
551 '4.0' => 963,
552 '4.1' => 964,
553 );
6be06cbb
DO
554 if (array_key_exists ($major_line, $nxos_codes))
555 updateStickerForCell ($objectInfo, 4, $nxos_codes[$major_line]);
74aee2dc 556 updateStickerForCell ($objectInfo, 5, $exact_release);
e7662d90 557 commitAddPort ($object_id, 'con0', '1-29', 'console', ''); // RJ-45 RS-232 console
56a797ef 558 $log = mergeLogs ($log, oneLiner (81, array ('nexus-generic')));
74aee2dc 559 break;
56a797ef 560 case preg_match ('/^11\.2\.3\.7\.11\./', $sysObjectID): // ProCurve
74aee2dc
DO
561 $exact_release = ereg_replace ('^.* revision ([^ ]+), .*$', '\\1', $sysDescr);
562 updateStickerForCell ($objectInfo, 5, $exact_release);
56a797ef 563 $log = mergeLogs ($log, oneLiner (81, array ('procurve-generic')));
74aee2dc 564 break;
6be06cbb
DO
565 case preg_match ('/^4526\.100\.2\./', $sysObjectID): // NETGEAR
566 commitAddPort ($object_id, 'console', 681, 'console', ''); // DB-9 RS-232 console
567 $log = mergeLogs ($log, oneLiner (81, array ('netgear-generic')));
568 break;
7d69a266
DO
569 case preg_match ('/^2011\.2\.23\./', $sysObjectID): // Huawei
570 commitAddPort ($object_id, 'console', 681, 'console', ''); // DB-9 RS-232 console
571 $log = mergeLogs ($log, oneLiner (81, array ('huawei-generic')));
572 break;
573 case preg_match ('/^2636\.1\.1\.1\.2\./', $sysObjectID): // Juniper
574 commitAddPort ($object_id, 'console', 681, 'console', ''); // DB-9 RS-232 console
575 $log = mergeLogs ($log, oneLiner (81, array ('juniper-generic')));
576 default: // Nortel...
74aee2dc
DO
577 break;
578 }
56a797ef
DO
579 $ifInfo = array();
580 $tablename = 'ifDescr';
581 foreach (snmpwalkoid ($endpoints[0], $community, $tablename) as $oid => $value)
582 {
583 $randomindex = ereg_replace ("^.*${tablename}\.(.+)\$", '\\1', $oid);
584 $value = trim (ereg_replace ('^.+: (.+)$', '\\1', $value), '"');
585 $ifInfo[$randomindex][$tablename] = $value;
586 }
587 $tablename = 'ifPhysAddress';
588 foreach (snmpwalkoid ($endpoints[0], $community, $tablename) as $oid => $value)
589 {
590 $randomindex = ereg_replace ("^.*${tablename}\.(.+)\$", '\\1', $oid);
591 $value = trim ($value);
592 // NET-SNMP may return MAC addresses in one of two (?) formats depending on
593 // DISPLAY-HINT internal database. The best we can do about it is to accept both.
594 // Bug originally reported by Walery Wysotsky against openSUSE 11.0.
595 if (preg_match ('/^string: /i', $value)) // STRING: x:yy:z:xx:y:zz
596 {
597 list ($dummy, $value) = explode (' ', $value);
598 $addrbytes = explode (':', $value);
599 foreach ($addrbytes as $bidx => $bytestr)
600 if (strlen ($bytestr) == 1)
601 $addrbytes[$bidx] = '0' . $bytestr;
602 }
603 elseif (preg_match ('/^hex-string: /i', $value)) // Hex-STRING: xx yy zz xx yy zz
604 $addrbytes = explode (' ', substr ($value, -17));
605 else
606 continue; // martian format
607 $ifInfo[$randomindex][$tablename] = implode ('', $addrbytes);
608 }
609 // process each interface only once regardless of how many processors we have to run
610 foreach ($ifInfo as $iface)
611 foreach ($known_switches[$sysObjectID]['processors'] as $processor_name)
612 {
56a797ef
DO
613 $newname = preg_replace ($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['replacement'], $iface['ifDescr'], 1, $count);
614 if (!$count)
615 continue; // try next processor on current port
616 $newlabel = preg_replace ($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['label'], $iface['ifDescr'], 1, $count);
617 commitAddPort ($object_id, $newname, $iftable_processors[$processor_name]['dict_key'], $newlabel, $iface['ifPhysAddress']);
618 if (!$iftable_processors[$processor_name]['try_next_proc']) // done with this port
619 continue 2;
620 }
621 foreach ($known_switches[$sysObjectID]['processors'] as $processor_name)
622 $log = mergeLogs ($log, oneLiner (81, array ($processor_name)));
8536e20a
DO
623 // No failure up to this point, thus leave current tab for the "Ports" one.
624 return buildWideRedirectURL ($log, NULL, 'ports');
74aee2dc
DO
625}
626
4848a7e3
DO
627$msgcode['doPDUSNMPmining']['OK'] = 0;
628function doPDUSNMPmining ($objectInfo, $hostname, $community)
38e05b77 629{
4848a7e3
DO
630 $switch = new APCPowerSwitch ($hostname, $community);
631 updateStickerForCell ($objectInfo, 3, $switch->getName());
632 $portno = 1;
633 foreach ($switch->getPorts() as $name => $port)
30ad8bc4 634 commitAddPort ($objectInfo['id'], $portno, '1-16', $portno++, '');
4848a7e3 635 return buildRedirectURL (__FUNCTION__, 'OK', array ('Added ' . ($portno - 1) . ' port(s)'));
38e05b77
DO
636}
637
4848a7e3 638// APC SNMP code by Russ Garrett
38e05b77
DO
639define('APC_STATUS_ON', 1);
640define('APC_STATUS_OFF', 2);
641define('APC_STATUS_REBOOT', 3);
642
643class SNMPDevice {
644 protected $hostname;
645 protected $community;
646
647 function __construct($hostname, $community) {
648 $this->hostname = $hostname;
649 $this->community = $community;
650 }
651
652 function getName() {
653 return $this->getString('sysName.0');
654 }
655
656 function getDescription() {
657 return $this->getString('sysDescr.0');
658 }
659
660 protected function snmpSet($oid, $type, $value) {
661 return snmpset($this->hostname, $this->community, $oid, $type, $value);
662 }
663
664 protected function getString($oid) {
665 return trim(str_replace('STRING: ', '', snmpget($this->hostname, $this->community, $oid)), '"');
666 }
667}
668
669class APCPowerSwitch extends SNMPDevice {
670 protected $snmpMib = 'SNMPv2-SMI::enterprises.318';
671
672 function getPorts() {
673 $data = snmpwalk($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.3.3.1.1.2");
674 $status = snmpwalk($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.3.3.1.1.4");
675 $out = array();
676 foreach ($data as $id => $d) {
677 $out[$id + 1] = array(trim(str_replace('STRING: ', '', $d), '"'), str_replace('INTEGER: ', '', $status[$id]));
678 }
679 return $out;
680 }
681
682 function getPortStatus($id) {
683 return trim(snmpget($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.3.3.1.1.4.$id"), 'INTEGER: ');
684 }
685
686 function getPortName($id) {
687 return trim(str_replace('STRING: ', '', snmpget($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.3.3.1.1.2.$id")), '"');
688 }
689
690 function setPortName($id, $name) {
691 return snmpset($this->hostname, $this->community, "{$this->snmpMib}.1.1.4.5.2.1.3.$id", 's', $name);
692 }
693
694 function portOff($id) {
695 return $this->snmpSet("{$this->snmpMib}.1.1.12.3.3.1.1.4.$id", 'i', APC_STATUS_OFF);
696 }
697
698 function portOn($id) {
699 return $this->snmpSet("{$this->snmpMib}.1.1.12.3.3.1.1.4.$id", 'i', APC_STATUS_ON);
700 }
701
702 function portReboot($id) {
703 return $this->snmpSet("{$this->snmpMib}.1.1.12.3.3.1.1.4.$id", 'i', APC_STATUS_REBOOT);
704 }
30ad8bc4
DO
705 // rPDUIdentFirmwareRev.0 == .1.3.6.1.4.1.318.1.1.12.1.3.0 = STRING: "vN.N.N"
706 function getFWRev()
707 {
708 return preg_replace ('/^STRING: "(.+)"$/', '\\1', snmpget ($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.1.3.0"));
709 }
710 // rPDUIdentSerialNumber.0 == .1.3.6.1.4.1.318.1.1.12.1.6.0 = STRING: "XXXXXXXXXXX"
711 function getHWSerial()
712 {
713 return preg_replace ('/^STRING: "(.+)"$/', '\\1', snmpget ($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.1.6.0"));
714 }
715 // rPDUIdentModelNumber.0 == .1.3.6.1.4.1.318.1.1.12.1.5.0 = STRING: "APnnnn"
716 function getHWModel()
717 {
718 return preg_replace ('/^STRING: "(.*)"$/', '\\1', snmpget ($this->hostname, $this->community, "{$this->snmpMib}.1.1.12.1.5.0"));
719 }
38e05b77
DO
720}
721
2ffd5a2a 722?>