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