本文整理汇总了PHP中NetworkPort::getContact方法的典型用法代码示例。如果您正苦于以下问题:PHP NetworkPort::getContact方法的具体用法?PHP NetworkPort::getContact怎么用?PHP NetworkPort::getContact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkPort
的用法示例。
在下文中一共展示了NetworkPort::getContact方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getNetworkEquipment
function getNetworkEquipment($id, $line, $a_links = array())
{
$networkPort = new NetworkPort();
$a_networkports = $networkPort->find("`itemtype`='NetworkEquipment'\n AND `items_id`='" . $id . "'");
$i = 0;
foreach ($a_networkports as $data_n) {
$networkports_id = $networkPort->getContact($data_n['id']);
if ($networkports_id) {
$networkPort->getFromDB($networkports_id);
switch ($networkPort->fields['itemtype']) {
case 'NetworkEquipment':
if ($i > 0) {
$this->line++;
$this->routes[$this->line] = $this->routes[$line];
$line = $this->line;
}
array_push($this->routes[$line], $networkPort->fields['items_id']);
if (!isset($this->devices[$networkPort->fields['items_id']])) {
$this->devices[$networkPort->fields['items_id']] = $networkPort->fields['items_id'];
$this->getNetworkEquipment($networkPort->fields['items_id'], $line);
}
$i++;
break;
}
}
}
}
示例2: getNetworkEquipments
function getNetworkEquipments($networkequipments_id)
{
$networkPort = new NetworkPort();
$a_networkports = $networkPort->find("`itemtype`='NetworkEquipment'\n AND `items_id`='" . $networkequipments_id . "'");
foreach ($a_networkports as $data_n) {
$networkports_id = $networkPort->getContact($data_n['id']);
if ($networkports_id) {
$networkPort->getFromDB($networkports_id);
switch ($networkPort->fields['itemtype']) {
case 'NetworkEquipment':
$this->a_devices_link['NetworkEquipment-' . $networkPort->fields['items_id']]['NetworkEquipment-' . $networkequipments_id] = 1;
if (!isset($this->a_devices['NetworkEquipment-' . $networkPort->fields['items_id']])) {
$this->a_devices['NetworkEquipment-' . $networkPort->fields['items_id']] = $this->getState('NetworkEquipment', $networkPort->fields['items_id']);
$this->getNetworkEquipments($networkPort->fields['items_id']);
}
break;
case 'Computer':
case 'Printer':
$this->a_devices_link['NetworkEquipment-' . $networkequipments_id][$networkPort->fields['itemtype'] . '-' . $networkPort->fields['items_id']] = 1;
if (!isset($this->a_devices[$networkPort->fields['itemtype'] . '-' . $networkPort->fields['items_id']])) {
$this->a_devices[$networkPort->fields['itemtype'] . '-' . $networkPort->fields['items_id']] = $this->getState($networkPort->fields['itemtype'], $networkPort->fields['items_id']);
}
break;
}
}
}
}
示例3: generateHostsCfg
//.........这里部分代码省略.........
$a_hosts[$i]['alias'] .= " (".Dropdown::getDropdownName("glpi_networkequipmenttypes", $class->fields['networkequipmenttypes_id']).")";
}
} else if (isset($class->fields['computertypes_id'])) {
if ($class->fields['computertypes_id'] > 0) {
$a_hosts[$i]['alias'] .= " (".Dropdown::getDropdownName("glpi_computertypes", $class->fields['computertypes_id']).")";
}
} else if (isset($class->fields['printertypes_id'])) {
if ($class->fields['printertypes_id'] > 0) {
$a_hosts[$i]['alias'] .= " (".Dropdown::getDropdownName("glpi_printertypes", $class->fields['printertypes_id']).")";
}
}
// WebUI user interface ...
if (isset(self::$shinkenParameters['webui']['hostIcons']['name'])) {
$a_hosts[$i][self::$shinkenParameters['webui']['hostIcons']['name']] =
self::$shinkenParameters['webui']['hostIcons']['value'];
}
if (isset(self::$shinkenParameters['webui']['hostView']['name'])) {
$a_hosts[$i][self::$shinkenParameters['webui']['hostView']['name']] =
self::$shinkenParameters['webui']['hostView']['value'];
}
// IP address
$ip = PluginMonitoringHostaddress::getIp($data['items_id'], $data['itemtype'], $class->fields['name']);
$a_hosts[$i]['address'] = $ip;
// Manage dependencies
$parent = '';
if ($data['itemtype'] != 'NetworkEquipment') {
$networkPort = new NetworkPort();
$a_networkports = $networkPort->find("`itemtype`='".$data['itemtype']."'
AND `items_id`='".$data['items_id']."'");
foreach ($a_networkports as $data_n) {
$networkports_id = $networkPort->getContact($data_n['id']);
if ($networkports_id) {
$networkPort->getFromDB($networkports_id);
if ($networkPort->fields['itemtype'] == 'NetworkEquipment') {
$networkEquipment->getFromDB($networkPort->fields['items_id']);
$parent = preg_replace("/[^A-Za-z0-9\-_]/","",$networkEquipment->fields['name']);
$a_parents_found[$parent] = 1;
$pmHost->updateDependencies($classname, $data['items_id'], 'NetworkEquipment-'.$networkPort->fields['items_id']);
}
}
}
if (empty($parent)) {
if (self::$shinkenParameters['shinken']['hosts']['parents'] == 'entity') {
$parent = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . $a_hosts[$i]['hostgroups'];
} else {
$parent = self::$shinkenParameters['shinken']['hosts']['parents'];
}
}
}
$a_hosts[$i]['parents'] = $parent;
$a_fields = array();
$pmComponent->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_components_id',
$class->fields['entities_id'],
$classname,
$class->getID()));
$pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']);
$a_fields = $pmComponent->fields;
示例4: configureNodesLinks
//.........这里部分代码省略.........
$name = $data['name'];
if ($name == '') {
$name = $item->getName();
}
// Try to get device/node connected on this port
$device_connected = '';
if ($data['arguments'] != '') {
$arguments = importArrayFromDB($data['arguments']);
foreach ($arguments as $argument) {
if (!is_numeric($argument)) {
if (strstr($argument, "[[NETWORKPORTDESCR]]")){
if (class_exists("PluginFusinvsnmpNetworkPort")) {
$pfNetworkPort = new PluginFusinvsnmpNetworkPort();
$pfNetworkPort->loadNetworkport($data['networkports_id']);
$argument = $pfNetworkPort->getValue("ifdescr");
}
} elseif (strstr($argument, "[[NETWORKPORTNUM]]")){
$networkPort = new NetworkPort();
$networkPort->getFromDB($data['networkports_id']);
$argument = $pfNetworkPort->fields['logical_number'];
} elseif (strstr($argument, "[[NETWORKPORTNAME]]")){
$networkPort = new NetworkPort();
$networkPort->getFromDB($data['networkports_id']);
$argument = $pfNetworkPort->fields['name'];
}
// Search networkport have this name or description
$a_ports = $networkPort->find("`itemtype`='".$itemtype."'
AND `items_id`='".$data['items_id']."'
AND `name`='".$argument."'");
foreach ($a_ports as $pdata) {
if ($device_connected == '') {
$oppositeports_id = $networkPort->getContact($pdata['id']);
if ($oppositeports_id) {
$networkPort->getFromDB($oppositeports_id);
$a_nodes = $pmWeathermapnode->find("
`plugin_monitoring_weathermaps_id`='".$weathermaps_id."'
AND `itemtype`='".$networkPort->fields['itemtype']."'
AND `items_id`='".$networkPort->fields['items_id']."'", "", 1);
if (count($a_nodes) > 0) {
$a_node = current($a_nodes);
$device_connected = $pmWeathermapnode->getNodeName($a_node['id']);
}
}
}
}
if ($device_connected == ''
AND class_exists("PluginFusinvsnmpNetworkPort")) {
$queryn = "SELECT `glpi_networkports`.`id` FROM `glpi_plugin_fusinvsnmp_networkports`
LEFT JOIN `glpi_networkports`
ON `glpi_networkports`.`id`=`networkports_id`
WHERE `itemtype`='".$itemtype."'
AND `items_id`='".$data['items_id']."'
AND `ifdescr`='".$argument."'";
$resultn = $DB->query($queryn);
while ($pdata=$DB->fetch_array($resultn)) {
if ($device_connected == '') {
$oppositeports_id = $networkPort->getContact($pdata['id']);
if ($oppositeports_id) {
$networkPort->getFromDB($oppositeports_id);
$a_nodes = $pmWeathermapnode->find("
`plugin_monitoring_weathermaps_id`='".$weathermaps_id."'
AND `itemtype`='".$networkPort->fields['itemtype']."'
示例5: configureNodesLinks
//.........这里部分代码省略.........
while ($data = $DB->fetch_array($result)) {
$itemtype = $data['itemtype'];
$item = new $itemtype();
$item->getFromDB($data['items_id']);
$name = $data['name'];
if ($name == '') {
$name = $item->getName();
}
// Try to get device/node connected on this port
$device_connected = '';
if ($data['arguments'] != '') {
$arguments = importArrayFromDB($data['arguments']);
foreach ($arguments as $argument) {
if (!is_numeric($argument)) {
if (strstr($argument, "[[NETWORKPORTDESCR]]")) {
if (class_exists("PluginFusinvsnmpNetworkPort")) {
$pfNetworkPort = new PluginFusinvsnmpNetworkPort();
$pfNetworkPort->loadNetworkport($data['networkports_id']);
$argument = $pfNetworkPort->getValue("ifdescr");
}
} elseif (strstr($argument, "[[NETWORKPORTNUM]]")) {
$networkPort = new NetworkPort();
$networkPort->getFromDB($data['networkports_id']);
$argument = $pfNetworkPort->fields['logical_number'];
} elseif (strstr($argument, "[[NETWORKPORTNAME]]")) {
$networkPort = new NetworkPort();
$networkPort->getFromDB($data['networkports_id']);
$argument = $pfNetworkPort->fields['name'];
}
// Search networkport have this name or description
$a_ports = $networkPort->find("`itemtype`='" . $itemtype . "'\n AND `items_id`='" . $data['items_id'] . "'\n AND `name`='" . $argument . "'");
foreach ($a_ports as $pdata) {
if ($device_connected == '') {
$oppositeports_id = $networkPort->getContact($pdata['id']);
if ($oppositeports_id) {
$networkPort->getFromDB($oppositeports_id);
$a_nodes = $pmWeathermapnode->find("\n `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n AND `itemtype`='" . $networkPort->fields['itemtype'] . "'\n AND `items_id`='" . $networkPort->fields['items_id'] . "'", "", 1);
if (count($a_nodes) > 0) {
$a_node = current($a_nodes);
$device_connected = $pmWeathermapnode->getNodeName($a_node['id']);
}
}
}
}
if ($device_connected == '' and class_exists("PluginFusinvsnmpNetworkPort")) {
$queryn = "SELECT `glpi_networkports`.`id` FROM `glpi_plugin_fusinvsnmp_networkports`\n \n LEFT JOIN `glpi_networkports`\n ON `glpi_networkports`.`id`=`networkports_id`\n \n WHERE `itemtype`='" . $itemtype . "'\n AND `items_id`='" . $data['items_id'] . "'\n AND `ifdescr`='" . $argument . "'";
$resultn = $DB->query($queryn);
while ($pdata = $DB->fetch_array($resultn)) {
if ($device_connected == '') {
$oppositeports_id = $networkPort->getContact($pdata['id']);
if ($oppositeports_id) {
$networkPort->getFromDB($oppositeports_id);
$a_nodes = $pmWeathermapnode->find("\n `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n AND `itemtype`='" . $networkPort->fields['itemtype'] . "'\n AND `items_id`='" . $networkPort->fields['items_id'] . "'", "", 1);
if (count($a_nodes) > 0) {
$a_node = current($a_nodes);
$queryl = "SELECT `plugin_monitoring_weathermapnodes_id_1`\n FROM `glpi_plugin_monitoring_weathermaplinks`\n\n LEFT JOIN `glpi_plugin_monitoring_weathermapnodes`\n ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1`\n\n WHERE ((`plugin_monitoring_weathermapnodes_id_1`='" . $data['id'] . "'\n AND `plugin_monitoring_weathermapnodes_id_2`='" . $a_node['id'] . "')\n OR (`plugin_monitoring_weathermapnodes_id_1`='" . $a_node['id'] . "'\n AND `plugin_monitoring_weathermapnodes_id_2`='" . $data['id'] . "'))\n AND `plugin_monitoring_weathermaps_id` = '" . $weathermaps_id . "'";
$resultl = $DB->query($queryl);
if ($DB->numrows($resultl) == '0') {
$device_connected = $pmWeathermapnode->getNodeName($a_node['id']);
}
}
}
}
}
}
}
示例6: assignVlan
function assignVlan($port, $vlan)
{
global $DB;
$query = "INSERT INTO\n `glpi_networkports_vlans` (`networkports_id`,`vlans_id`)\n VALUES ('{$port}','{$vlan}')";
$DB->query($query);
$np = new NetworkPort();
if ($contact_id = $np->getContact($port)) {
if ($np->getFromDB($contact_id)) {
$vlans = self::getVlansForNetworkPort($port);
if (!in_array($vlan, $vlans)) {
$query = "INSERT INTO\n `glpi_networkports_vlans` (`networkports_id`,`vlans_id`)\n VALUES ('{$contact_id}','{$vlan}')";
$DB->query($query);
}
}
}
}
示例7: displayHubConnections
function displayHubConnections($items_id, $background_img)
{
$NetworkPort = new NetworkPort();
$a_ports = $NetworkPort->find("`itemtype`='PluginFusioninventoryUnmanaged'\n AND `items_id`='" . $items_id . "'");
echo "<table width='100%' class='tab_cadre' cellpadding='5'>";
foreach ($a_ports as $a_port) {
if ($a_port['name'] != "Link") {
$id = $NetworkPort->getContact($a_port['id']);
if ($id) {
$NetworkPort->getFromDB($id);
$link = '';
$link1 = '';
$link2 = '';
if ($NetworkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') {
$classname = $NetworkPort->fields['itemtype'];
$item = new $classname();
$item->getFromDB($NetworkPort->fields['items_id']);
$link1 = $item->getLink(1);
$link = str_replace($item->getName(0), $NetworkPort->fields["mac"], $item->getLink());
// Get ips
$a_ips = PluginFusioninventoryToolbox::getIPforDevice('PluginFusioninventoryUnmanaged', $item->getID());
$link2 = str_replace($item->getName(0), implode(", ", $a_ips), $item->getLink());
$icon = $this->getItemtypeIcon($item->fields["item_type"]);
if ($item->fields['accepted'] == 1) {
echo "<tr>";
echo "<td align='center' style='background:#bfec75'\n class='tab_bg_1_2'>" . $icon . $item->getLink(1);
} else {
echo "<tr>";
echo "<td align='center' style='background:#cf9b9b'\n class='tab_bg_1_2'>" . $icon . $item->getLink(1);
}
if (!empty($link)) {
echo "<br/>" . $link;
}
if (!empty($link2)) {
echo "<br/>" . $link2;
}
echo "</td>";
echo "</tr>";
} else {
$classname = $NetworkPort->fields['itemtype'];
$item = new $classname();
$item->getFromDB($NetworkPort->fields['items_id']);
$link1 = $item->getLink(1);
$link = str_replace($item->getName(0), $NetworkPort->fields["mac"], $item->getLink());
// $link2 = str_replace($item->getName(0), $NetworkPort->fields["ip"],
// $item->getLink());
echo "<tr>";
$icon = $this->getItemtypeIcon($classname);
echo "<td align='center' " . $background_img . "\n class='tab_bg_1_2'>" . $icon . $item->getLink(1);
if (!empty($link)) {
echo "<br/>" . $link;
}
if (!empty($link2)) {
echo "<br/>" . $link2;
}
echo "</td>";
echo "</tr>";
}
}
}
}
echo "</table>";
}
示例8: pdfForItem
static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
{
global $DB;
$ID = $item->getField('id');
$type = get_class($item);
$query = "SELECT `glpi_networkports`.`id`\n FROM `glpi_networkports`\n WHERE `items_id` = '" . $ID . "'\n AND `itemtype` = '" . $type . "'\n ORDER BY `name`, `logical_number`";
$pdf->setColumnsSize(100);
if ($result = $DB->query($query)) {
$nb_connect = $DB->numrows($result);
if (!$nb_connect) {
$pdf->displayTitle('<b>0 ' . __('No network port found') . '</b>');
} else {
$pdf->displayTitle('<b>' . sprintf(__('%1$s: %2$d'), _n('Network port', 'Network ports', $nb_connect), $nb_connect . "</b>"));
while ($devid = $DB->fetch_row($result)) {
$netport = new NetworkPort();
$netport->getfromDB(current($devid));
$instantiation_type = $netport->fields["instantiation_type"];
$instname = call_user_func(array($instantiation_type, 'getTypeName'));
$pdf->displayTitle('<b>' . $instname . '</b>');
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), '#</b>', $netport->fields["logical_number"]));
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), __('Name') . '</b>', $netport->fields["name"]));
$contact = new NetworkPort();
$netport2 = new NetworkPort();
$add = __('Not connected.');
if ($cid = $contact->getContact($netport->fields["id"])) {
if ($netport2->getFromDB($cid) && ($device2 = getItemForItemtype($netport2->fields["itemtype"]))) {
if ($device2->getFromDB($netport2->fields["items_id"])) {
$add = $netport2->getName() . ' ' . __('on') . ' ' . $device2->getName() . ' (' . $device2->getTypeName() . ')';
}
}
}
if ($instantiation_type == 'NetworkPortEthernet') {
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), __('Connected to') . '</b>', $add));
$netportethernet = new NetworkPortEthernet();
$speed = $type = '';
if ($netportethernet->getFromDB($netport->fields['id'])) {
$speed = NetworkPortEthernet::getPortSpeed($netportethernet->fields['speed']);
$type = NetworkPortEthernet::getPortTypeName($netportethernet->fields['type']);
}
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), __('Ethernet port speed') . '</b>', $speed));
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), __('Ethernet port type') . '</b>', $type));
$netpoint = new Netpoint();
$outlet = '';
if ($netpoint->getFromDB($netportethernet->fields['netpoints_id'])) {
$outlet = $netpoint->fields['name'];
}
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), __('Network outlet') . '</b>', $outlet));
}
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), __('MAC') . '</b>', $netport->fields["mac"]));
$sqlip = "LEFT JOIN `glpi_networknames`\n ON (`glpi_ipaddresses`.`items_id` = `glpi_networknames`.`id`\n AND `glpi_ipaddresses`.`entities_id`\n = '" . $_SESSION['glpiactive_entity'] . "')\n WHERE `glpi_networknames`.`items_id` = '" . $netport->fields["id"] . "'";
$ipname = '';
$ip = new IPAddress();
if ($ip->getFromDBByQuery($sqlip)) {
$ipname = $ip->fields['name'];
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), __('ip') . '</b>', $ipname));
$sql = "SELECT `glpi_ipaddresses_ipnetworks`.`ipnetworks_id`\n FROM `glpi_ipaddresses_ipnetworks`\n LEFT JOIN `glpi_ipnetworks`\n ON (`glpi_ipaddresses_ipnetworks`.`ipnetworks_id` = `glpi_ipnetworks`.`id`)\n WHERE `glpi_ipaddresses_ipnetworks`.`ipaddresses_id` = '" . $ip->getID() . "'";
$res = $DB->query($sql);
if ($res) {
while ($row = $DB->fetch_assoc($res)) {
$ipnetwork = new IPNetwork();
if ($ipnetwork->getFromDB($row['ipnetworks_id'])) {
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), __('IP network') . '</b>', $ipnetwork->fields['address']));
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), __('Subnet mask') . '</b>', $ipnetwork->fields['netmask']));
$pdf->displayLine('<b>' . sprintf(__('%1$s: %2$s'), __('Gateway') . '</b>', $ipnetwork->fields['gateway']));
}
}
}
}
}
// each port
}
// Found
}
// Query
$pdf->displaySpace();
}
示例9: plugin_item_purge_fusioninventory
function plugin_item_purge_fusioninventory($parm)
{
switch (get_class($parm)) {
case 'NetworkPort_NetworkPort':
// If remove connection of a hub port (unknown device), we must delete this port too
$NetworkPort = new NetworkPort();
$NetworkPort_Vlan = new NetworkPort_Vlan();
$pfUnmanaged = new PluginFusioninventoryUnmanaged();
$networkPort_NetworkPort = new NetworkPort_NetworkPort();
$a_hubs = array();
$port_id = $NetworkPort->getContact($parm->getField('networkports_id_1'));
$NetworkPort->getFromDB($parm->getField('networkports_id_1'));
if ($NetworkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') {
$pfUnmanaged->getFromDB($NetworkPort->fields['items_id']);
if ($pfUnmanaged->fields['hub'] == '1') {
$a_hubs[$NetworkPort->fields['items_id']] = 1;
$NetworkPort->delete($NetworkPort->fields);
}
}
$NetworkPort->getFromDB($port_id);
if ($port_id) {
if ($NetworkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') {
$pfUnmanaged->getFromDB($NetworkPort->fields['items_id']);
if ($pfUnmanaged->fields['hub'] == '1') {
$a_hubs[$NetworkPort->fields['items_id']] = 1;
}
}
}
$port_id = $NetworkPort->getContact($parm->getField('networkports_id_2'));
$NetworkPort->getFromDB($parm->getField('networkports_id_2'));
if ($NetworkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') {
if ($pfUnmanaged->getFromDB($NetworkPort->fields['items_id'])) {
if ($pfUnmanaged->fields['hub'] == '1') {
$a_vlans = $NetworkPort_Vlan->getVlansForNetworkPort($NetworkPort->fields['id']);
foreach ($a_vlans as $vlan_id) {
$NetworkPort_Vlan->unassignVlan($NetworkPort->fields['id'], $vlan_id);
}
$a_hubs[$NetworkPort->fields['items_id']] = 1;
$NetworkPort->delete($NetworkPort->fields);
}
}
}
if ($port_id) {
$NetworkPort->getFromDB($port_id);
if ($NetworkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') {
$pfUnmanaged->getFromDB($NetworkPort->fields['items_id']);
if ($pfUnmanaged->fields['hub'] == '1') {
$a_hubs[$NetworkPort->fields['items_id']] = 1;
}
}
}
// If hub have no port, delete it
foreach (array_keys($a_hubs) as $unkowndevice_id) {
$a_networkports = $NetworkPort->find("`itemtype`='PluginFusioninventoryUnmanaged'\n AND `items_id`='" . $unkowndevice_id . "' ");
if (count($a_networkports) < 2) {
$pfUnmanaged->delete(array('id' => $unkowndevice_id), 1);
} else {
if (count($a_networkports) == '2') {
$switchPorts_id = 0;
$otherPorts_id = 0;
foreach ($a_networkports as $data) {
if ($data['name'] == 'Link') {
$switchPorts_id = $NetworkPort->getContact($data['id']);
} else {
if ($otherPorts_id == '0') {
$otherPorts_id = $NetworkPort->getContact($data['id']);
} else {
$switchPorts_id = $NetworkPort->getContact($data['id']);
}
}
}
$pfUnmanaged->disconnectDB($switchPorts_id);
// disconnect this port
$pfUnmanaged->disconnectDB($otherPorts_id);
// disconnect destination port
$networkPort_NetworkPort->add(array('networkports_id_1' => $switchPorts_id, 'networkports_id_2' => $otherPorts_id));
}
}
}
break;
case 'NetworkEquipment':
// Delete all ports
$query_delete = "DELETE FROM `glpi_plugin_fusioninventory_networkequipments`\n WHERE `networkequipments_id`='" . $parm->fields["id"] . "';";
$DB->query($query_delete);
$query_select = "SELECT `glpi_plugin_fusioninventory_networkports`.`id`,\n `glpi_networkports`.`id` as nid\n FROM `glpi_plugin_fusioninventory_networkports`\n LEFT JOIN `glpi_networkports`\n ON `glpi_networkports`.`id` = `networkports_id`\n WHERE `items_id`='" . $parm->fields["id"] . "'\n AND `itemtype`='NetworkEquipment';";
$result = $DB->query($query_select);
while ($data = $DB->fetch_array($result)) {
$query_delete = "DELETE FROM `glpi_plugin_fusioninventory_networkports`\n WHERE `id`='" . $data["id"] . "';";
$DB->query($query_delete);
$query_delete = "DELETE FROM `glpi_plugin_fusinvsnmp_networkportlogs`\n WHERE `networkports_id`='" . $data['nid'] . "'";
$DB->query($query_delete);
}
break;
case "Printer":
$query_delete = "DELETE FROM `glpi_plugin_fusioninventory_printers`\n WHERE `printers_id`='" . $parm->fields["id"] . "';";
$DB->query($query_delete);
$query_delete = "DELETE FROM `glpi_plugin_fusioninventory_printercartridges`\n WHERE `printers_id`='" . $parm->fields["id"] . "';";
$DB->query($query_delete);
$query_delete = "DELETE FROM `glpi_plugin_fusioninventory_printerlogs`\n WHERE `printers_id`='" . $parm->fields["id"] . "';";
$DB->query($query_delete);
//.........这里部分代码省略.........
示例10: generateHostsCfg
function generateHostsCfg($file = 0, $tag = '')
{
global $DB;
$pmCommand = new PluginMonitoringCommand();
$pmCheck = new PluginMonitoringCheck();
$pmComponent = new PluginMonitoringComponent();
$pmEntity = new PluginMonitoringEntity();
$pmHostconfig = new PluginMonitoringHostconfig();
$pmHost = new PluginMonitoringHost();
$calendar = new Calendar();
$pmRealm = new PluginMonitoringRealm();
$networkEquipment = new NetworkEquipment();
$pmContact_Item = new PluginMonitoringContact_Item();
$profile_User = new Profile_User();
$user = new User();
$a_hosts = array();
$i = 0;
$a_parents_found = array();
$a_hosts_found = array();
$a_entities_allowed = $pmEntity->getEntitiesByTag($tag);
// * Prepare contacts
$a_contacts_entities = array();
$a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog'\n AND `users_id`>0");
foreach ($a_list_contact as $data) {
$contactentities = getSonsOf('glpi_entities', $data['entities_id']);
if (isset($a_contacts_entities[$data['items_id']][$data['users_id']])) {
$contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$data['users_id']]);
}
$a_contacts_entities[$data['items_id']][$data['users_id']] = $contactentities;
}
$query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n GROUP BY `itemtype`, `items_id`";
$result = $DB->query($query);
while ($data = $DB->fetch_array($result)) {
$classname = $data['itemtype'];
$class = new $classname();
if ($class->getFromDB($data['items_id'])) {
if (isset($a_entities_allowed['-1']) or isset($a_entities_allowed[$class->fields['entities_id']])) {
$a_hosts[$i]['host_name'] = $classname . "-" . $data['items_id'] . "-" . preg_replace("/[^A-Za-z0-9]/", "", $class->fields['name']);
$a_hosts_found[$a_hosts[$i]['host_name']] = 1;
$a_hosts[$i]['alias'] = preg_replace("/[^A-Za-z0-9]/", "", $class->fields['name']) . " / " . $classname . "-" . $data['items_id'];
if (isset($class->fields['networkequipmenttypes_id'])) {
if ($class->fields['networkequipmenttypes_id'] > 0) {
$a_hosts[$i]['alias'] .= " (" . Dropdown::getDropdownName("glpi_networkequipmenttypes", $class->fields['networkequipmenttypes_id']) . ")";
}
} else {
if (isset($class->fields['computertypes_id'])) {
if ($class->fields['computertypes_id'] > 0) {
$a_hosts[$i]['alias'] .= " (" . Dropdown::getDropdownName("glpi_computertypes", $class->fields['computertypes_id']) . ")";
}
} else {
if (isset($class->fields['printertypes_id'])) {
if ($class->fields['printertypes_id'] > 0) {
$a_hosts[$i]['alias'] .= " (" . Dropdown::getDropdownName("glpi_printertypes", $class->fields['printertypes_id']) . ")";
}
}
}
}
$ip = PluginMonitoringHostaddress::getIp($data['items_id'], $data['itemtype'], $class->fields['name']);
$a_hosts[$i]['address'] = $ip;
// Manage dependencies
$parent = '';
if ($data['itemtype'] != 'NetworkEquipment') {
$networkPort = new NetworkPort();
$a_networkports = $networkPort->find("`itemtype`='" . $data['itemtype'] . "'\n AND `items_id`='" . $data['items_id'] . "'");
foreach ($a_networkports as $data_n) {
$networkports_id = $networkPort->getContact($data_n['id']);
if ($networkports_id) {
$networkPort->getFromDB($networkports_id);
if ($networkPort->fields['itemtype'] == 'NetworkEquipment') {
$networkEquipment->getFromDB($networkPort->fields['items_id']);
$parent = 'NetworkEquipment-' . $networkPort->fields['items_id'] . '-' . preg_replace("/[^A-Za-z0-9]/", "", $networkEquipment->fields['name']);
$a_parents_found[$parent] = 1;
$pmHost->updateDependencies($classname, $data['items_id'], 'NetworkEquipment-' . $networkPort->fields['items_id']);
}
}
}
}
$a_hosts[$i]['parents'] = $parent;
$a_fields = array();
$pmCommand->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_commands_id', $class->fields['entities_id'], $classname, $class->getID()));
$a_component = current($pmComponent->find("`plugin_monitoring_commands_id`='" . $pmCommand->fields['id'] . "'", "", 1));
$a_fields = $a_component;
$a_hosts[$i]['check_command'] = $pmCommand->fields['command_name'];
$pmCheck->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_checks_id', $class->fields['entities_id'], $classname, $class->getID()));
$a_hosts[$i]['check_interval'] = $pmCheck->fields['check_interval'];
$a_hosts[$i]['retry_interval'] = $pmCheck->fields['retry_interval'];
$a_hosts[$i]['max_check_attempts'] = $pmCheck->fields['max_check_attempts'];
if ($calendar->getFromDB($pmHostconfig->getValueAncestor('calendars_id', $class->fields['entities_id'], $classname, $class->getID()))) {
$a_hosts[$i]['check_period'] = $calendar->fields['name'];
} else {
$a_hosts[$i]['check_period'] = "24x7";
}
$pmRealm->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_realms_id', $class->fields['entities_id'], $classname, $class->getID()));
$a_hosts[$i]['realm'] = $pmRealm->fields['name'];
$a_hosts[$i]['process_perf_data'] = '1';
$a_hosts[$i]['notification_interval'] = '30';
// For contact check if a service with this component
$a_hosts[$i]['contacts'] = '';
$querycont = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n LEFT JOIN `glpi_plugin_monitoring_services`\n ON `plugin_monitoring_componentscatalogs_hosts_id`\n = `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`\n WHERE `plugin_monitoring_components_id`='" . $a_component['id'] . "'\n AND `items_id`='" . $data['items_id'] . "'\n AND `itemtype`='" . $data['itemtype'] . "'\n LIMIT 1";
$resultcont = $DB->query($querycont);
//.........这里部分代码省略.........
示例11: importConnectionMac
function importConnectionMac($a_portconnection, $networkports_id)
{
$wire = new NetworkPort_NetworkPort();
$networkPort = new NetworkPort();
$pfNetworkPort = new PluginFusioninventoryNetworkPort();
$pfUnmanaged = new PluginFusioninventoryUnmanaged();
$a_snmpports = current($pfNetworkPort->find("`networkports_id`='" . $networkports_id . "'", "", 1));
$pfNetworkPort->getFromDB($a_snmpports['id']);
$count = count($a_portconnection);
$pfNetworkPort->loadNetworkport($networkports_id);
if ($pfNetworkPort->getValue('trunk') != '1') {
if ($count == '2') {
// detect if phone IP is one of the 2 devices
$phonecase = 0;
$macNotPhone_id = 0;
$macNotPhone = '';
$phonePort_id = 0;
foreach ($a_portconnection as $ifmac) {
$a_ports = $networkPort->find("`mac`='" . $ifmac . "'", "", 1);
$a_port = current($a_ports);
if ($a_port['itemtype'] == 'Phone') {
// Connect phone on switch port and other (computer..) in this phone
$phonePort_id = $a_port['id'];
$phonecase++;
} else {
$macNotPhone_id = $a_port['id'];
$macNotPhone = $ifmac;
}
}
if ($phonecase == '1') {
$wire->add(array('networkports_id_1' => $networkports_id, 'networkports_id_2' => $phonePort_id));
$networkPort->getFromDB($phonePort_id);
$Phone = new Phone();
$Phone->getFromDB($networkPort->fields['items_id']);
$a_portsPhone = $networkPort->find("`items_id`='" . $networkPort->fields['items_id'] . "'\n AND `itemtype`='Phone'\n AND `name`='Link'", '', 1);
$portLink_id = 0;
if (count($a_portsPhone) == '1') {
$a_portPhone = current($a_portsPhone);
$portLink_id = $a_portPhone['id'];
} else {
// Create Port Link
$input = array();
$input['name'] = 'Link';
$input['itemtype'] = 'Phone';
$input['items_id'] = $Phone->fields['id'];
$input['entities_id'] = $Phone->fields['entities_id'];
$portLink_id = $networkPort->add($input);
}
$opposite_id = FALSE;
if ($opposite_id == $wire->getOppositeContact($portLink_id)) {
if ($opposite_id != $macNotPhone_id) {
$pfNetworkPort->disconnectDB($portLink_id);
// disconnect this port
$pfNetworkPort->disconnectDB($macNotPhone_id);
// disconnect destination port
}
}
if (!isset($macNotPhone_id)) {
// Create unmanaged ports
$unmanagedn_infos = array();
$unmanagedn_infos["name"] = '';
if (isset($_SESSION["plugin_fusioninventory_entity"])) {
$input['entities_id'] = $_SESSION["plugin_fusioninventory_entity"];
}
$newID = $pfUnmanaged->add($unmanagedn_infos);
// Add networking_port
$port_add = array();
$port_add["items_id"] = $newID;
$port_add["itemtype"] = 'PluginFusioninventoryUnmanaged';
$port_add['mac'] = $macNotPhone;
$port_add['instantiation_type'] = "NetworkPortEthernet";
$macNotPhone_id = $networkPort->add($port_add);
}
$wire->add(array('networkports_id_1' => $portLink_id, 'networkports_id_2' => $macNotPhone_id));
} else {
$pfUnmanaged->hubNetwork($pfNetworkPort, $a_portconnection);
}
} else {
if ($count > 1) {
// MultipleMac
$pfUnmanaged->hubNetwork($pfNetworkPort, $a_portconnection);
} else {
// One mac on port
foreach ($a_portconnection as $ifmac) {
//Only 1 time
$a_ports = $networkPort->find("`mac`='" . $ifmac . "' AND `logical_number`='1'", "", 1);
if (count($a_ports) == 0) {
$a_ports = $networkPort->find("`mac`='" . $ifmac . "'", "", 1);
}
if (count($a_ports) > 0) {
$a_port = current($a_ports);
$hub = 0;
$id = $networkPort->getContact($a_port['id']);
if ($id and $networkPort->getFromDB($id)) {
if ($networkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') {
$pfUnmanaged->getFromDB($networkPort->fields['items_id']);
if ($pfUnmanaged->fields['hub'] == '1') {
$hub = 1;
}
}
//.........这里部分代码省略.........
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:101,代码来源:inventorynetworkequipmentlib.class.php