r3069 - add SQL stuff for ticket:64
[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',
56a797ef 63 'dict_key' => 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',
56a797ef 72 'dict_key' => 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',
56a797ef 81 'dict_key' => 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',
56a797ef 90 'dict_key' => 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',
56a797ef 99 'dict_key' => 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',
56a797ef 108 'dict_key' => 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',
56a797ef 117 'dict_key' => 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',
56a797ef 126 'dict_key' => 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',
56a797ef 135 'dict_key' => 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',
56a797ef
DO
144 'dict_key' => 1084,
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',
216 'dict_key' => 1077,
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
56a797ef
DO
414// This function is only kept here for reference, it will be removed after we
415// make sure, that the new code performs everything correctly.
416function doSNMPmining_old ($object_id, $community)
2ffd5a2a 417{
74aee2dc 418 return; // overhaul in progress
7056988c 419 // FIXME: switch to message log version 2
2ffd5a2a
DO
420 $log = array();
421// IDs: http://cisco.com/en/US/products/sw/cscowork/ps2064/products_device_support_table09186a0080803bb4.html
422// 2950: http://www.cisco.com/en/US/products/hw/switches/ps628/prod_models_home.html
423// 2960: http://www.cisco.com/en/US/products/ps6406/prod_models_comparison.html
424// 2970: http://cisco.com/en/US/products/hw/switches/ps5206/products_qanda_item09186a00801b1750.shtml
b1101095 425// 3030: http://www.cisco.com/en/US/products/ps6764/index.html
2ffd5a2a
DO
426// 3500XL: http://cisco.com/en/US/products/hw/switches/ps637/products_eol_models.html
427// 3560: http://cisco.com/en/US/products/hw/switches/ps5528/products_data_sheet09186a00801f3d7f.html
428// 3750: http://cisco.com/en/US/products/hw/switches/ps5023/products_data_sheet09186a008016136f.html
429
389e01ee 430 // Cisco sysObjectID to model (not product number, i.e. image code is missing) decoder
74aee2dc
DO
431 $verb_model = array
432 (
74aee2dc 433 '9.1.283' => 'WS-C6509-E (9-slot system)',
74aee2dc
DO
434 '9.1.58' => 'WS-C4503 (3-slot system)',
435 '9.1.503' => '4503 (3-slot system)',
436 '9.1.59' => 'WS-C4506 (6-slot system)',
437 '9.1.502' => '4506 (6-slot system)',
2ffd5a2a 438 );
389e01ee 439 // Cisco sysObjectID to Dictionary dict_key map
2ffd5a2a
DO
440 $hwtype = array
441 (
74aee2dc 442 '9.1.283' => 148,
74aee2dc
DO
443 '9.1.58' => 145,
444 '9.1.503' => 145,
445 '9.1.59' => 156,
446 '9.1.502' => 156,
b3f866fc
AD
447 );
448 // Cisco portType to Dictionary dict_key map
449 $porttype = array
450 (
451 18 => 19, // 10/100BaseT => RJ-45/100Base-T
452 28 => 25, // 1000BaseSX => SC/1000Base-SX
453 31 => 440, // No Transceiver => unknown
454 61 => 24, // 10/100/1000BaseT => RJ-45/1000Base-T
2ffd5a2a
DO
455 );
456
2ffd5a2a
DO
457 switch ($sysObjectID)
458 {
b3f866fc
AD
459 // For modular devices we issue a separate SNMP query to determine port type,
460 // then extract blade & port numbers from the results.
74aee2dc
DO
461 case '9.1.58': // WS-C4503
462 case '9.1.503': // WS-C4503
463 case '9.1.59': // WS-C4506
464 case '9.1.502': // WS-C4506
465 case '9.1.283': // WS-C6509-E
b3f866fc
AD
466 // get slot #, port # and port type using Cisco's MIB
467 $portType = snmpwalkoid ($endpoints[0], $community, '.1.3.6.1.4.1.9.5.1.4.1.1.5');
468 $ifList = array();
469 $i = 0;
470 foreach ($portType as $key => $val)
2ffd5a2a 471 {
b3f866fc
AD
472 // slot = $portIndex[8]
473 // port = $portIndex[9]
474 $portIndex = explode('.', $key);
475 $ifList[$i]['slotno'] = $portIndex[8];
476 $ifList[$i]['portno'] = $portIndex[9];
477
478 // note the Cisco port type and corresponding RackTables port type
479 list ($dummy, $cptype) = explode (' ', $val);
480 $ifList[$i]['cptype'] = $cptype;
481 if (array_key_exists($cptype, $porttype))
482 $ifList[$i]['ptype'] = $porttype[$cptype];
483 else
484 $ifList[$i]['ptype'] = null;
485 $i++;
486 }
487
488 // use Cisco's ifIndex attribute to map Cisco table to standard SNMP table
489 $ifIndex = snmpwalkoid ($endpoints[0], $community, '.1.3.6.1.4.1.9.5.1.4.1.1.11');
490 $i = 0;
491 foreach ($ifIndex as $val)
492 {
493 if (is_null($ifList[$i]['ptype']))
2ffd5a2a 494 {
b3f866fc
AD
495 $log[] = array ('code' => 'error', 'message' => 'Unknown port type: ' . $ifList[$i]['cptype']);
496 } else {
497 switch ($ifList[$i]['ptype'])
498 {
499 case 19: // fast eth
500 $prefix = 'fa';
501 break;
502 case 28: // 1000base-sx
503 case 61: // gig eth
504 $prefix = 'gi';
505 break;
506 default: // unknown, default to gig eth
507 $prefix = 'gi';
508 }
509 $pname = "{$prefix}{$ifList[$i]['slotno']}/{$ifList[$i]['portno']}";
510 $label = "slot {$ifList[$i]['slotno']} port {$ifList[$i]['portno']}";
511 list($dummy, $index) = explode(' ', $val);
512
513 // if l2address already exists in DB, nullify value so new row gets added without error
514 if (!is_null(searchByl2address($ifList1[$index]['phyad']))) $ifList1[$index]['phyad'] = null;
515
516 $error = commitAddPort ($object_id, $pname, $ifList[$i]['ptype'], $label, $ifList1[$index]['phyad']);
517 if ($error == '')
518 $newports++;
519 else
520 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $pname . ': ' . $error);
2ffd5a2a 521 }
b3f866fc
AD
522 $i++;
523 }
524 break;
2ffd5a2a 525 default:
4466c276 526 $log[] = array ('code' => 'error', 'message' => "Unexpected sysObjectID '${sysObjectID}'");
2ffd5a2a
DO
527 }
528 $error = commitAddPort ($object_id, 'con0', 29, 'console', '');
2ffd5a2a
DO
529}
530
74aee2dc
DO
531function updateStickerForCell ($cell, $attr_id, $new_value)
532{
533 if (!strlen ($cell['attrs'][$attr_id]['value']) && strlen ($new_value))
534 commitUpdateAttrValue ($cell['id'], $attr_id, $new_value);
535}
536
56a797ef 537function doSNMPmining ($object_id, $community)
74aee2dc
DO
538{
539 $log = emptyLog();
540 global $known_switches, $iftable_processors;
541
542 $objectInfo = spotEntity ('object', $object_id);
543 $objectInfo['attrs'] = getAttrValues ($object_id);
544 $endpoints = findAllEndpoints ($object_id, $objectInfo['name']);
545 if (count ($endpoints) == 0)
546 return oneLiner (161); // endpoint not found
547 if (count ($endpoints) > 1)
548 return oneLiner (162); // can't pick an address
549
550 if (FALSE === ($sysObjectID = snmpget ($endpoints[0], $community, 'sysObjectID.0')))
551 return oneLiner (188); // fatal SNMP failure
552 $sysObjectID = ereg_replace ('^.*(enterprises\.)([\.[:digit:]]+)$', '\\2', $sysObjectID);
56a797ef 553 $sysName = substr (snmpget ($endpoints[0], $community, 'sysName.0'), strlen ('STRING: '));
74aee2dc
DO
554 $sysDescr = substr (snmpget ($endpoints[0], $community, 'sysDescr.0'), strlen ('STRING: '));
555 $sysDescr = str_replace (array ("\n", "\r"), " ", $sysDescr); // Make it one line
556 if (!isset ($known_switches[$sysObjectID]))
557 return oneLiner (189, array ($sysObjectID)); // unknown OID
56a797ef 558 updateStickerForCell ($objectInfo, 2, $known_switches[$sysObjectID]['dict_key']);
74aee2dc 559 updateStickerForCell ($objectInfo, 3, $sysName);
56a797ef 560 $log = mergeLogs ($log, oneLiner (81, array ('generic')));
74aee2dc
DO
561 switch (1)
562 {
56a797ef 563 case preg_match ('/^9\.1\./', $sysObjectID): // Catalyst
74aee2dc
DO
564 $exact_release = ereg_replace ('^.*, Version ([^ ]+), .*$', '\\1', $sysDescr);
565 $major_line = ereg_replace ('^([[:digit:]]+\.[[:digit:]]+)[^[:digit:]].*', '\\1', $exact_release);
566 $ios_codes = array
567 (
568 '12.0' => 244,
569 '12.1' => 251,
570 '12.2' => 252,
571 );
572 updateStickerForCell ($objectInfo, 5, $exact_release);
6be06cbb
DO
573 if (array_key_exists ($major_line, $ios_codes))
574 updateStickerForCell ($objectInfo, 4, $ios_codes[$major_line]);
74aee2dc
DO
575 $sysChassi = snmpget ($endpoints[0], $community, '1.3.6.1.4.1.9.3.6.3.0');
576 if ($sysChassi !== FALSE or $sysChassi !== NULL)
577 updateStickerForCell ($objectInfo, 1, str_replace ('"', '', substr ($sysChassi, strlen ('STRING: '))));
6be06cbb 578 commitAddPort ($object_id, 'con0', 29, 'console', ''); // RJ-45 RS-232 console
56a797ef 579 $log = mergeLogs ($log, oneLiner (81, array ('catalyst-generic')));
74aee2dc 580 break;
56a797ef 581 case preg_match ('/^9\.12\.3\.1\.3\./', $sysObjectID): // Nexus
74aee2dc
DO
582 $exact_release = ereg_replace ('^.*, Version ([^ ]+), .*$', '\\1', $sysDescr);
583 $major_line = ereg_replace ('^([[:digit:]]+\.[[:digit:]]+)[^[:digit:]].*', '\\1', $exact_release);
584 $nxos_codes = array
585 (
586 '4.0' => 963,
587 '4.1' => 964,
588 );
6be06cbb
DO
589 if (array_key_exists ($major_line, $nxos_codes))
590 updateStickerForCell ($objectInfo, 4, $nxos_codes[$major_line]);
74aee2dc 591 updateStickerForCell ($objectInfo, 5, $exact_release);
56a797ef 592 $log = mergeLogs ($log, oneLiner (81, array ('nexus-generic')));
74aee2dc 593 break;
56a797ef 594 case preg_match ('/^11\.2\.3\.7\.11\./', $sysObjectID): // ProCurve
74aee2dc
DO
595 $exact_release = ereg_replace ('^.* revision ([^ ]+), .*$', '\\1', $sysDescr);
596 updateStickerForCell ($objectInfo, 5, $exact_release);
56a797ef 597 $log = mergeLogs ($log, oneLiner (81, array ('procurve-generic')));
74aee2dc 598 break;
6be06cbb
DO
599 case preg_match ('/^4526\.100\.2\./', $sysObjectID): // NETGEAR
600 commitAddPort ($object_id, 'console', 681, 'console', ''); // DB-9 RS-232 console
601 $log = mergeLogs ($log, oneLiner (81, array ('netgear-generic')));
602 break;
56a797ef 603 default: // Nortel, NETGEAR...
74aee2dc
DO
604 break;
605 }
56a797ef
DO
606 $ifInfo = array();
607 $tablename = 'ifDescr';
608 foreach (snmpwalkoid ($endpoints[0], $community, $tablename) as $oid => $value)
609 {
610 $randomindex = ereg_replace ("^.*${tablename}\.(.+)\$", '\\1', $oid);
611 $value = trim (ereg_replace ('^.+: (.+)$', '\\1', $value), '"');
612 $ifInfo[$randomindex][$tablename] = $value;
613 }
614 $tablename = 'ifPhysAddress';
615 foreach (snmpwalkoid ($endpoints[0], $community, $tablename) as $oid => $value)
616 {
617 $randomindex = ereg_replace ("^.*${tablename}\.(.+)\$", '\\1', $oid);
618 $value = trim ($value);
619 // NET-SNMP may return MAC addresses in one of two (?) formats depending on
620 // DISPLAY-HINT internal database. The best we can do about it is to accept both.
621 // Bug originally reported by Walery Wysotsky against openSUSE 11.0.
622 if (preg_match ('/^string: /i', $value)) // STRING: x:yy:z:xx:y:zz
623 {
624 list ($dummy, $value) = explode (' ', $value);
625 $addrbytes = explode (':', $value);
626 foreach ($addrbytes as $bidx => $bytestr)
627 if (strlen ($bytestr) == 1)
628 $addrbytes[$bidx] = '0' . $bytestr;
629 }
630 elseif (preg_match ('/^hex-string: /i', $value)) // Hex-STRING: xx yy zz xx yy zz
631 $addrbytes = explode (' ', substr ($value, -17));
632 else
633 continue; // martian format
634 $ifInfo[$randomindex][$tablename] = implode ('', $addrbytes);
635 }
636 // process each interface only once regardless of how many processors we have to run
637 foreach ($ifInfo as $iface)
638 foreach ($known_switches[$sysObjectID]['processors'] as $processor_name)
639 {
56a797ef
DO
640 $newname = preg_replace ($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['replacement'], $iface['ifDescr'], 1, $count);
641 if (!$count)
642 continue; // try next processor on current port
643 $newlabel = preg_replace ($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['label'], $iface['ifDescr'], 1, $count);
644 commitAddPort ($object_id, $newname, $iftable_processors[$processor_name]['dict_key'], $newlabel, $iface['ifPhysAddress']);
645 if (!$iftable_processors[$processor_name]['try_next_proc']) // done with this port
646 continue 2;
647 }
648 foreach ($known_switches[$sysObjectID]['processors'] as $processor_name)
649 $log = mergeLogs ($log, oneLiner (81, array ($processor_name)));
650 return $log;
74aee2dc
DO
651}
652
2ffd5a2a 653?>