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