r2637 - record Cisco NX-OS
[racktables] / inc / snmp.php
CommitLineData
2ffd5a2a
DO
1<?php
2
3function doSNMPmining ($object_id, $community)
4{
7056988c 5 // FIXME: switch to message log version 2
2ffd5a2a
DO
6 $log = array();
7// IDs: http://cisco.com/en/US/products/sw/cscowork/ps2064/products_device_support_table09186a0080803bb4.html
8// 2950: http://www.cisco.com/en/US/products/hw/switches/ps628/prod_models_home.html
9// 2960: http://www.cisco.com/en/US/products/ps6406/prod_models_comparison.html
10// 2970: http://cisco.com/en/US/products/hw/switches/ps5206/products_qanda_item09186a00801b1750.shtml
11// 3500XL: http://cisco.com/en/US/products/hw/switches/ps637/products_eol_models.html
12// 3560: http://cisco.com/en/US/products/hw/switches/ps5528/products_data_sheet09186a00801f3d7f.html
13// 3750: http://cisco.com/en/US/products/hw/switches/ps5023/products_data_sheet09186a008016136f.html
14
389e01ee 15 // Cisco sysObjectID to model (not product number, i.e. image code is missing) decoder
2ffd5a2a
DO
16 $ciscomodel = array
17 (
b3f866fc 18 278 => 'WS-C3548-XL (48 Ethernet 10/100 ports and 2 10/100/1000 uplinks)',
2ffd5a2a 19 283 => 'WS-C6509-E (9-slot system)',
bbcf1dde 20 324 => 'WS-C2950-24 (24 Ethernet 10/100 ports)',
1f5d0fa0 21 325 => 'WS-C2950C-24 (24 Ethernet 10/100 ports and 2 100FX uplinks)',
2ffd5a2a
DO
22# 694 => 'WS-C2960-24TC-L (24 Ethernet 10/100 ports and 2 dual-purpose uplinks)',
23# 695 => 'WS-C2960-48TC-L (48 Ethernet 10/100 ports and 2 dual-purpose uplinks)',
24 696 => 'WS-C2960G-24TC-L (20 Ethernet 10/100/1000 ports and 4 dual-purpose uplinks)',
25 697 => 'WS-C2960G-48TC-L (44 Ethernet 10/100/1000 ports and 4 dual-purpose uplinks)',
069c186f
DO
26 716 => 'WS-C2960-24TT-L (24 Ethernet 10/100 ports and 2 10/100/1000 uplinks)',
27 717 => 'WS-C2960-48TT-L (48 Ethernet 10/100 ports and 2 10/100/1000 uplinks)',
2ffd5a2a
DO
28 527 => 'WS-C2970G-24T (24 Ethernet 10/100/1000 ports)',
29 561 => 'WS-C2970G-24TS (24 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)',
30 633 => 'WS-C3560-24TS (24 Ethernet 10/100 ports and 2 10/100/1000 SFP uplinks)',
31 634 => 'WS-C3560-48TS (48 Ethernet 10/100 ports and 4 10/100/1000 SFP uplinks)',
32 563 => 'WS-C3560-24PS (24 Ethernet 10/100 POE ports and 2 10/100/1000 SFP uplinks)',
33 564 => 'WS-C3560-48PS (48 Ethernet 10/100 POE ports and 4 10/100/1000 SFP uplinks)',
b3f866fc 34 516 => 'WS-C3750-XXPS (24 or 48 Ethernet 10/100 POE ports and 4 10/100/1000 SFP uplinks)',
2ffd5a2a
DO
35 614 => 'WS-C3560G-24PS (24 Ethernet 10/100/1000 POE ports and 4 10/100/1000 SFP uplinks)',
36 615 => 'WS-C3560G-24TS (24 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)',
37 616 => 'WS-C3560G-48PS (48 Ethernet 10/100/1000 POE ports and 4 10/100/1000 SFP uplinks)',
38 617 => 'WS-C3560G-48TS (48 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)',
b3f866fc 39 624 => 'WS-C3750G-24TS (24 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)',
2ffd5a2a
DO
40 58 => 'WS-C4503 (3-slot system)',
41 503 => '4503 (3-slot system)',
42 59 => 'WS-C4506 (6-slot system)',
43 502 => '4506 (6-slot system)',
44 626 => 'WS-C4948 (48 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)',
45 659 => 'WS-C4948-10GE (48 Ethernet 10/100/1000 ports and 2 10Gb X2 uplinks)',
3ec29bf4
DO
46 428 => 'WS-C2950G-24 (24 Ethernet 10/100 ports and 2 1000 GBIC uplinks)',
47 429 => 'WS-C2950G-48 (48 Ethernet 10/100 ports and 2 1000 GBIC uplinks)',
389e01ee 48 559 => 'WS-C2950T-48 (48 Ethernet 10/100 ports and 2 10/100/1000 uplinks)',
b3f866fc 49 920 => 'WS-CBS3032-DEL-F (16 Ethernet 10/100/1000 and up to 8 10/100/1000 uplinks)',
2ffd5a2a 50 );
389e01ee 51 // Cisco sysObjectID to Dictionary dict_key map
2ffd5a2a
DO
52 $hwtype = array
53 (
b3f866fc 54 278 => 395,
2ffd5a2a 55 283 => 148,
de89d7f3 56 324 => 380,
1f5d0fa0 57 325 => 382,
2ffd5a2a
DO
58 696 => 167,
59 697 => 166,
60 527 => 210,
61 561 => 115,
62 633 => 169,
63 634 => 170,
64 563 => 171,
65 564 => 172,
66 614 => 175,
67 615 => 173,
68 616 => 176,
69 617 => 174,
b3f866fc 70 624 => 143,
2ffd5a2a
DO
71 58 => 145,
72 503 => 145,
73 59 => 156,
74 502 => 156,
75 626 => 147,
3ec29bf4
DO
76 659 => 377,
77 428 => 389,
78 429 => 390,
389e01ee 79 559 => 387,
069c186f
DO
80 516 => 179,
81 716 => 164,
82 717 => 162,
b3f866fc
AD
83 920 => 795,
84 );
85 // Cisco portType to Dictionary dict_key map
86 $porttype = array
87 (
88 18 => 19, // 10/100BaseT => RJ-45/100Base-T
89 28 => 25, // 1000BaseSX => SC/1000Base-SX
90 31 => 440, // No Transceiver => unknown
91 61 => 24, // 10/100/1000BaseT => RJ-45/1000Base-T
2ffd5a2a
DO
92 );
93
7ddbcf59 94 $objectInfo = getObjectInfo ($object_id, FALSE);
2ffd5a2a
DO
95 $endpoints = findAllEndpoints ($object_id, $objectInfo['name']);
96 $sysName = substr (snmpget ($endpoints[0], $community, 'sysName.0'), strlen ('STRING: '));
97 $sysDescr = snmpget ($endpoints[0], $community, 'sysDescr.0');
601b058b
DO
98 // Don't generate error for agents other than IOS.
99 $sysChassi = @snmpget ($endpoints[0], $community, '1.3.6.1.4.1.9.3.6.3.0');
100 if ($sysChassi === FALSE or $sysChassi == NULL)
101 $sysChassi = '';
2ffd5a2a
DO
102 // Strip the object type, it's always string here.
103 $sysDescr = substr ($sysDescr, strlen ('STRING: '));
3ec29bf4 104 $IOSversion = ereg_replace ('^.*, Version ([^ ]+), .*$', '\\1', $sysDescr);
2ffd5a2a
DO
105 $sysChassi = str_replace ('"', '', substr ($sysChassi, strlen ('STRING: ')));
106 if (strpos ($sysDescr, 'Cisco IOS Software') === 0 or strpos ($sysDescr, 'Cisco Internetwork Operating System Software') === 0)
107 $log[] = array ('code' => 'success', 'message' => 'Seems to be a Cisco box');
108 else
109 {
110 $log[] = array ('code' => 'error', 'message' => 'No idea how to handle ' . $sysDescr);
3ec29bf4 111 return $log;
2ffd5a2a
DO
112 }
113
114 // It's a Cisco box. Go on.
115 $attrs = getAttrValues ($object_id);
116 // Only fill in attribute values, if they are not set.
117 // FIXME: this is hardcoded
118
119 if (empty ($attrs[3]['value']) && !empty ($sysName)) // FQDN
120 {
121 $error = commitUpdateAttrValue ($object_id, 3, $sysName);
122 if ($error == TRUE)
123 $log[] = array ('code' => 'success', 'message' => 'FQDN set to ' . $sysName);
124 else
125 $log[] = array ('code' => 'error', 'message' => 'Failed settig FQDN: ' . $error);
126 }
127
3ec29bf4 128 if (empty ($attrs[5]['value']) and strlen ($IOSversion) > 0) // SW version
2ffd5a2a 129 {
2ffd5a2a
DO
130 $error = commitUpdateAttrValue ($object_id, 5, $IOSversion);
131 if ($error == TRUE)
132 $log[] = array ('code' => 'success', 'message' => 'SW version set to ' . $IOSversion);
133 else
134 $log[] = array ('code' => 'error', 'message' => 'Failed settig SW version: ' . $error);
135 }
136
137 if (empty ($attrs[1]['value']) and strlen ($sysChassi) > 0) // OEM Serial #1
138 {
139 $error = commitUpdateAttrValue ($object_id, 1, $sysChassi);
140 if ($error == TRUE)
141 $log[] = array ('code' => 'success', 'message' => 'OEM S/N 1 set to ' . $sysChassi);
142 else
143 $log[] = array ('code' => 'error', 'message' => 'Failed settig OEM S/N 1: ' . $error);
144 }
145
146 if (empty ($attrs[4]['value'])) // switch OS type
3ec29bf4 147 {
2ffd5a2a
DO
148 switch (substr ($IOSversion, 0, 4))
149 {
150 case '12.2':
151 $error = commitUpdateAttrValue ($object_id, 4, 252);
152 break;
153 case '12.1':
154 $error = commitUpdateAttrValue ($object_id, 4, 251);
155 break;
156 case '12.0':
157 $error = commitUpdateAttrValue ($object_id, 4, 244);
158 break;
3ec29bf4
DO
159 default:
160 $log[] = array ('code' => 'error', 'message' => "Unknown IOS version ${IOSversion}");
161 $error = TRUE;
162 break;
2ffd5a2a 163 }
3ec29bf4
DO
164 if ($error == TRUE)
165 $log[] = array ('code' => 'success', 'message' => 'Switch OS type set to Cisco IOS ' . substr ($IOSversion, 0, 4));
166 else
167 $log[] = array ('code' => 'error', 'message' => 'Failed setting Switch OS type');
168 }
2ffd5a2a
DO
169
170 $sysObjectID = snmpget ($endpoints[0], $community, 'sysObjectID.0');
171 // Transform OID
172 $sysObjectID = substr ($sysObjectID, strlen ('OID: SNMPv2-SMI::enterprises.9.1.'));
173 if (!isset ($ciscomodel[$sysObjectID]))
174 {
175 $log[] = array ('code' => 'error', 'message' => 'Could not guess exact HW model!');
3ec29bf4 176 return $log;
2ffd5a2a
DO
177 }
178 $log[] = array ('code' => 'success', 'message' => 'HW is ' . $ciscomodel[$sysObjectID]);
179 if (empty ($attrs[2]['value']) and isset ($hwtype[$sysObjectID])) // switch HW type
180 {
181 $error = commitUpdateAttrValue ($object_id, 2, $hwtype[$sysObjectID]);
182 if ($error == TRUE)
183 $log[] = array ('code' => 'success', 'message' => 'HW type updated Ok');
184 else
185 $log[] = array ('code' => 'error', 'message' => 'Failed settig HW type: ' . $error);
186 }
187 // Now fetch ifType, ifDescr and ifPhysAddr and let model-specific code sort the data out.
188 $ifType = snmpwalkoid ($endpoints[0], $community, 'ifType');
189 $ifDescr = snmpwalkoid ($endpoints[0], $community, 'ifdescr');
190 $ifPhysAddress = snmpwalkoid ($endpoints[0], $community, 'ifPhysAddress');
191 // Combine 3 tables into 1...
192 $ifList1 = array();
193 foreach ($ifType as $key => $val)
194 {
195 list ($dummy, $ifIndex) = explode ('.', $key);
196 list ($dummy, $type) = explode (' ', $val);
197 $ifList1[$ifIndex]['type'] = $type;
198 }
199 foreach ($ifDescr as $key => $val)
200 {
201 list ($dummy, $ifIndex) = explode ('.', $key);
202 list ($dummy, $descr) = explode (' ', $val);
203 $ifList1[$ifIndex]['descr'] = trim ($descr, '"');
204 }
205 foreach ($ifPhysAddress as $key => $val)
206 {
5fc57c5b 207 $val = trim ($val);
2ffd5a2a 208 list ($dummy, $ifIndex) = explode ('.', $key);
5fc57c5b
DO
209 // NET-SNMP may return MAC addresses in one of two (?) formats depending on
210 // DISPLAY-HINT internal database. The best we can do about it is to accept both.
211 // Bug originally reported by Walery Wysotsky against openSUSE 11.0.
212 if (preg_match ('/^string: /i', $val)) // STRING: x:yy:z:xx:y:zz
213 {
214 list ($dummy, $val) = explode (' ', $val);
215 $addrbytes = explode (':', $val);
216 foreach ($addrbytes as $bidx => $bytestr)
217 if (strlen ($bytestr) == 1)
218 $addrbytes[$bidx] = '0' . $bytestr;
219 }
220 elseif (preg_match ('/^hex-string: /i', $val)) // Hex-STRING: xx yy zz xx yy zz
221 $addrbytes = explode (' ', substr ($val, -17));
222 else
223 continue; // martian format
224 $ifList1[$ifIndex]['phyad'] = implode ('', $addrbytes);
2ffd5a2a
DO
225 }
226 // ...and then reverse it inside out to make description the key.
227 $ifList2 = array();
228 foreach ($ifList1 as $ifIndex => $data)
229 {
230 $ifList2[$data['descr']]['type'] = $data['type'];
231 $ifList2[$data['descr']]['phyad'] = $data['phyad'];
232 $ifList2[$data['descr']]['idx'] = $ifIndex;
233 }
234 $newports = 0;
235 // Now we can directly pick necessary ports from the table accordingly
236 // to our known hardware model.
237 switch ($sysObjectID)
238 {
239 // FIXME: chassis edge switches often share a common naming scheme, so
240 // the sequences below have to be generalized. Let's have some duplicated
241 // code for the time being, as this is the first implementation ever.
242 case '697': // WS-C2960G-48TC-L
243 // 44 copper ports: 1X, 2X, 3X...
244 // 4 combo ports: 45, 46, 47, 48. Don't list SFP connectors atm, as it's not
245 // clear how to fit them into current Ports table structure.
246 for ($i = 1; $i <= 48; $i++)
247 {
248 $label = ($i >= 45) ? "${i}" : "${i}X";
249 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
250 if ($error == '')
251 $newports++;
252 else
253 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
bbcf1dde
AD
254 }
255 break;
1f5d0fa0
DO
256 case '325': // WS-C2950C-24
257 for ($i = 1; $i <= 26; $i++)
258 {
259 $label = "${i}X";
260 $error = commitAddPort ($object_id, 'fa0/' . $i, 24, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
261 if ($error == '')
262 $newports++;
263 else
264 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
265 }
266 break;
bbcf1dde
AD
267 case '324': // WS-C2950-24
268 for ($i = 1; $i <= 24; $i++)
269 {
270 $label = "${i}X";
271 $error = commitAddPort ($object_id, 'fa0/' . $i, 24, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
272 if ($error == '')
273 $newports++;
274 else
275 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
2ffd5a2a
DO
276 }
277 break;
b3f866fc 278 case '624': // WS-C3750-24TS
2ffd5a2a
DO
279 case '696': // WS-C2960G-24TC-L
280 // Quite similar to the above.
281 for ($i = 1; $i <= 24; $i++)
282 {
283 $label = ($i >= 21) ? "${i}" : "${i}X";
284 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
285 if ($error == '')
286 $newports++;
287 else
288 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
289 }
290 break;
069c186f 291 case '716': // WS-C2960-24TT-L
2ffd5a2a
DO
292 case '563': // WS-C3560-24PS
293 case '633': // WS-C3560-24TS
3ec29bf4 294 case '428': // WS-C2950G-24
2ffd5a2a
DO
295 for ($i = 1; $i <= 24; $i++)
296 {
297 $label = "${i}X";
298 $error = commitAddPort ($object_id, 'fa0/' . $i, 19, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
299 if ($error == '')
300 $newports++;
301 else
302 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
303 }
304 for ($i = 1; $i <= 2; $i++)
305 {
306 $label = "${i}";
307 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
308 if ($error == '')
309 $newports++;
310 else
311 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
312 }
313 break;
069c186f 314 case '717': // WS-C2960-48TT-L
3ec29bf4 315 case '429': // WS-C2950G-48
389e01ee 316 case '559': // WS-C2950T-48
3ec29bf4
DO
317 for ($i = 1; $i <= 48; $i++)
318 {
319 $label = "${i}X";
320 $error = commitAddPort ($object_id, 'fa0/' . $i, 19, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
321 if ($error == '')
322 $newports++;
323 else
324 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
325 }
326 for ($i = 1; $i <= 2; $i++)
327 {
328 $label = "${i}";
329 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
330 if ($error == '')
331 $newports++;
332 else
333 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
334 }
335 break;
b3f866fc
AD
336 case '516': // WS-C3750G-24TS OR WS-C3750-48PS
337 // FIXME: only handles 2 models of 3750, make it handle all of them
338 // see if it has 24 or 48 ports
339 $numports = substr (snmpget ($endpoints[0], $community, '.1.3.6.1.4.1.9.5.1.3.1.1.14.1'), strlen('INTEGER: '));
340
341 if ($numports == 28) // has 24 ports (+4 SFP) meaning it's a WS-C3750G-24TS
069c186f 342 {
b3f866fc
AD
343 for ($i = 1; $i <= 28; $i++)
344 {
345 $label = "${i}";
346 $error = commitAddPort ($object_id, 'gi1/0/' . $i, 24, $label, $ifList2["GigabitEthernet1/0/${i}"]['phyad']);
347 if ($error == '')
348 $newports++;
349 else
350 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
351 }
069c186f 352 }
b3f866fc 353 elseif ($numports == 52) // has 48 ports (+4 SFP) meaning it's a WS-C3750-48PS
069c186f 354 {
b3f866fc
AD
355 for ($i = 1; $i <= 48; $i++)
356 {
357 $label = "${i}X";
358 $error = commitAddPort ($object_id, 'fa1/0/' . $i, 19, $label, $ifList2["FastEthernet1/0/${i}"]['phyad']);
359 if ($error == '')
360 $newports++;
361 else
362 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
363 }
364 for ($i = 1; $i <= 4; $i++)
365 {
366 $label = "${i}";
367 $error = commitAddPort ($object_id, 'gi1/0/' . $i, 24, $label, $ifList2["GigabitEthernet1/0/${i}"]['phyad']);
368 if ($error == '')
369 $newports++;
370 else
371 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
372 }
069c186f
DO
373 }
374 break;
2ffd5a2a
DO
375 case '564': // WS-C3560-48PS
376 case '634': // WS-C3560-48TS
377 for ($i = 1; $i <= 48; $i++)
378 {
379 $label = "${i}X";
380 $error = commitAddPort ($object_id, 'fa0/' . $i, 19, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
381 if ($error == '')
382 $newports++;
383 else
384 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
385 }
386 for ($i = 1; $i <= 4; $i++)
387 {
388 $label = "${i}";
389 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
390 if ($error == '')
391 $newports++;
392 else
393 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
394 }
395 break;
396 case '614': // WS-C3560G-24PS
397 case '615': // WS-C3560G-24TS
398 case '527': // WS-C2970G-24T
399 case '561': // WS-C2970G-24TS
2ffd5a2a
DO
400 for ($i = 1; $i <= 24; $i++)
401 {
402 $label = "${i}X";
403 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
404 if ($error == '')
405 $newports++;
406 else
407 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
408 }
409 break;
410 case '616': // WS-C3560G-48PS
411 case '617': // WS-C3560G-48TS
2ffd5a2a
DO
412 for ($i = 1; $i <= 48; $i++)
413 {
414 $label = "${i}X";
415 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
416 if ($error == '')
417 $newports++;
418 else
419 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
420 }
421 break;
422 case '626': // WS-C4948
423 case '659': // WS-C4948-10GE
424 for ($i = 1; $i <= 48; $i++)
425 {
426 $label = "${i}X";
427 $error = commitAddPort ($object_id, 'gi1/' . $i, 24, $label, $ifList2["GigabitEthernet1/${i}"]['phyad']);
428 if ($error == '')
429 $newports++;
430 else
431 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
432 }
433 break;
b3f866fc
AD
434 // For modular devices we issue a separate SNMP query to determine port type,
435 // then extract blade & port numbers from the results.
436 case '58': // WS-C4503
437 case '503': // WS-C4503
438 case '59': // WS-C4506
439 case '502': // WS-C4506
2ffd5a2a 440 case '283': // WS-C6509-E
b3f866fc
AD
441 // get slot #, port # and port type using Cisco's MIB
442 $portType = snmpwalkoid ($endpoints[0], $community, '.1.3.6.1.4.1.9.5.1.4.1.1.5');
443 $ifList = array();
444 $i = 0;
445 foreach ($portType as $key => $val)
2ffd5a2a 446 {
b3f866fc
AD
447 // slot = $portIndex[8]
448 // port = $portIndex[9]
449 $portIndex = explode('.', $key);
450 $ifList[$i]['slotno'] = $portIndex[8];
451 $ifList[$i]['portno'] = $portIndex[9];
452
453 // note the Cisco port type and corresponding RackTables port type
454 list ($dummy, $cptype) = explode (' ', $val);
455 $ifList[$i]['cptype'] = $cptype;
456 if (array_key_exists($cptype, $porttype))
457 $ifList[$i]['ptype'] = $porttype[$cptype];
458 else
459 $ifList[$i]['ptype'] = null;
460 $i++;
461 }
462
463 // use Cisco's ifIndex attribute to map Cisco table to standard SNMP table
464 $ifIndex = snmpwalkoid ($endpoints[0], $community, '.1.3.6.1.4.1.9.5.1.4.1.1.11');
465 $i = 0;
466 foreach ($ifIndex as $val)
467 {
468 if (is_null($ifList[$i]['ptype']))
2ffd5a2a 469 {
b3f866fc
AD
470 $log[] = array ('code' => 'error', 'message' => 'Unknown port type: ' . $ifList[$i]['cptype']);
471 } else {
472 switch ($ifList[$i]['ptype'])
473 {
474 case 19: // fast eth
475 $prefix = 'fa';
476 break;
477 case 28: // 1000base-sx
478 case 61: // gig eth
479 $prefix = 'gi';
480 break;
481 default: // unknown, default to gig eth
482 $prefix = 'gi';
483 }
484 $pname = "{$prefix}{$ifList[$i]['slotno']}/{$ifList[$i]['portno']}";
485 $label = "slot {$ifList[$i]['slotno']} port {$ifList[$i]['portno']}";
486 list($dummy, $index) = explode(' ', $val);
487
488 // if l2address already exists in DB, nullify value so new row gets added without error
489 if (!is_null(searchByl2address($ifList1[$index]['phyad']))) $ifList1[$index]['phyad'] = null;
490
491 $error = commitAddPort ($object_id, $pname, $ifList[$i]['ptype'], $label, $ifList1[$index]['phyad']);
492 if ($error == '')
493 $newports++;
494 else
495 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $pname . ': ' . $error);
2ffd5a2a 496 }
b3f866fc
AD
497 $i++;
498 }
499 break;
500 case '278': // WS-C3548-XL
501 for ($i = 1; $i <= 48; $i++)
502 {
503 $label = "${i}X";
504 $error = commitAddPort ($object_id, 'fa0/' . $i, 19, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
2ffd5a2a
DO
505 if ($error == '')
506 $newports++;
507 else
b3f866fc
AD
508 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
509 }
510 for ($i = 1; $i <= 2; $i++)
511 {
512 $label = "${i}";
513 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
514 if ($error == '')
515 $newports++;
516 else
517 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
518 }
519 break;
520 case '920': // WS-CBS3032-DEL-F
521 for ($i = 1; $i <= 24; $i++)
522 {
523 $label = "${i}";
524 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
525 if ($error == '')
526 $newports++;
527 else
528 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
2ffd5a2a
DO
529 }
530 break;
531 default:
532 showError ("Unexpected sysObjectID '${sysObjectID}'", __FUNCTION__);
533 }
534 $error = commitAddPort ($object_id, 'con0', 29, 'console', '');
535 if ($error == '')
536 $newports++;
537 else
538 $log[] = array ('code' => 'error', 'message' => 'Failed to add console port : ' . $error);
539 if ($newports > 0)
540 $log[] = array ('code' => 'success', 'message' => "Added ${newports} new ports");
541 return $log;
542}
543
544?>