本文整理汇总了PHP中NetworkPort::find方法的典型用法代码示例。如果您正苦于以下问题:PHP NetworkPort::find方法的具体用法?PHP NetworkPort::find怎么用?PHP NetworkPort::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkPort
的用法示例。
在下文中一共展示了NetworkPort::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
}
}
示例2: 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;
}
}
}
}
示例3: NewComputer
/**
* @test
*/
public function NewComputer()
{
global $DB;
$_SESSION["plugin_fusioninventory_entity"] = 0;
$_SESSION["glpiname"] = 'Plugin_FusionInventory';
$a_inventory = array('fusioninventorycomputer' => array('last_fusioninventory_update' => date('Y-m-d H:i:s')), 'soundcard' => array(), 'graphiccard' => array(), 'controller' => array(), 'processor' => array(), 'computerdisk' => array(), 'memory' => array(), 'monitor' => array(), 'printer' => array(), 'peripheral' => array(), 'networkport' => array(), 'software' => array(), 'harddrive' => array(), 'virtualmachine' => array(), 'antivirus' => array(), 'storage' => array(), 'licenseinfo' => array(), 'networkcard' => array(), 'drive' => array(), 'batteries' => array(), 'itemtype' => 'Computer');
$a_inventory['Computer'] = array('name' => 'pc', 'users_id' => 0, 'operatingsystems_id' => 1, 'operatingsystemversions_id' => 1, 'uuid' => 1, 'domains_id' => 1, 'os_licenseid' => '', 'os_license_number' => '', 'operatingsystemservicepacks_id' => 1, 'manufacturers_id' => 0, 'computermodels_id' => 0, 'serial' => 'XB63J7D', 'computertypes_id' => 1, 'is_dynamic' => 1, 'contact' => 'ddurieux');
$a_inventory['networkport'] = array('em0-cc:f9:54:a1:03:45' => array('name' => 'em0', 'netmask' => '255.255.255.0', 'subnet' => '192.168.30.0', 'mac' => 'cc:f9:54:a1:03:45', 'instantiation_type' => 'NetworkPortEthernet', 'virtualdev' => 0, 'ssid' => '', 'gateway' => '', 'dhcpserver' => '', 'logical_number' => 1, 'ipaddress' => array('192.168.30.198')));
$networkPort = new NetworkPort();
$a_networkports = $networkPort->find("`mac`='cc:f9:54:a1:03:45'");
$a_networkport = current($a_networkports);
$networkports_id = $a_networkport['id'];
$pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
$computer = new Computer();
$computers_id = $computer->add(array('serial' => 'XB63J7D', 'entities_id' => 0));
$_SESSION['glpiactive_entity'] = 0;
$pfiComputerLib->updateComputer($a_inventory, $computers_id, FALSE);
$a_networkports = $networkPort->find("`mac`='cc:f9:54:a1:03:45'");
$this->assertEquals(1, count($a_networkports), "The MAC address cc:f9:54:a1:03:45 must be tied to only one port");
$a_networkport = current($a_networkports);
$this->assertEquals($networkports_id, $a_networkport['id'], 'The networkport ID is not the same ' . 'between the unknown device and the computer');
$this->assertEquals('Computer', $a_networkport['itemtype'], "Maybe Computer ");
}
示例4: getIPforDevice
static function getIPforDevice($itemtype, $items_id)
{
$NetworkPort = new NetworkPort();
$networkName = new NetworkName();
$iPAddress = new IPAddress();
$a_ips = array();
$a_ports = $NetworkPort->find("`itemtype`='" . $itemtype . "'\n AND `items_id`='" . $items_id . "'\n AND `instantiation_type` != 'NetworkPortLocal'");
foreach ($a_ports as $a_port) {
$a_networknames = $networkName->find("`itemtype`='NetworkPort'\n AND `items_id`='" . $a_port['id'] . "'");
foreach ($a_networknames as $a_networkname) {
$a_ipaddresses = $iPAddress->find("`itemtype`='NetworkName'\n AND `items_id`='" . $a_networkname['id'] . "'");
foreach ($a_ipaddresses as $data) {
if ($data['name'] != '127.0.0.1' && $data['name'] != '::1') {
$a_ips[$data['name']] = $data['name'];
}
}
}
}
return array_unique($a_ips);
}
示例5: run
/**
* When agent contact server, this function send datas to agent
*/
function run($jobstate)
{
$pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
$pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
$NetworkPort = new NetworkPort();
$sxml_option = $this->message->addChild('OPTION');
$sxml_option->addChild('NAME', 'WAKEONLAN');
$changestate = 0;
// foreach ($taskjobstates as $jobstate) {
$data = $jobstate->fields;
$a_networkPort = $NetworkPort->find("`itemtype`='Computer' AND `items_id`='" . $data['items_id'] . "' ");
$computerip = 0;
foreach ($a_networkPort as $datanetwork) {
//if ($datanetwork['ip'] != "127.0.0.1") {
if ($datanetwork['mac'] != '') {
$computerip++;
$sxml_param = $sxml_option->addChild('PARAM');
$sxml_param->addAttribute('MAC', $datanetwork['mac']);
//$sxml_param->addAttribute('IP', $datanetwork['ip']);
if ($changestate == '0') {
$pfTaskjobstate->changeStatus($data['id'], 1);
$pfTaskjoblog->addTaskjoblog($data['id'], '0', 'Computer', '1', '');
$changestate = $pfTaskjobstate->fields['id'];
} else {
$pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 0, "Merged with " . $changestate);
}
// Update taskjobstate (state = 3 : finish); Because we haven't return of agent on this action
$pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 0, 'WakeOnLan have not return state', 1);
}
//}
}
if ($computerip == '0') {
$pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 1, "No IP found on the computer");
}
//}
return $this->message;
}
示例6: NetworkPort
function _updateNetworkInfo($arrayinventory, $item_type, $id, $instanciation_type, $check_addresses)
{
$NetworkPort = new NetworkPort();
$port = current($NetworkPort->find("`itemtype`='{$item_type}' AND `items_id`='{$id}'" . " AND `instantiation_type`='{$instanciation_type}'", "", 1));
$port_id = 0;
if (isset($port['id'])) {
if (isset($arrayinventory['MAC']) and !empty($arrayinventory['MAC'])) {
$input = array();
$input['id'] = $port['id'];
$input['mac'] = $arrayinventory['MAC'];
$NetworkPort->update($input);
}
$port_id = $port['id'];
} else {
$input = array();
$input['itemtype'] = $item_type;
$input['items_id'] = $id;
$input['instantiation_type'] = $instanciation_type;
$input['name'] = "management";
if (isset($arrayinventory['MAC']) && !empty($arrayinventory['MAC'])) {
$input['mac'] = $arrayinventory['MAC'];
}
$port_id = $NetworkPort->add($input);
}
$NetworkName = new NetworkName();
$name = current($NetworkName->find("`itemtype`='NetworkPort' AND `items_id`='" . $port_id . "'", "", 1));
$name_id = 0;
if (isset($name['id'])) {
$name_id = $name['id'];
} else {
$input = array();
$input['itemtype'] = 'NetworkPort';
$input['items_id'] = $port_id;
$name_id = $NetworkName->add($input);
}
if (isset($arrayinventory['IP'])) {
$IPAddress = new IPAddress();
if ($check_addresses) {
$addresses = $IPAddress->find("`itemtype`='NetworkName'\n AND `items_id`='" . $name_id . "'", '', 1);
} else {
// Case of NetworkEquipment
$a_ips = $IPAddress->find("`itemtype`='NetworkName'\n AND `items_id`='" . $name_id . "'\n AND `name`='" . $arrayinventory['IP'] . "'", '', 1);
if (count($a_ips) > 0) {
$addresses = $a_ips;
} else {
$addresses = array();
}
}
if (count($addresses) == 0) {
$input = array();
$input['itemtype'] = 'NetworkName';
$input['items_id'] = $name_id;
$input['name'] = $arrayinventory['IP'];
$IPAddress->add($input);
} else {
$address = current($addresses);
if ($address['name'] != $arrayinventory['IP']) {
$input = array();
$input['id'] = $address['id'];
$input['name'] = $arrayinventory['IP'];
$IPAddress->update($input);
}
}
}
}
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:65,代码来源:communicationnetworkdiscovery.class.php
示例7: deleteNetworking
/**
* Delete network ports for an itemtype
* @param the itemtype
* @return nothing
*/
static function deleteNetworking($itemtype)
{
$networkport = new NetworkPort();
foreach ($networkport->find("`itemtype`='{$itemtype}'") as $port) {
$networkport->delete($port);
}
}
示例8: importPorts
function importPorts($a_inventory, $items_id)
{
$networkPort = new NetworkPort();
$pfNetworkPort = new PluginFusioninventoryNetworkPort();
$networkports_id = 0;
foreach ($a_inventory['networkport'] as $a_port) {
$a_ports_DB = current($networkPort->find("`itemtype`='Printer'\n AND `items_id`='" . $items_id . "'\n AND `instantiation_type`='NetworkPortEthernet'\n AND `logical_number` = '" . $a_port['logical_number'] . "'", '', 1));
if (!isset($a_ports_DB['id'])) {
// Add port
$a_port['instantiation_type'] = 'NetworkPortEthernet';
$a_port['items_id'] = $items_id;
$a_port['itemtype'] = 'Printer';
$networkports_id = $networkPort->add($a_port);
unset($a_port['id']);
$a_pfnetworkport_DB = current($pfNetworkPort->find("`networkports_id`='" . $networkports_id . "'", '', 1));
$a_port['id'] = $a_pfnetworkport_DB['id'];
$pfNetworkPort->update($a_port);
} else {
// Update port
$networkports_id = $a_ports_DB['id'];
$a_port['id'] = $a_ports_DB['id'];
$networkPort->update($a_port);
unset($a_port['id']);
// Check if pfnetworkport exist.
$a_pfnetworkport_DB = current($pfNetworkPort->find("`networkports_id`='" . $networkports_id . "'", '', 1));
$a_port['networkports_id'] = $networkports_id;
if (isset($a_pfnetworkport_DB['id'])) {
$a_port['id'] = $a_pfnetworkport_DB['id'];
$pfNetworkPort->update($a_port);
} else {
$a_port['networkports_id'] = $networkports_id;
$pfNetworkPort->add($a_port);
}
}
}
}
示例9: getIp
static function getIp($items_id, $itemtype, $hostname)
{
global $DB;
$networkPort = new NetworkPort();
$pmHostaddress = new PluginMonitoringHostaddress();
$ip = $hostname;
if ($itemtype == 'NetworkEquipment') {
$class = new $itemtype();
$class->getFromDB($items_id);
if ($class->fields['ip'] != '') {
$ip = $class->fields['ip'];
}
} else {
$query = "SELECT * FROM `" . $pmHostaddress->getTable() . "`\n WHERE `items_id`='" . $items_id . "'\n AND `itemtype`='" . $itemtype . "'\n LIMIT 1";
$result = $DB->query($query);
if ($DB->numrows($result) == '1') {
$data = $DB->fetch_assoc($result);
$pmHostaddress->getFromDB($data['id']);
$networkPort->getFromDB($pmHostaddress->fields['networkports_id']);
$ip = $networkPort->fields['ip'];
} else {
$a_listnetwork = $networkPort->find("`itemtype`='" . $itemtype . "'\n AND `items_id`='" . $items_id . "'", "`id`");
foreach ($a_listnetwork as $datanetwork) {
if ($datanetwork['ip'] != '' and $datanetwork['ip'] != '127.0.0.1' and $ip != '') {
$ip = $datanetwork['ip'];
break;
}
}
}
}
return $ip;
}
示例10: manageNetworkPort
function manageNetworkPort($inventory_networkports, $computers_id, $no_history)
{
global $DB;
$networkPort = new NetworkPort();
$networkName = new NetworkName();
$iPAddress = new IPAddress();
$iPNetwork = new IPNetwork();
$networkPortEthernet = new NetworkPortEthernet();
$item_DeviceNetworkCard = new Item_DeviceNetworkCard();
foreach ($inventory_networkports as $a_networkport) {
if ($a_networkport['mac'] != '') {
$a_networkports = $networkPort->find("`mac`='" . $a_networkport['mac'] . "'\n AND `itemtype`='PluginFusioninventoryUnmanaged'", "", 1);
if (count($a_networkports) > 0) {
$input = current($a_networkports);
$unmanageds_id = $input['items_id'];
$input['logical_number'] = $a_networkport['logical_number'];
$input['itemtype'] = 'Computer';
$input['items_id'] = $computers_id;
$input['is_dynamic'] = 1;
$input['name'] = $a_networkport['name'];
$networkPort->update($input, !$no_history);
$pfUnmanaged = new PluginFusioninventoryUnmanaged();
$pfUnmanaged->delete(array('id' => $unmanageds_id), 1);
}
}
}
// end get port from unknwon device
$db_networkport = array();
if ($no_history === FALSE) {
$query = "SELECT `id`, `name`, `mac`, `instantiation_type`, `logical_number`\n FROM `glpi_networkports`\n WHERE `items_id` = '{$computers_id}'\n AND `itemtype`='Computer'\n AND `is_dynamic`='1'";
$result = $DB->query($query);
while ($data = $DB->fetch_assoc($result)) {
$idtmp = $data['id'];
unset($data['id']);
if (is_null($data['mac'])) {
$data['mac'] = '';
}
if (preg_match("/[^a-zA-Z0-9 \\-_\\(\\)]+/", $data['name'])) {
$data['name'] = Toolbox::addslashes_deep($data['name']);
}
$db_networkport[$idtmp] = array_map('strtolower', $data);
}
}
$simplenetworkport = array();
foreach ($inventory_networkports as $key => $a_networkport) {
// Add ipnetwork if not exist
if ($a_networkport['gateway'] != '' && $a_networkport['netmask'] != '' && $a_networkport['subnet'] != '') {
if (countElementsInTable('glpi_ipnetworks', "`address`='" . $a_networkport['subnet'] . "'\n AND `netmask`='" . $a_networkport['netmask'] . "'\n AND `gateway`='" . $a_networkport['gateway'] . "'\n AND `entities_id`='" . $_SESSION["plugin_fusioninventory_entity"] . "'") == 0) {
$input_ipanetwork = array('name' => $a_networkport['subnet'] . '/' . $a_networkport['netmask'] . ' - ' . $a_networkport['gateway'], 'network' => $a_networkport['subnet'] . ' / ' . $a_networkport['netmask'], 'gateway' => $a_networkport['gateway'], 'entities_id' => $_SESSION["plugin_fusioninventory_entity"]);
$iPNetwork->add($input_ipanetwork, array(), !$no_history);
}
}
// End add ipnetwork
$a_field = array('name', 'mac', 'instantiation_type');
foreach ($a_field as $field) {
if (isset($a_networkport[$field])) {
$simplenetworkport[$key][$field] = $a_networkport[$field];
}
}
}
foreach ($simplenetworkport as $key => $arrays) {
$arrayslower = array_map('strtolower', $arrays);
foreach ($db_networkport as $keydb => $arraydb) {
$logical_number = $arraydb['logical_number'];
unset($arraydb['logical_number']);
if ($arrayslower == $arraydb) {
if ($inventory_networkports[$key]['logical_number'] != $logical_number) {
$input = array();
$input['id'] = $keydb;
$input['logical_number'] = $inventory_networkports[$key]['logical_number'];
$networkPort->update($input, !$no_history);
}
// Add / update instantiation_type
if (isset($inventory_networkports[$key]['instantiation_type'])) {
if ($inventory_networkports[$key]['instantiation_type'] == 'NetworkPortEthernet') {
$portsethernet = $networkPortEthernet->find("`networkports_id`='" . $keydb . "'", '', 1);
if (count($portsethernet) == 1) {
$portethernet = current($portsethernet);
$input = $portethernet;
} else {
$input = array('networkports_id' => $keydb);
}
if (isset($inventory_networkports[$key]['speed'])) {
$input['speed'] = $inventory_networkports[$key]['speed'];
$input['speed_other_value'] = $inventory_networkports[$key]['speed'];
}
if (isset($inventory_networkports[$key]['mac'])) {
$networkcards = $item_DeviceNetworkCard->find("`mac`='" . $inventory_networkports[$key]['mac'] . "' " . " AND `itemtype`='Computer'" . " AND `items_id`='" . $computers_id . "'", '', 1);
if (count($networkcards) == 1) {
$networkcard = current($networkcards);
$input['items_devicenetworkcards_id'] = $networkcard['id'];
}
}
$input['_no_history'] = $no_history;
if (isset($input['id'])) {
$networkPortEthernet->update($input);
} else {
$networkPortEthernet->add($input);
}
}
//.........这里部分代码省略.........
示例11: NetworkPortCreated
/**
* @test
*/
public function NetworkPortCreated()
{
global $DB;
$DB->connect();
$networkPort = new NetworkPort();
$a_networkports = $networkPort->find("`itemtype`='NetworkEquipment'");
$this->assertEquals(4, count($a_networkports), 'Number of networkport must be 4');
}
示例12: 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>";
}
示例13: 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);
//.........这里部分代码省略.........
示例14: 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);
//.........这里部分代码省略.........
示例15: configureNodesLinks
//.........这里部分代码省略.........
$elements[0] = Dropdown::EMPTY_VALUE;
$elements2 = array();
$result = $DB->query($query);
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']);
}
}
}
}