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