function setPatchCableAmount() { commitSetPatchCableAmount(genericAssertion('id', 'uint'), genericAssertion('amount', 'uint0')); showFuncMessage(__FUNCTION__, 'OK'); }
function doGenericSNMPmining($device) { global $objectInfo, $known_devices, $iftable_processors; if (FALSE === ($sysObjectID = $device->snmpget('sysObjectID.0'))) { showFuncMessage(__FUNCTION__, 'ERR3'); // // fatal SNMP failure return; } $sysObjectID = preg_replace('/^.*(enterprises\\.|joint-iso-ccitt\\.)([\\.[:digit:]]+)$/', '\\2', $sysObjectID); if (!isset($known_devices[$sysObjectID])) { showFuncMessage(__FUNCTION__, 'ERR4', array($sysObjectID)); // unknown OID return; } $sysName = substr($device->snmpget('sysName.0'), strlen('STRING: ')); $sysDescr = substr($device->snmpget('sysDescr.0'), strlen('STRING: ')); $sysDescr = str_replace(array("\n", "\r"), " ", $sysDescr); // Make it one line showSuccess($known_devices[$sysObjectID]['text']); updateStickerForCell($objectInfo, 2, $known_devices[$sysObjectID]['dict_key']); // HW type updateStickerForCell($objectInfo, 3, $sysName); detectSoftwareType($objectInfo, $sysDescr); switch (1) { case preg_match('/^9\\.1\\./', $sysObjectID): // Catalyst w/one AC port // Catalyst w/one AC port case preg_match('/^9\\.5\\.18/', $sysObjectID): $exact_release = preg_replace('/^.*, Version ([^ ]+), .*$/', '\\1', $sysDescr); $major_line = preg_replace('/^([[:digit:]]+\\.[[:digit:]]+)[^[:digit:]].*/', '\\1', $exact_release); $ios_codes = array('12.0' => 244, '12.1' => 251, '12.2' => 252, '15.0' => 1901, '15.1' => 2082); updateStickerForCell($objectInfo, 5, $exact_release); if (array_key_exists($major_line, $ios_codes)) { updateStickerForCell($objectInfo, 4, $ios_codes[$major_line]); } $sysChassi = $device->snmpget('1.3.6.1.4.1.9.3.6.3.0'); if ($sysChassi !== FALSE or $sysChassi !== NULL) { updateStickerForCell($objectInfo, 1, str_replace('"', '', substr($sysChassi, strlen('STRING: ')))); } // some models have the console port located on a module instead of the chassis $no_console = array('9.1.222', '9.1.283', '9.1.503'); if (!in_array($sysObjectID, $no_console)) { checkPIC('1-29'); commitAddPort($objectInfo['id'], 'con0', '1-29', 'console', ''); // RJ-45 RS-232 console } if (preg_match('/Cisco IOS Software, C2600/', $sysDescr)) { commitAddPort($objectInfo['id'], 'aux0', '1-29', 'auxillary', ''); } // RJ-45 RS-232 aux port $dual_ac = array('9.1.222', '9.1.283', '9.1.956'); if (in_array($sysObjectID, $dual_ac)) { // models with two AC inputs checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in-1', '1-16', 'AC1', ''); commitAddPort($objectInfo['id'], 'AC-in-2', '1-16', 'AC2', ''); } elseif ($sysObjectID != '9.1.749' and $sysObjectID != '9.1.920') { // assume the rest have one AC input, but exclude blade devices checkPIC('1-16'); // AC input commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); } break; case preg_match('/^9\\.5\\.42/', $sysObjectID): // Catalyst 2948 running CatOS // Catalyst 2948 running CatOS case preg_match('/^9\\.6\\.1\\./', $sysObjectID): // Cisco SF series // Cisco SF series case preg_match('/^2011\\.2\\.239?\\./', $sysObjectID): // Huawei checkPIC('1-681'); commitAddPort($objectInfo['id'], 'con0', '1-681', 'console', ''); // DB-9 RS-232 console checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^9\\.12\\.3\\.1\\.3\\./', $sysObjectID): // Nexus $exact_release = preg_replace('/^.*, Version ([^ ]+), .*$/', '\\1', $sysDescr); $major_line = preg_replace('/^([[:digit:]]+\\.[[:digit:]]+)[^[:digit:]].*/', '\\1', $exact_release); $nxos_codes = array('4.0' => 963, '4.1' => 964); if (array_key_exists($major_line, $nxos_codes)) { updateStickerForCell($objectInfo, 4, $nxos_codes[$major_line]); } updateStickerForCell($objectInfo, 5, $exact_release); $sysChassi = $device->snmpget('1.3.6.1.2.1.47.1.1.1.1.11.149'); if ($sysChassi !== FALSE or $sysChassi !== NULL) { updateStickerForCell($objectInfo, 1, str_replace('"', '', substr($sysChassi, strlen('STRING: ')))); } checkPIC('1-29'); commitAddPort($objectInfo['id'], 'con0', '1-29', 'console', ''); // RJ-45 RS-232 console checkPIC('1-16'); // AC input commitAddPort($objectInfo['id'], 'AC-in-1', '1-16', 'AC1', ''); commitAddPort($objectInfo['id'], 'AC-in-2', '1-16', 'AC2', ''); break; case preg_match('/^11\\.2\\.3\\.7\\.11\\.(\\d+)$/', $sysObjectID, $matches): // ProCurve $console_per_product = array(33 => '1-29', 63 => '1-29', 78 => '1-29', 79 => '1-29', 80 => '1-29', 84 => '1-29', 86 => '1-29', 87 => '1-29', 94 => '1-29', 95 => '1-29', 154 => '1-29', 19 => '1-681', 31 => '1-681', 34 => '1-681', 58 => '1-681', 59 => '1-681'); if (array_key_exists($matches[1], $console_per_product)) { checkPIC($console_per_product[$matches[1]]); commitAddPort($objectInfo['id'], 'console', $console_per_product[$matches[1]], 'console', ''); } $oom_per_product = array(33 => '1-24'); if (array_key_exists($matches[1], $oom_per_product)) { checkPIC($oom_per_product[$matches[1]]); commitAddPort($objectInfo['id'], 'mgmt', $oom_per_product[$matches[1]], 'mgmt', ''); } checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); $exact_release = preg_replace('/^.* revision ([^ ]+), .*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $exact_release); break; case preg_match('/^2636\\.1\\.1\\.1\\.2\\.3(0|1)/', $sysObjectID): // Juniper EX3200/EX4200 $sw_version = preg_replace('/^.*, kernel JUNOS ([^ ]+).*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $sw_version); // one RJ-45 RS-232 and one AC port (it could be DC, but chances are it's AC) checkPIC('1-29'); commitAddPort($objectInfo['id'], 'con', '1-29', 'CON', ''); // RJ-45 RS-232 console checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); // Juniper uses the same sysObjectID for multiple HW models, override if necessary if (preg_match('/^Juniper Networks, Inc. ex3200-48t internet router/', $sysDescr)) { updateStickerForCell($objectInfo, 2, 902); } if (preg_match('/^Juniper Networks, Inc. ex4200-48t internet router/', $sysDescr)) { updateStickerForCell($objectInfo, 2, 907); } break; case preg_match('/^1991\\.1\\.3\\.53\\.1\\.2$/', $sysObjectID): // TurboIron 24X // TurboIron 24X case preg_match('/^2636\\.1\\.1\\.1\\.2\\./', $sysObjectID): // Juniper checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', 'console', ''); // DB-9 RS-232 console break; case preg_match('/^1991\\.1\\.3\\.45\\./', $sysObjectID): // snFGSFamily // snFGSFamily case preg_match('/^1991\\.1\\.3\\.46\\./', $sysObjectID): // snFLSFamily // snFLSFamily case preg_match('/^1991\\.1\\.3\\.54\\.2\\.4\\.1\\.1$/', $sysObjectID): // FCX 648 $exact_release = preg_replace('/^.*, IronWare Version ([^ ]+) .*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $exact_release); # FOUNDRY-SN-AGENT-MIB::snChasSerNum.0 $sysChassi = $device->snmpget('enterprises.1991.1.1.1.1.2.0'); if ($sysChassi !== FALSE or $sysChassi !== NULL) { updateStickerForCell($objectInfo, 1, str_replace('"', '', substr($sysChassi, strlen('STRING: ')))); } # Type of uplink module installed. # table: FOUNDRY-SN-AGENT-MIB::snAgentBrdMainBrdDescription # Possible part numbers are: # FGS-1XG1XGC (one fixed CX4 port) # FGS-2XGC (two fixed CX4 ports) # FGS-2XG (two XFP slots) # And for FLS result (which is not handled here) would be: # 1991.1.1.2.2.1.1.2.1 = STRING: "FLS-24G 24-port Management Module" # 1991.1.1.2.2.1.1.2.3 = STRING: "FLS-1XG 1-port 10G Module (1-XFP)" # 1991.1.1.2.2.1.1.2.4 = STRING: "FLS-1XG 1-port 10G Module (1-XFP)" # (assuming, that the device has 2 XFP modules in slots 3 and 4). foreach ($device->snmpwalkoid('enterprises.1991.1.1.2.2.1.1.2') as $module_raw) { if (preg_match('/^STRING: "(FGS-1XG1XGC|FGS-2XGC) /i', $module_raw)) { $iftable_processors['fgs-uplinks']['dict_key'] = '1-40'; // CX4 break; } } # AC inputs # table: FOUNDRY-SN-AGENT-MIB::snChasPwrSupplyDescription # "Power supply 1 " # "Power supply 2 " foreach ($device->snmpwalkoid('enterprises.1991.1.1.1.2.1.1.2') as $PSU_raw) { $count = 0; $PSU_cooked = trim(preg_replace('/^string: "(.+)"$/i', '\\1', $PSU_raw, 1, $count)); if ($count) { checkPIC('1-16'); commitAddPort($objectInfo['id'], $PSU_cooked, '1-16', '', ''); } } # fixed console port checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', 'console', ''); // DB-9 RS-232 console break; case preg_match('/^1916\\.2\\./', $sysObjectID): // Extreme Networks Summit $xos_release = preg_replace('/^ExtremeXOS version ([[:digit:]]+)\\..*$/', '\\1', $sysDescr); $xos_codes = array('10' => 1350, '11' => 1351, '12' => 1352); if (array_key_exists($xos_release, $xos_codes)) { updateStickerForCell($objectInfo, 4, $xos_codes[$xos_release]); } checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', 'console', ''); // DB-9 RS-232 checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^6027\\.1\\./', $sysObjectID): # Force10 commitAddPort($objectInfo['id'], 'aux0', '1-29', 'RS-232', ''); // RJ-45 RS-232 console $m = array(); if (preg_match('/Force10 Application Software Version: ([\\d\\.]+)/', $sysDescr, $m)) { updateStickerForCell($objectInfo, 5, $m[1]); $ftos_release = preg_replace('/^([678])\\..+$/', '\\1', $m[1]); $ftos_codes = array('6' => 1592, '7' => 1593, '8' => 1594); if (array_key_exists($ftos_release, $ftos_codes)) { updateStickerForCell($objectInfo, 4, $ftos_codes[$ftos_release]); } } # F10-S-SERIES-CHASSIS-MIB::chStackUnitSerialNumber.1 $serialNo = $device->snmpget('enterprises.6027.3.10.1.2.2.1.12.1'); # F10-S-SERIES-CHASSIS-MIB::chSysPowerSupplyType.1.1 if ($device->snmpget('enterprises.6027.3.10.1.2.3.1.3.1.1') == 'INTEGER: 1') { checkPIC('1-16'); commitAddPort($objectInfo['id'], 'PSU0', '1-16', 'PSU0', ''); } # F10-S-SERIES-CHASSIS-MIB::chSysPowerSupplyType.1.2 if ($device->snmpget('enterprises.6027.3.10.1.2.3.1.3.1.2') == 'INTEGER: 1') { checkPIC('1-16'); commitAddPort($objectInfo['id'], 'PSU1', '1-16', 'PSU1', ''); } if (strlen($serialNo)) { updateStickerForCell($objectInfo, 1, str_replace('"', '', substr($serialNo, strlen('STRING: ')))); } break; case preg_match('/^171\\.10\\.63\\.8/', $sysObjectID): // D-Link DES-3052 // D-Link DES-3052 case preg_match('/^202\\.20\\./', $sysObjectID): // SMC TigerSwitch // SMC TigerSwitch case preg_match('/^674\\.10895\\.4/', $sysObjectID): // Dell PowerConnect // Dell PowerConnect case preg_match('/^674\\.10895\\.300(3|4|7|9)/', $sysObjectID): case preg_match('/^674\\.10895\\.301(0|4|7|9)/', $sysObjectID): case preg_match('/^674\\.10895\\.302(0|1|8)/', $sysObjectID): case preg_match('/^3955\\.6\\.1\\.20(24|48)\\.1/', $sysObjectID): // Linksys // Linksys case preg_match('/^3955\\.6\\.50(24|48)/', $sysObjectID): // Linksys // Linksys case preg_match('/^4526\\.100\\./', $sysObjectID): // NETGEAR (with console) // NETGEAR (with console) case preg_match('/^11863\\.1\\.1\\.1/', $sysObjectID): // TPLink // TPLink case preg_match('/^11863\\.6\\.10\\.58/', $sysObjectID): // one DB-9 RS-232 and one AC port checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', '', ''); // DB-9 RS-232 checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^388\\.18/', $sysObjectID): // Motorola RFS 4000 // one RJ-45 RS-232 and one AC port checkPIC('1-29'); commitAddPort($objectInfo['id'], 'console', '1-29', 'console', ''); checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^207\\.1\\.14\\./', $sysObjectID): // Allied Telesyn // one RJ-45 RS-232 and two AC ports checkPIC('1-29'); commitAddPort($objectInfo['id'], 'console', '1-29', 'console', ''); checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in-1', '1-16', 'AC1', ''); commitAddPort($objectInfo['id'], 'AC-in-2', '1-16', 'AC2', ''); break; case preg_match('/^674\\.10895\\.3000/', $sysObjectID): // one DB-9 RS-232, one 100Mb OOB mgmt, and one AC port checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', '', ''); // DB-9 RS-232 checkPIC('1-19'); commitAddPort($objectInfo['id'], 'mgmt', '1-19', '', ''); checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^43\\.1\\.16\\.4\\.3\\./', $sysObjectID): // 3Com $sw_version = preg_replace('/^.* Version 3Com OS ([^ ]+).*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $sw_version); // one RJ-45 RS-232 and one AC port checkPIC('1-29'); commitAddPort($objectInfo['id'], 'console', '1-29', '', ''); // RJ-45 RS-232 console checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^10977\\.11825\\.11833\\.97\\.25451\\.12800\\.100\\.4\\.4/', $sysObjectID): // Netgear $sw_version = preg_replace('/^.* V([^ ]+).*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $sw_version); // one AC port, no console checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^171\\.10\\.76\\.10/', $sysObjectID): // D-Link DGS-1210-24 // D-Link DGS-1210-24 case preg_match('/^207\\.1\\.4\\./', $sysObjectID): // Allied Telesyn AT-GS950/24 // Allied Telesyn AT-GS950/24 case preg_match('/^4526\\.100\\.4\\.(6|10)/', $sysObjectID): // NETGEAR (without console) // one AC port, no console checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^30065\\.1\\.3011\\./', $sysObjectID): // Arista checkPIC('1-29'); commitAddPort($objectInfo['id'], 'console', '1-29', 'IOIOI', ''); $sw_version = preg_replace('/^Arista Networks EOS version (.+) running on .*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $sw_version); if (strlen($serialNo = $device->snmpget('mib-2.47.1.1.1.1.11.1'))) { # entPhysicalSerialNumber.1 updateStickerForCell($objectInfo, 1, str_replace('"', '', substr($serialNo, strlen('STRING: ')))); } break; case preg_match('/^119\\.1\\.203\\.2\\.2\\./', $sysObjectID): # NEC checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console 0', '1-681', 'console', ''); checkPIC('1-16'); commitAddPort($objectInfo['id'], 'PS1', '1-16', '', ''); commitAddPort($objectInfo['id'], 'PS2', '1-16', '', ''); break; case preg_match('/^26543\\.1\\.7\\./', $sysObjectID): # IBM checkPIC('1-29'); commitAddPort($objectInfo['id'], 'console', '1-29', '', ''); # RJ-45 RS-232 console break; default: // Nortel... break; } if (isset($known_devices[$sysObjectID]['modular'])) { // this is a modular device // TODO: put the entire mining operation inside a single transaction (not possible now because commitAddPort() LOCKs/UNLOCKs the Port table which auto-commits any open transactions) global $snmp_data; $snmp_data = array(); foreach ($device->snmpwalkoid('mib-2.47.1.1.1.1.4') as $raw_key => $raw_value) { $key = substr($raw_key, strlen('SNMPv2-SMI::mib-2.47.1.1.1.1.4.')); $value = substr($raw_value, strlen('INTEGER: ')); $snmp_data['entPhysicalContainedIn'][$key] = $value; } foreach ($device->snmpwalkoid('mib-2.47.1.1.1.1.2') as $raw_key => $raw_value) { $key = substr($raw_key, strlen('SNMPv2-SMI::mib-2.47.1.1.1.1.2.')); $value = str_ireplace(array('STRING: ', '"'), '', $raw_value); $snmp_data['entPhysicalDescr'][$key] = $value; } foreach ($device->snmpwalkoid('mib-2.47.1.1.1.1.7') as $raw_key => $raw_value) { $key = substr($raw_key, strlen('SNMPv2-SMI::mib-2.47.1.1.1.1.7.')); $value = str_ireplace(array('STRING: ', '"'), '', $raw_value); $snmp_data['entPhysicalName'][$key] = $value; } foreach ($device->snmpwalkoid('mib-2.47.1.1.1.1.13') as $raw_key => $raw_value) { $key = substr($raw_key, strlen('SNMPv2-SMI::mib-2.47.1.1.1.1.13.')); $value = str_ireplace(array('STRING: ', '"'), '', $raw_value); $snmp_data['entPhysicalModelName'][$key] = $value; } foreach ($device->snmpwalkoid('mib-2.47.1.1.1.1.11') as $raw_key => $raw_value) { $key = substr($raw_key, strlen('SNMPv2-SMI::mib-2.47.1.1.1.1.11.')); $value = str_ireplace(array('STRING: ', '"'), '', $raw_value); $snmp_data['entPhysicalSerialNum'][$key] = $value; } updateStickerForCell($objectInfo, 1, $snmp_data['entPhysicalSerialNum'][1]); // OEM S/N 1, safe to assume that the chassis is the first array element foreach ($device->snmpwalkoid('mib-2.47.1.1.1.1.9') as $raw_key => $raw_value) { $key = substr($raw_key, strlen('SNMPv2-SMI::mib-2.47.1.1.1.1.9.')); $value = str_ireplace(array('STRING: ', '"'), '', $raw_value); $snmp_data['entPhysicalFirmwareRev'][$key] = $value; } foreach ($device->snmpwalkoid('ifPhysAddress') as $raw_key => $raw_value) { $key = substr($raw_key, strlen('IF-MIB::ifPhysAddress.')); $value = str_ireplace(array('STRING: ', '"'), '', $raw_value); if (preg_match('/^[0-9a-f]{1,2}(:[0-9a-f]{1,2}){5}/i', $value)) { $addrbytes = explode(':', $value); foreach ($addrbytes as $bidx => $bytestr) { if (strlen($bytestr) == 1) { $addrbytes[$bidx] = '0' . $bytestr; } } } elseif (preg_match('/^[0-9a-f]{1,2}( [0-9a-f]{1,2}){5}/i', $value)) { // xx yy zz xx yy zz $addrbytes = explode(' ', substr($value, -17)); } elseif (preg_match('/22[0-9a-f]{12}22$/', bin2hex($value))) { // "??????" $addrbytes = array(substr(bin2hex($value), -14, 12)); } else { break; } // martian format // if this port's MAC is already assigned to another port, mark it as an empty string instead of causing a conflict $mac = implode('', $addrbytes); $snmp_data['ifPhysAddress'][$key] = (array_key_exists('ifPhysAddress', $snmp_data) and in_array($mac, $snmp_data['ifPhysAddress'])) ? '' : $mac; } // map entPhysicalIndex to ifIndex for MAC addresses association // first try to use entAliasMappingIdentifier (some devices don't support it) if ($entToIfMapping_raw = @$device->snmpwalkoid('mib-2.47.1.3.2.1.2')) { foreach ($entToIfMapping_raw as $key => $value) { // find the entID and map it to the ifID $e_array = explode('.', $key); $e_index = count($e_array) - 2; $eid = $e_array[$e_index]; $iid = substr($value, strrpos($value, '.') + 1); $snmp_data['entToIfMapping'][$eid] = $iid; } } else { // entAliasMappingIdentifier isn't available, use entPhysicalName $ifName = array(); foreach ($device->snmpwalkoid('ifName') as $raw_key => $raw_value) { $key = substr($raw_key, strlen('IF-MIB::ifName.')); $value = str_ireplace(array('STRING: ', '"'), '', $raw_value); $ifName[$key] = $value; } // query entPhysicalClass and note which entries which are ports foreach ($device->snmpwalkoid('mib-2.47.1.1.1.1.5') as $raw_key => $raw_value) { if (substr($raw_value, strlen('INTEGER: ')) == 10) { $snmp_data['entPhysicalPorts'][] = substr($raw_key, strlen('SNMPv2-SMI::mib-2.47.1.1.1.1.5.')); } } // do the mapping, but only for ports foreach ($snmp_data['entPhysicalName'] as $key => $value) { if (in_array($key, $snmp_data['entPhysicalPorts'])) { $snmp_data['entToIfMapping'][$key] = array_search($value, $ifName); } } } addModules(1, $objectInfo['id']); } else { // this is not a modular device $ifDescr_tablename = isset($known_devices[$sysObjectID]['ifDescrOID']) ? $known_devices[$sysObjectID]['ifDescrOID'] : 'ifDescr'; foreach (array_keys($known_devices[$sysObjectID]['processors']) as $pkey) { if (!array_key_exists($known_devices[$sysObjectID]['processors'][$pkey], $iftable_processors)) { showWarning('processor "' . $known_devices[$sysObjectID]['processors'][$pkey] . '" not found'); unset($known_devices[$sysObjectID]['processors'][$pkey]); } } $ifInfo = array(); foreach ($device->snmpwalkoid($ifDescr_tablename) as $oid => $value) { $randomindex = preg_replace("/^.*{$ifDescr_tablename}\\.(.+)\$/", '\\1', $oid); $value = trim(preg_replace('/^[^:]+: (.+)$/', '\\1', $value), '"'); $ifInfo[$randomindex]['ifDescr'] = $value; } foreach ($device->snmpwalkoid('ifPhysAddress') as $oid => $value) { $randomindex = preg_replace("/^.*ifPhysAddress\\.(.+)\$/", '\\1', $oid); $value = trim($value); // NET-SNMP may return MAC addresses in one of two (?) formats depending on // DISPLAY-HINT internal database. The best we can do about it is to accept both. // Bug originally reported by Walery Wysotsky against openSUSE 11.0. if (preg_match('/^string: [0-9a-f]{1,2}(:[0-9a-f]{1,2}){5}/i', $value)) { list($dummy, $value) = explode(' ', $value); $addrbytes = explode(':', $value); foreach ($addrbytes as $bidx => $bytestr) { if (strlen($bytestr) == 1) { $addrbytes[$bidx] = '0' . $bytestr; } } } elseif (preg_match('/^hex-string:( [0-9a-f]{2}){6}/i', $value)) { // Hex-STRING: xx yy zz xx yy zz $addrbytes = explode(' ', substr($value, -17)); } elseif (preg_match('/22[0-9a-f]{12}22$/', bin2hex($value))) { // STRING: "??????" $addrbytes = array(substr(bin2hex($value), -14, 12)); } else { continue; } // martian format $ifInfo[$randomindex]['ifPhysAddress'] = implode('', $addrbytes); } // process each interface only once regardless of how many processors we have to run foreach ($ifInfo as $iface) { foreach ($known_devices[$sysObjectID]['processors'] as $processor_name) { $newname = preg_replace($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['replacement'], $iface['ifDescr'], 1, $count); if ($newname === NULL) { showError('PCRE pattern error, terminating'); break 2; } if (!$count) { continue; } // try next processor on current port $newlabel = preg_replace($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['label'], $iface['ifDescr'], 1, $count); checkPIC($iftable_processors[$processor_name]['dict_key']); commitAddPort($objectInfo['id'], $newname, $iftable_processors[$processor_name]['dict_key'], $newlabel, $iface['ifPhysAddress']); if (!$iftable_processors[$processor_name]['try_next_proc']) { // done with this port continue 2; } } } } // No failure up to this point, thus leave current tab for the "Ports" one. return buildRedirectURL(NULL, 'ports'); }
function setPortVLAN() { assertUIntArg('portcount'); try { $data = getSwitchVLANs($_REQUEST['object_id']); } catch (RTGatewayError $re) { return showFuncMessage(__FUNCTION__, 'ERR', array($re->getMessage())); } list($vlanlist, $portlist) = $data; // Here we just build up 1 set command for the gateway with all of the ports // included. The gateway is expected to filter unnecessary changes silently // and to provide a list of responses with either error or success message // for each of the rest. $nports = $_REQUEST['portcount']; $prefix = 'set '; $setcmd = ''; for ($i = 0; $i < $nports; $i++) { genericAssertion('portname_' . $i, 'string'); genericAssertion('vlanid_' . $i, 'string'); if ($_REQUEST['portname_' . $i] != $portlist[$i]['portname']) { throw new InvalidRequestArgException('portname_' . $i, $_REQUEST['portname_' . $i], 'expected to be ' . $portlist[$i]['portname']); } if ($_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] || $portlist[$i]['vlanid'] == 'TRUNK') { continue; } $portname = $_REQUEST['portname_' . $i]; $oldvlanid = $portlist[$i]['vlanid']; $newvlanid = $_REQUEST['vlanid_' . $i]; if (!permitted(NULL, NULL, NULL, array(array('tag' => '$fromvlan_' . $oldvlanid), array('tag' => '$vlan_' . $oldvlanid))) or !permitted(NULL, NULL, NULL, array(array('tag' => '$tovlan_' . $newvlanid), array('tag' => '$vlan_' . $newvlanid)))) { showOneLiner(159, array($portname, $oldvlanid, $newvlanid)); continue; } $setcmd .= $prefix . $portname . '=' . $newvlanid; $prefix = ';'; } // Feed the gateway and interpret its (non)response. if ($setcmd == '') { showOneLiner(201); } else { try { setSwitchVLANs($_REQUEST['object_id'], $setcmd); // shows messages by itself } catch (RTGatewayError $e) { showFuncMessage(__FUNCTION__, 'ERR', array($e->getMessage())); } } }
function importFingData() { $net = spotEntity('ipv4net', getBypassValue()); assertUIntArg('addrcount'); $nbad = $ngood = 0; for ($i = 1; $i <= $_REQUEST['addrcount']; $i++) { $inputname = "import_{$i}"; if (!isCheckSet($inputname)) { continue; } $ip_bin = assertIPv4Arg("addr_{$i}"); assertStringArg("descr_{$i}", TRUE); assertStringArg("rsvd_{$i}"); // Non-existent addresses will not have this argument set in request. $rsvd = 'no'; if ($_REQUEST["rsvd_{$i}"] == 'yes') { $rsvd = 'yes'; } try { if (!ip_in_range($ip_bin, $net)) { throw new InvalidArgException('ip_bin', $ip_bin); } updateAddress($ip_bin, $_REQUEST["descr_{$i}"], $rsvd); $ngood++; } catch (RackTablesError $e) { $nbad++; } } if (!$nbad) { showFuncMessage(__FUNCTION__, 'OK', array($ngood)); } else { showFuncMessage(__FUNCTION__, 'ERR', array($nbad, $ngood)); } }
function updateObjectAllocation() { global $remote_username, $sic; if (!isset($_REQUEST['got_atoms'])) { unset($_GET['page']); unset($_GET['tab']); unset($_GET['op']); unset($_POST['page']); unset($_POST['tab']); unset($_POST['op']); return buildRedirectURL(NULL, NULL, $_REQUEST); } $object_id = getBypassValue(); $rf1 = $_REQUEST['rfid']; if (isset($_REQUEST['rfid'])) { // $rf1 = 1000000;//$_REQUEST['rfid']; $result = usePreparedSelectBlade("SELECT object_id FROM objecttorf WHERE rf_id = ?", array($rf1)); $row = $result->fetch(PDO::FETCH_ASSOC); if (isset($row)) { $object_id = $row['object_id']; } //получить значение из базы где rf1=njvenj //showError ('Permission deniedddddddd, "' . $object_id . '" left unchanged'); } $changecnt = 0; // Get a list of all of this object's parents, // then trim the list to only include parents that are racks $objectParents = getEntityRelatives('parents', 'object', $object_id); $parentRacks = array(); foreach ($objectParents as $parentData) { if ($parentData['entity_type'] == 'rack') { $parentRacks[] = $parentData['entity_id']; } } $workingRacksData = array(); foreach ($_REQUEST['rackmulti'] as $cand_id) { if (!isset($workingRacksData[$cand_id])) { $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); $workingRacksData[$cand_id] = $rackData; } // It's zero-U mounted to this rack on the form, but not in the DB. Mount it. if (isset($_REQUEST["zerou_{$cand_id}"]) && !in_array($cand_id, $parentRacks)) { $changecnt++; commitLinkEntities('rack', $cand_id, 'object', $object_id); } // It's not zero-U mounted to this rack on the form, but it is in the DB. Unmount it. if (!isset($_REQUEST["zerou_{$cand_id}"]) && in_array($cand_id, $parentRacks)) { $changecnt++; commitUnlinkEntities('rack', $cand_id, 'object', $object_id); } } foreach ($workingRacksData as &$rd) { applyObjectMountMask($rd, $object_id); } $oldMolecule = getMoleculeForObject($object_id); foreach ($workingRacksData as $rack_id => $rackData) { if (!processGridForm($rackData, 'F', 'T', $object_id)) { continue; } $changecnt++; // Reload our working copy after form processing. $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); applyObjectMountMask($rackData, $object_id); $workingRacksData[$rack_id] = $rackData; } if ($changecnt) { // Log a record. $newMolecule = getMoleculeForObject($object_id); usePreparedInsertBlade('MountOperation', array('object_id' => $object_id, 'old_molecule_id' => count($oldMolecule) ? createMolecule($oldMolecule) : NULL, 'new_molecule_id' => count($newMolecule) ? createMolecule($newMolecule) : NULL, 'user_name' => $remote_username, 'comment' => empty($sic['comment']) ? NULL : $sic['comment'])); } showFuncMessage(__FUNCTION__, 'OK', array($changecnt)); }
function importDPData() { global $sic, $dbxlink; assertUIntArg('nports'); $nignored = $ndone = 0; for ($i = 0; $i < $sic['nports']; $i++) { if (array_key_exists("do_{$i}", $sic)) { $params = array(); assertStringArg("ports_{$i}"); foreach (explode(',', $_REQUEST["ports_{$i}"]) as $item) { $pair = explode(':', $item); if (count($pair) != 2) { continue; } $params[$pair[0]] = $pair[1]; } if (!isset($params['a_id']) || !isset($params['b_id']) || !intval($params['a_id']) || !intval($params['b_id'])) { throw new InvalidArgException("ports_{$i}", $_REQUEST["ports_{$i}"], "can not unpack port ids"); } $porta = getPortInfo($params['a_id']); $portb = getPortInfo($params['b_id']); if ($porta['linked'] or $portb['linked'] or $porta['object_id'] != $sic['object_id'] and $portb['object_id'] != $sic['object_id']) { $nignored++; continue; } $oif_a = intval(@$params['a_oif']); // these parameters are optional $oif_b = intval(@$params['b_oif']); $dbxlink->beginTransaction(); try { if ($oif_a) { commitUpdatePortOIF($params['a_id'], $oif_a); $porta['oif_id'] = $oif_a; } if ($oif_b) { commitUpdatePortOIF($params['b_id'], $oif_b); $portb['oif_id'] = $oif_b; } if (arePortsCompatible($porta, $portb)) { linkPorts($params['a_id'], $params['b_id']); $ndone++; $dbxlink->commit(); } else { $dbxlink->rollback(); $nignored++; } } catch (RTDatabaseError $e) { $dbxlink->rollBack(); $nignored++; } } } return showFuncMessage(__FUNCTION__, 'OK', array($nignored, $ndone)); }
function updateNodePingCheck() { assertUIntArg('check_id'); assertUIntArg('account_id'); assertStringArg('np_check_id'); $check = getNodePingCheck($_REQUEST['check_id']); $account = getNodePingAccount($_REQUEST['account_id']); $nodeping = new NodePingClient(array('token' => $account['token'])); $np_check = $nodeping->check->get(array('id' => $_REQUEST['np_check_id'], 'limit' => 1, 'clean' => true)); if (isset($check['error'])) { return showFuncMessage(__FUNCTION__, 'ERR1', array('Error: ' . $np_check['error'])); } usePreparedUpdateBlade('NodePingCheck', array('account_id' => $_REQUEST['account_id'], 'np_check_id' => $_REQUEST['np_check_id'], 'label' => $np_check['label'], 'type' => $np_check['type'], 'target' => $np_check['parameters']['target'], 'check_interval' => $np_check['interval']), array('id' => $_REQUEST['check_id'])); return showFuncMessage(__FUNCTION__, 'OK', array(htmlspecialchars($np_check['label']))); }
function doSwitchSNMPmining($objectInfo, $device) { global $known_switches, $iftable_processors; if (FALSE === ($sysObjectID = $device->snmpget('sysObjectID.0'))) { return showFuncMessage(__FUNCTION__, 'ERR3'); } // // fatal SNMP failure $sysObjectID = preg_replace('/^.*(enterprises\\.|joint-iso-ccitt\\.)([\\.[:digit:]]+)$/', '\\2', $sysObjectID); $sysName = substr($device->snmpget('sysName.0'), strlen('STRING: ')); $sysDescr = substr($device->snmpget('sysDescr.0'), strlen('STRING: ')); $sysDescr = str_replace(array("\n", "\r"), " ", $sysDescr); // Make it one line $ifDescr_tablename = isset($known_switches[$sysObjectID]['ifDescrOID']) ? $known_switches[$sysObjectID]['ifDescrOID'] : 'ifDescr'; if (!isset($known_switches[$sysObjectID])) { return showFuncMessage(__FUNCTION__, 'ERR4', array($sysObjectID)); } // unknown OID showSuccess($known_switches[$sysObjectID]['text']); foreach (array_keys($known_switches[$sysObjectID]['processors']) as $pkey) { if (!array_key_exists($known_switches[$sysObjectID]['processors'][$pkey], $iftable_processors)) { showWarning('processor "' . $known_switches[$sysObjectID]['processors'][$pkey] . '" not found'); unset($known_switches[$sysObjectID]['processors'][$pkey]); } } updateStickerForCell($objectInfo, 2, $known_switches[$sysObjectID]['dict_key']); updateStickerForCell($objectInfo, 3, $sysName); switch (1) { case preg_match('/^9\\.1\\./', $sysObjectID): // Catalyst w/one AC port $exact_release = preg_replace('/^.*, Version ([^ ]+), .*$/', '\\1', $sysDescr); $major_line = preg_replace('/^([[:digit:]]+\\.[[:digit:]]+)[^[:digit:]].*/', '\\1', $exact_release); $ios_codes = array('12.0' => 244, '12.1' => 251, '12.2' => 252); updateStickerForCell($objectInfo, 5, $exact_release); if (array_key_exists($major_line, $ios_codes)) { updateStickerForCell($objectInfo, 4, $ios_codes[$major_line]); } $sysChassi = $device->snmpget('1.3.6.1.4.1.9.3.6.3.0'); if ($sysChassi !== FALSE or $sysChassi !== NULL) { updateStickerForCell($objectInfo, 1, str_replace('"', '', substr($sysChassi, strlen('STRING: ')))); } checkPIC('1-29'); commitAddPort($objectInfo['id'], 'con0', '1-29', 'console', ''); // RJ-45 RS-232 console if (preg_match('/Cisco IOS Software, C2600/', $sysDescr)) { commitAddPort($objectInfo['id'], 'aux0', '1-29', 'auxillary', ''); } // RJ-45 RS-232 aux port if ($sysObjectID == '9.1.956') { // models with two AC inputs checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in-1', '1-16', 'AC1', ''); commitAddPort($objectInfo['id'], 'AC-in-2', '1-16', 'AC2', ''); } elseif ($sysObjectID != '9.1.749' and $sysObjectID != '9.1.920') { // assume the rest have one AC input, but exclude blade devices checkPIC('1-16'); // AC input commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); } break; case preg_match('/^9\\.6\\.1\\./', $sysObjectID): // Cisco SF series checkPIC('1-681'); commitAddPort($objectInfo['id'], 'con0', '1-681', 'console', ''); // DB-9 RS-232 console checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^9\\.12\\.3\\.1\\.3\\./', $sysObjectID): // Nexus $exact_release = preg_replace('/^.*, Version ([^ ]+), .*$/', '\\1', $sysDescr); $major_line = preg_replace('/^([[:digit:]]+\\.[[:digit:]]+)[^[:digit:]].*/', '\\1', $exact_release); $nxos_codes = array('4.0' => 963, '4.1' => 964); if (array_key_exists($major_line, $nxos_codes)) { updateStickerForCell($objectInfo, 4, $nxos_codes[$major_line]); } updateStickerForCell($objectInfo, 5, $exact_release); $sysChassi = $device->snmpget('1.3.6.1.2.1.47.1.1.1.1.11.149'); if ($sysChassi !== FALSE or $sysChassi !== NULL) { updateStickerForCell($objectInfo, 1, str_replace('"', '', substr($sysChassi, strlen('STRING: ')))); } checkPIC('1-29'); commitAddPort($objectInfo['id'], 'con0', '1-29', 'console', ''); // RJ-45 RS-232 console checkPIC('1-16'); // AC input commitAddPort($objectInfo['id'], 'AC-in-1', '1-16', 'AC1', ''); commitAddPort($objectInfo['id'], 'AC-in-2', '1-16', 'AC2', ''); break; case preg_match('/^11\\.2\\.3\\.7\\.11\\.(\\d+)$/', $sysObjectID, $matches): // ProCurve $console_per_product = array(33 => '1-29', 63 => '1-29', 78 => '1-29', 79 => '1-29', 80 => '1-29', 86 => '1-29', 87 => '1-29', 19 => '1-681'); if (array_key_exists($matches[1], $console_per_product)) { checkPIC($console_per_product[$matches[1]]); commitAddPort($objectInfo['id'], 'console', $console_per_product[$matches[1]], 'console', ''); } $oom_per_product = array(33 => '1-24'); if (array_key_exists($matches[1], $oom_per_product)) { checkPIC($oom_per_product[$matches[1]]); commitAddPort($objectInfo['id'], 'mgmt', $oom_per_product[$matches[1]], 'mgmt', ''); } checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); $exact_release = preg_replace('/^.* revision ([^ ]+), .*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $exact_release); break; case preg_match('/^4526\\.100\\./', $sysObjectID): // NETGEAR checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', 'console', ''); // DB-9 RS-232 console break; case preg_match('/^2011\\.2\\.23\\./', $sysObjectID): // Huawei detectSoftwareType($objectInfo, $sysDescr); checkPIC('1-681'); commitAddPort($objectInfo['id'], 'con0', '1-681', 'console', ''); // DB-9 RS-232 console break; case preg_match('/^2636\\.1\\.1\\.1\\.2\\.3(0|1)/', $sysObjectID): // Juniper EX3200/EX4200 detectSoftwareType($objectInfo, $sysDescr); $sw_version = preg_replace('/^.*, kernel JUNOS ([^ ]+).*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $sw_version); // one RJ-45 RS-232 and one AC port (it could be DC, but chances are it's AC) checkPIC('1-29'); commitAddPort($objectInfo['id'], 'con', '1-29', 'CON', ''); // RJ-45 RS-232 console checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); // Juniper uses the same sysObjectID for multiple HW models, override if necessary if (preg_match('/^Juniper Networks, Inc. ex3200-48t internet router/', $sysDescr)) { updateStickerForCell($objectInfo, 2, 902); } if (preg_match('/^Juniper Networks, Inc. ex4200-48t internet router/', $sysDescr)) { updateStickerForCell($objectInfo, 2, 907); } break; case preg_match('/^2636\\.1\\.1\\.1\\.2\\./', $sysObjectID): // Juniper detectSoftwareType($objectInfo, $sysDescr); checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', 'console', ''); // DB-9 RS-232 console break; case preg_match('/^1991\\.1\\.3\\.45\\./', $sysObjectID): // snFGSFamily // snFGSFamily case preg_match('/^1991\\.1\\.3\\.46\\./', $sysObjectID): // snFLSFamily // snFLSFamily case preg_match('/^1991\\.1\\.3\\.54\\.2\\.4\\.1\\.1$/', $sysObjectID): // FCX 648 detectSoftwareType($objectInfo, $sysDescr); $exact_release = preg_replace('/^.*, IronWare Version ([^ ]+) .*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $exact_release); # FOUNDRY-SN-AGENT-MIB::snChasSerNum.0 $sysChassi = $device->snmpget('enterprises.1991.1.1.1.1.2.0'); if ($sysChassi !== FALSE or $sysChassi !== NULL) { updateStickerForCell($objectInfo, 1, str_replace('"', '', substr($sysChassi, strlen('STRING: ')))); } # Type of uplink module installed. # table: FOUNDRY-SN-AGENT-MIB::snAgentBrdMainBrdDescription # Possible part numbers are: # FGS-1XG1XGC (one fixed CX4 port) # FGS-2XGC (two fixed CX4 ports) # FGS-2XG (two XFP slots) # And for FLS result (which is not handled here) would be: # 1991.1.1.2.2.1.1.2.1 = STRING: "FLS-24G 24-port Management Module" # 1991.1.1.2.2.1.1.2.3 = STRING: "FLS-1XG 1-port 10G Module (1-XFP)" # 1991.1.1.2.2.1.1.2.4 = STRING: "FLS-1XG 1-port 10G Module (1-XFP)" # (assuming, that the device has 2 XFP modules in slots 3 and 4). foreach ($device->snmpwalkoid('enterprises.1991.1.1.2.2.1.1.2') as $module_raw) { if (preg_match('/^STRING: "(FGS-1XG1XGC|FGS-2XGC) /i', $module_raw)) { $iftable_processors['fgs-uplinks']['dict_key'] = '1-40'; // CX4 break; } } # AC inputs # table: FOUNDRY-SN-AGENT-MIB::snChasPwrSupplyDescription # "Power supply 1 " # "Power supply 2 " foreach ($device->snmpwalkoid('enterprises.1991.1.1.1.2.1.1.2') as $PSU_raw) { $count = 0; $PSU_cooked = trim(preg_replace('/^string: "(.+)"$/i', '\\1', $PSU_raw, 1, $count)); if ($count) { checkPIC('1-16'); commitAddPort($objectInfo['id'], $PSU_cooked, '1-16', '', ''); } } # fixed console port checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', 'console', ''); // DB-9 RS-232 console break; case preg_match('/^1916\\.2\\./', $sysObjectID): // Extreme Networks Summit $xos_release = preg_replace('/^ExtremeXOS version ([[:digit:]]+)\\..*$/', '\\1', $sysDescr); $xos_codes = array('10' => 1350, '11' => 1351, '12' => 1352); if (array_key_exists($xos_release, $xos_codes)) { updateStickerForCell($objectInfo, 4, $xos_codes[$xos_release]); } checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', 'console', ''); // DB-9 RS-232 checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^6027\\.1\\./', $sysObjectID): # Force10 commitAddPort($objectInfo['id'], 'aux0', '1-29', 'RS-232', ''); // RJ-45 RS-232 console $m = array(); if (preg_match('/Force10 Application Software Version: ([\\d\\.]+)/', $sysDescr, $m)) { updateStickerForCell($objectInfo, 5, $m[1]); $ftos_release = preg_replace('/^([678])\\..+$/', '\\1', $m[1]); $ftos_codes = array('6' => 1592, '7' => 1593, '8' => 1594); if (array_key_exists($ftos_release, $ftos_codes)) { updateStickerForCell($objectInfo, 4, $ftos_codes[$ftos_release]); } } # F10-S-SERIES-CHASSIS-MIB::chStackUnitSerialNumber.1 $serialNo = $device->snmpget('enterprises.6027.3.10.1.2.2.1.12.1'); # F10-S-SERIES-CHASSIS-MIB::chSysPowerSupplyType.1.1 if ($device->snmpget('enterprises.6027.3.10.1.2.3.1.3.1.1') == 'INTEGER: 1') { checkPIC('1-16'); commitAddPort($objectInfo['id'], 'PSU0', '1-16', 'PSU0', ''); } # F10-S-SERIES-CHASSIS-MIB::chSysPowerSupplyType.1.2 if ($device->snmpget('enterprises.6027.3.10.1.2.3.1.3.1.2') == 'INTEGER: 1') { checkPIC('1-16'); commitAddPort($objectInfo['id'], 'PSU1', '1-16', 'PSU1', ''); } if (strlen($serialNo)) { updateStickerForCell($objectInfo, 1, str_replace('"', '', substr($serialNo, strlen('STRING: ')))); } break; case preg_match('/^202\\.20\\./', $sysObjectID): // SMC TigerSwitch // SMC TigerSwitch case preg_match('/^674\\.10895\\.4/', $sysObjectID): // Dell PowerConnect // Dell PowerConnect case preg_match('/^674\\.10895\\.300(3|4|7|9)/', $sysObjectID): case preg_match('/^674\\.10895\\.301(0|4|7|9)/', $sysObjectID): case preg_match('/^674\\.10895\\.302(0|1)/', $sysObjectID): case preg_match('/^3955\\.6\\.1\\.2048\\.1/', $sysObjectID): // Linksys // one DB-9 RS-232 and one AC port checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', '', ''); // DB-9 RS-232 checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^207\\.1\\.14\\./', $sysObjectID): // Allied Telesyn // one RJ-45 RS-232 and two AC ports checkPIC('1-29'); commitAddPort($objectInfo['id'], 'console', '1-29', 'console', ''); checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in-1', '1-16', 'AC1', ''); commitAddPort($objectInfo['id'], 'AC-in-2', '1-16', 'AC2', ''); break; case preg_match('/^674\\.10895\\.3000/', $sysObjectID): // one DB-9 RS-232, one 100Mb OOB mgmt, and one AC port checkPIC('1-681'); commitAddPort($objectInfo['id'], 'console', '1-681', '', ''); // DB-9 RS-232 checkPIC('1-19'); commitAddPort($objectInfo['id'], 'mgmt', '1-19', '', ''); checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^43\\.1\\.16\\.4\\.3\\.29/', $sysObjectID): // 3Com $sw_version = preg_replace('/^.* Version 3Com OS ([^ ]+).*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $sw_version); // one RJ-45 RS-232 and one AC port checkPIC('1-29'); commitAddPort($objectInfo['id'], 'console', '1-29', '', ''); // RJ-45 RS-232 console checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^10977\\.11825\\.11833\\.97\\.25451\\.12800\\.100\\.4\\.4/', $sysObjectID): // Netgear $sw_version = preg_replace('/^.* V([^ ]+).*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $sw_version); // one AC port, no console checkPIC('1-16'); commitAddPort($objectInfo['id'], 'AC-in', '1-16', '', ''); break; case preg_match('/^30065\\.1\\.3011\\./', $sysObjectID): // Arista detectSoftwareType($objectInfo, $sysDescr); checkPIC('1-29'); commitAddPort($objectInfo['id'], 'console', '1-29', 'IOIOI', ''); $sw_version = preg_replace('/^Arista Networks EOS version (.+) running on .*$/', '\\1', $sysDescr); updateStickerForCell($objectInfo, 5, $sw_version); if (strlen($serialNo = $device->snmpget('mib-2.47.1.1.1.1.11.1'))) { # entPhysicalSerialNumber.1 updateStickerForCell($objectInfo, 1, str_replace('"', '', substr($serialNo, strlen('STRING: ')))); } break; default: // Nortel... break; } $ifInfo = array(); foreach ($device->snmpwalkoid($ifDescr_tablename) as $oid => $value) { $randomindex = preg_replace("/^.*{$ifDescr_tablename}\\.(.+)\$/", '\\1', $oid); $value = trim(preg_replace('/^[^:]+: (.+)$/', '\\1', $value), '"'); $ifInfo[$randomindex]['ifDescr'] = $value; } foreach ($device->snmpwalkoid('ifPhysAddress') as $oid => $value) { $randomindex = preg_replace("/^.*ifPhysAddress\\.(.+)\$/", '\\1', $oid); $value = trim($value); // NET-SNMP may return MAC addresses in one of two (?) formats depending on // DISPLAY-HINT internal database. The best we can do about it is to accept both. // Bug originally reported by Walery Wysotsky against openSUSE 11.0. if (preg_match('/^string: [0-9a-f]{1,2}(:[0-9a-f]{1,2}){5}/i', $value)) { list($dummy, $value) = explode(' ', $value); $addrbytes = explode(':', $value); foreach ($addrbytes as $bidx => $bytestr) { if (strlen($bytestr) == 1) { $addrbytes[$bidx] = '0' . $bytestr; } } } elseif (preg_match('/^hex-string:( [0-9a-f]{2}){6}/i', $value)) { // Hex-STRING: xx yy zz xx yy zz $addrbytes = explode(' ', substr($value, -17)); } elseif (preg_match('/22[0-9a-f]{12}22$/', bin2hex($value))) { // STRING: "??????" $addrbytes = array(substr(bin2hex($value), -14, 12)); } else { continue; } // martian format $ifInfo[$randomindex]['ifPhysAddress'] = implode('', $addrbytes); } // process each interface only once regardless of how many processors we have to run foreach ($ifInfo as $iface) { foreach ($known_switches[$sysObjectID]['processors'] as $processor_name) { $newname = preg_replace($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['replacement'], $iface['ifDescr'], 1, $count); if ($newname === NULL) { showError('PCRE pattern error, terminating'); break 2; } if (!$count) { continue; } // try next processor on current port $newlabel = preg_replace($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['label'], $iface['ifDescr'], 1, $count); checkPIC($iftable_processors[$processor_name]['dict_key']); commitAddPort($objectInfo['id'], $newname, $iftable_processors[$processor_name]['dict_key'], $newlabel, $iface['ifPhysAddress']); if (!$iftable_processors[$processor_name]['try_next_proc']) { // done with this port continue 2; } } } // No failure up to this point, thus leave current tab for the "Ports" one. return buildRedirectURL(NULL, 'ports'); }