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