/** * Return connection base type device * @param array $params * @param string $type * @return object */ public function getConnection(array $params, $type) { if ($type == 'S') { $host = !empty($params['num_ip']) ? $params['num_ip'] : '127.0.0.1'; $community = !empty($params['des_snmp_community']) ? $params['des_snmp_community'] : 'public'; $version = !empty($params['des_snmp_version']) ? $params['des_snmp_version'] : '2c'; $seclevel = !empty($params['des_snmp_sec_level']) ? $params['des_snmp_sec_level'] : 'noAuthNoPriv'; $authprotocol = !empty($params['des_snmp_auth_protocol']) ? $params['des_snmp_auth_protocol'] : 'MD5'; $authpassphrase = !empty($params['des_snmp_auth_passphrase']) ? $params['des_snmp_auth_passphrase'] : 'None'; $privprotocol = !empty($params['des_snmp_priv_protocol']) ? $params['des_snmp_priv_protocol'] : 'DES'; $privpassphrase = !empty($params['des_snmp_priv_passphrase']) ? $params['des_snmp_priv_passphrase'] : 'None'; $connection = new \Cityware\Snmp\SNMP($host, $community, $version, $seclevel, $authprotocol, $authpassphrase, $privprotocol, $privpassphrase); $connection->setSecLevel(3); $connection->disableCache(); $this->setSnmpCon($connection); } else { if ($type == 'W') { $host = !empty($params['num_ip']) ? $params['num_ip'] : '127.0.0.1'; $username = !empty($params['des_wmi_user']) ? $params['des_wmi_user'] : null; $password = !empty($params['des_wmi_password']) ? $params['des_wmi_password'] : null; $domain = !empty($params['des_wmi_domain']) ? $params['des_wmi_domain'] : null; $wmi = new \Cityware\Wmi\Wmi($host, $username, $password, $domain); $connection = $wmi->connect('root\\cimv2'); $this->setWmiCon($connection); } } return $connection; }
/** * Recursivily crawls all CDP neighbours to build up a flat array of all devices * indexed by the CDP device id. * * Array form is same as that returned by neighbours() * * @see neighbours() * @param array $devices Unless you're doing something funky, just pass an empty array. This is where the result will be found. * @param string $device CDP device ID of next host to crawl. On first pass, set to null - used internally when recursing * @param array $ignore An array of CDP device IDs to *ignore*. I.e. to not include in recursive crawling * @return array The resultant array of all crawled devices (same as that passed in the @param $devices parameter) */ public function crawl(&$devices = array(), $device = null, $ignore = array()) { if (!count($devices)) { $device = $this->id(); $devices[$device] = $this->neighbours(true, $ignore); } foreach ($devices[$device] as $feNeighbour => $feConnections) { if (in_array($feNeighbour, $ignore)) { if (isset($devices[$device][$feNeighbour])) { unset($devices[$device][$feNeighbour]); } continue; } if (!isset($devices[$feNeighbour])) { $snmp = new \Cityware\Snmp\SNMP($feNeighbour, $this->getSNMP()->getCommunity()); try { $devices[$feNeighbour] = $snmp->useCisco_CDP()->neighbours(true, $ignore); unset($snmp); $this->crawl($devices, $feNeighbour, $ignore); } catch (\Cityware\Snmp\Exception $e) { // this device did not respond / have CDP enabled / CDP available - skip unset($devices[$feNeighbour]); } } } return $devices; }