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