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