/** * Determine CDP ports (trunk) * * @param $ID_Device : ID of device * @param $type type of device (NETWORKING_TYPE, PRINTER_TYPE ...) * @param $oidsModel : oid list from model SNMP * @param $oidvalues : list of values from agent query * @param $ArrayPort_LogicalNum_SNMPNum : array logical port number => SNMP port number (ifindex) * @param $ArrayPortsID : array with port name and port ID (from DB) * * @return array of trunk ports * **/ static function cdp_trunk($ID_Device, $type, $oidsModel, $oidvalues, $ArrayPort_LogicalNum_SNMPNum, $ArrayPortsID) { global $DB; $netwire = new Netwire(); $nn = new NetworkPort_NetworkPort(); $snmp_queries = new PluginFusioninventorySNMP(); if ($_SESSION['fusioninventory_logs'] == "1") { $logs = new PluginFusioninventoryLogs(); } $walks = new PluginFusioninventoryWalk(); $Threads = new PluginFusioninventoryProcesses(); $tmpc = new PluginFusioninventoryTmpConnections(); $manuf3com = new PluginFusioninventoryManufacturer3com(); $manufCisco = new PluginFusioninventoryManufacturerCisco(); $manufHP = new PluginFusioninventoryManufacturerHP(); $Array_cdp_ifIndex = array(); $Array_trunk_ifIndex = array(); $Array_multiplemac_ifIndex = array(); //$trunk_no_cdp = array(); if ($_SESSION['fusioninventory_logs'] == "1") { $logs->write("fusioninventory_fullsync", ">>>>>>>>>> Networking : Get cdp trunk ports <<<<<<<<<<", $type, $ID_Device, 1); } switch (!false) { case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "Cisco IOS Software, C1"): $sysDescr = "Cisco IOS Software, C1"; break; case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "Cisco"): $sysDescr = "Cisco"; break; case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "ProCurve J"): case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "HP J4"): case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "PROCURVE J"): $sysDescr = "ProCurve J"; break; case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "3Com IntelliJack NJ225"): $sysDescr = "3Com IntelliJack NJ225"; break; } // Detect if ports are non trunk and have multiple mac addresses // (with list of dot1dTpFdbPort & dot1dBasePortIfIndex) // Get all port_number $pass = 0; //$manufCisco->NbMacEachPort if ($sysDescr == "Cisco") { $Array_vlan = $walks->GetoidValuesFromWalk($oidvalues, $oidsModel[0][1]['vtpVlanName'], 1); if (array_count_values($Array_vlan) != 0 and array_count_values($Array_vlan) != 0) { $pass = 1; // Creation of var for each port foreach ($ArrayPort_LogicalNum_SNMPNum as $num => $ifIndex) { $Arraydot1dTpFdbPort[$ifIndex] = 0; } foreach ($Array_vlan as $num => $vlan) { $ArrayPortNumber = $walks->GetoidValuesFromWalk($oidvalues, $oidsModel[0][1]['dot1dTpFdbPort'], 1, $vlan); foreach ($ArrayPortNumber as $num => $dynamicdata) { $BridgePortNumber = $oidvalues[$oidsModel[0][1]['dot1dTpFdbPort'] . "." . $dynamicdata][$vlan]; $Arraydot1dTpFdbPort[$oidvalues[$oidsModel[0][1]['dot1dBasePortIfIndex'] . "." . $BridgePortNumber][$vlan]]++; } } } } if ($pass == "1") { foreach ($Arraydot1dTpFdbPort as $ifIndex => $num) { if ($num > 1) { $Array_multiplemac_ifIndex[$ifIndex] = 1; } } } else { if ($pass == "0") { $Arraydot1dTpFdbPort = array(); $ArrayConnectionsPort = $walks->GetoidValuesFromWalk($oidvalues, $oidsModel[0][1]['dot1dTpFdbPort'], 1); foreach ($ArrayConnectionsPort as $num => $Connectionkey) { $Arraydot1dTpFdbPort[] = $oidvalues[$oidsModel[0][1]['dot1dTpFdbPort'] . "." . $Connectionkey][""]; } $ArrayCount = array_count_values($Arraydot1dTpFdbPort); $ArrayPortNumber = $walks->GetoidValuesFromWalk($oidvalues, $oidsModel[0][1]['dot1dBasePortIfIndex'], 1); foreach ($ArrayPortNumber as $num => $PortNumber) { if (isset($ArrayCount[$PortNumber]) and $ArrayCount[$PortNumber] > 1) { $Array_multiplemac_ifIndex[$oidvalues[$oidsModel[0][1]['dot1dBasePortIfIndex'] . "." . $PortNumber][""]] = 1; } } } } if ($sysDescr == "Cisco IOS Software, C1") { $Array_multiplemac_ifIndex[$oidvalues[$oidsModel[0][1]['dot1dBasePortIfIndex'] . ".3"][$vlan]] = 1; } // End detection of ports non trunk and have multiple mac addresses // Initialization of Trunk ports (Trunk in Cisco AND Tagged in other switchs) $Array_trunk_ifIndex = array(); // ***** Get Trunk / taged ports switch ($sysDescr) { case "Cisco": $Array_trunk_ifIndex = $manufCisco->TrunkPorts($oidvalues, $oidsModel, $ID_Device, $type); break; case "ProCurve J": $Array_trunk_ifIndex = $manufHP->TrunkPorts($oidvalues, $oidsModel, $ID_Device, $type); break; } // ***** Get CDP ports switch ($sysDescr) { case "Cisco": list($Array_cdp_ifIndex, $Array_multiplemac_ifIndex) = $manufCisco->CDPPorts($oidvalues, $oidsModel, $ID_Device, $type, $Array_multiplemac_ifIndex); break; case "ProCurve J": list($Array_cdp_ifIndex, $Array_multiplemac_ifIndex) = $manufHP->CDPPorts($oidvalues, $oidsModel, $ID_Device, $type, $Array_multiplemac_ifIndex); break; case "3Com IntelliJack NJ225": $Array_multiplemac_ifIndex = $manuf3com->MultiplePorts(); break; } // ** Update for all ports on this network device the field 'trunk' in // glpi_plugin_fusioninventory_networking_ports foreach ($ArrayPort_LogicalNum_SNMPNum as $num => $ifIndex) { $query = "SELECT *, `glpi_plugin_fusioninventory_networking_ports`.`ID` AS `sid`\n FROM `glpi_networking_ports`\n LEFT JOIN `glpi_plugin_fusioninventory_networking_ports`\n ON `glpi_plugin_fusioninventory_networking_ports`.`FK_networking_ports` =\n `glpi_networking_ports`.`ID`\n WHERE `device_type`='2'\n AND `on_device`='" . $ID_Device . "'\n AND `logical_number`='" . $ifIndex . "';"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { // If trunk => 1 if (isset($Array_trunk_ifIndex[$ifIndex]) and $Array_trunk_ifIndex[$ifIndex] == "1") { if ($data['trunk'] != "1") { $query_update = "UPDATE `glpi_plugin_fusioninventory_networking_ports`\n SET `trunk`='1'\n WHERE `ID`='" . $data['sid'] . "';"; $DB->query($query_update); PluginFusioninventorySnmphistory::addLog($data["FK_networking_ports"], "trunk", "0", "1", "", $_SESSION['FK_process']); // Remove vlan $snmp_queries->CleanVlan($data['FK_networking_ports']); $snmp_queries->CleanVlan($netwire->getOppositeContact($data['FK_networking_ports'])); } // If multiple => -1 } else { if (isset($Array_multiplemac_ifIndex[$ifIndex]) and $Array_multiplemac_ifIndex[$ifIndex] == "1") { if ($data['trunk'] != "-1") { $query_update = "UPDATE `glpi_plugin_fusioninventory_networking_ports`\n SET `trunk`='-1'\n WHERE `ID`='" . $data['sid'] . "';"; $DB->query($query_update); PluginFusioninventorySnmphistory::addLog($data["FK_networking_ports"], "trunk", "0", "-1", "", $_SESSION['FK_process']); // Remove vlan PluginFusioninventoryDb::lock_wire_check(); PluginFusioninventorySnmphistory::addLogConnection("remove", $netwire->getOppositeContact($data['FK_networking_ports']), $FK_process); PluginFusioninventorySnmphistory::addLogConnection("remove", $data['FK_networking_ports'], $FK_process); $snmp_queries->CleanVlan($data['FK_networking_ports']); $snmp_queries->CleanVlan($netwire->getOppositeContact($data['FK_networking_ports'])); // Remove connection if ($nn->getFromDBForNetworkPort($data['FK_networking_ports'])) { $nn->delete(array('id' => $data['FK_networking_ports'])); } PluginFusioninventoryDb::lock_wire_unlock(); } } else { if ($data['trunk'] != "0") { $query_update = "UPDATE `glpi_plugin_fusioninventory_networking_ports`\n SET `trunk`='0'\n WHERE `ID`='" . $data['sid'] . "';"; $DB->query($query_update); PluginFusioninventorySnmphistory::addLog($data["FK_networking_ports"], "trunk", "1", "0", "", $_SESSION['FK_process']); } } } } } // ***** Add ports and connections in glpi_plugin_fusioninventory_tmp_* tables for connections between // switchs foreach ($Array_multiplemac_ifIndex as $ifIndex => $val) { $ifName = $oidvalues[$oidsModel[0][1]['ifName'] . "." . $ifIndex][""]; $TMP_ID = $tmpc->UpdatePort($ID_Device, $ArrayPortsID[$ifName]); switch ($sysDescr) { case "Cisco": $manufCisco->tmpConnections($oidvalues, $oidsModel, $ifIndex, $TMP_ID, $ID_Device, $type); break; case "ProCurve J": $manufHP->tmpConnections($oidvalues, $oidsModel, $ifIndex, $TMP_ID, $ID_Device, $type); break; case "3Com IntelliJack NJ225": $manuf3com->tmpConnections($oidvalues, $oidsModel, $ifIndex, $TMP_ID, $ID_Device, $type); break; } } foreach ($Array_cdp_ifIndex as $ifIndex => $val) { $ifName = $oidvalues[$oidsModel[0][1]['ifName'] . "." . $ifIndex][""]; $TMP_ID = $tmpc->UpdatePort($ID_Device, $ArrayPortsID[$ifName], 1); $Array_multiplemac_ifIndex[$ifIndex] = 1; } return $Array_multiplemac_ifIndex; }
/** * Disconnect a port in DB * *@param $p_port='' Port ID to disconnect *@return nothing **/ function disconnectDB($p_port = '') { if ($p_port == '') { $p_port = $this->getValue('ID'); } $netwire = new Netwire(); PluginFusioninventorySnmphistory::addLogConnection("remove", $netwire->getOppositeContact($p_port)); //PluginFusioninventorySnmphistory::addLogConnection("remove",$p_port); $nn = new NetworkPort_NetworkPort(); if ($nn->getFromDBForNetworkPort($p_port)) { if ($nn->delete(array('id' => $p_port))) { $ptap = new PluginFusioninventoryAgentsProcesses(); $ptap->updateProcess($_SESSION['glpi_plugin_fusioninventory_processnumber'], array('query_nb_connections_deleted' => '1')); } } }