本文整理汇总了PHP中NetworkPort::getFromDB方法的典型用法代码示例。如果您正苦于以下问题:PHP NetworkPort::getFromDB方法的具体用法?PHP NetworkPort::getFromDB怎么用?PHP NetworkPort::getFromDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkPort
的用法示例。
在下文中一共展示了NetworkPort::getFromDB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: prepareInput
function prepareInput($input)
{
// Try to get mac address from the instantiation ...
if (!isset($input['mac']) && isset($input['networkports_id_alias'])) {
$networkPort = new NetworkPort();
if ($networkPort->getFromDB($input['networkports_id_alias'])) {
$input['mac'] = $networkPort->getField('mac');
}
}
return $input;
}
示例3: showNetworkPortDetail
/**
* Display detail networkport based on glpi core networkport and fusioninventory
* networkport
*
* @param array $data with id ant fusionid
* @param boolean $monitoring true if monitoring installed && actived
* @param boolean $aggrega true if this port is aggregate port
*
* @return nothing
*/
function showNetworkPortDetail($data, $monitoring, $aggrega = 0)
{
global $CFG_GLPI, $DB;
$nw = new NetworkPort_NetworkPort();
$networkName = new NetworkName();
$networkPort = new NetworkPort();
$pfNetworkPort = new PluginFusioninventoryNetworkPort();
$iPAddress = new IPAddress();
$networkPort->getFromDB($data['id']);
$pfNetworkPort->getFromDB($data['fusionid']);
$background_img = "";
if ($pfNetworkPort->fields["trunk"] == "1" && (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1)) {
$background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/port_trunk.png\"); '";
} else {
if (PluginFusioninventoryNetworkPort::isPortHasMultipleMac($data['id']) && (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1)) {
$background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/multiple_mac_addresses.png\"); '";
} else {
if (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1) {
$background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/connected_trunk.png\"); '";
}
}
}
echo "<tr class='tab_bg_1 center' height='40'" . $background_img . ">";
if ($aggrega) {
echo "<td style='background-color: #f2f2f2;'></td><td>";
}
if (!$aggrega) {
if ($networkPort->fields['instantiation_type'] == 'NetworkPortAggregate') {
echo "<td>";
} else {
echo "<td colspan='2'>";
}
}
echo "<a href='networkport.form.php?id=" . $networkPort->fields["id"] . "'>" . $networkPort->fields["name"] . "</a>";
Html::showToolTip($pfNetworkPort->fields['ifdescr']);
if (!$aggrega) {
if ($networkPort->fields['instantiation_type'] == 'NetworkPortAggregate') {
echo "<td><i><font style='color: grey'>" . __('Aggregation port') . "</font></i></td>";
}
}
if ($monitoring == '1') {
echo "<td>";
$state = PluginMonitoringNetworkport::isMonitoredNetworkport($data['id']);
if (Session::haveRight("plugin_monitoring_componentscatalog", UPDATE)) {
$checked = '';
if ($state) {
$checked = 'checked';
}
echo "<input type='checkbox' name='networkports_id[]' value='" . $data['id'] . "' " . $checked . "/>";
} else {
if (Session::haveRight("plugin_monitoring_componentscatalog", READ)) {
echo Dropdown::getYesNo($state);
}
}
echo "</td>";
}
$a_pref = DisplayPreference::getForTypeUser('PluginFusioninventoryNetworkport', Session::getLoginUserID());
foreach ($a_pref as $data_array) {
switch ($data_array) {
case 3:
echo "<td>" . $pfNetworkPort->fields["ifmtu"] . "</td>";
break;
case 5:
echo "<td>" . $this->byteSize($pfNetworkPort->fields["ifspeed"], 1000) . "bps</td>";
break;
case 6:
echo "<td>";
if (strstr($pfNetworkPort->fields["ifstatus"], "up") || strstr($pfNetworkPort->fields["ifinternalstatus"], "1")) {
echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png'/>";
} else {
if (strstr($pfNetworkPort->fields["ifstatus"], "down") || strstr($pfNetworkPort->fields["ifinternalstatus"], "2")) {
echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'/>";
} else {
if (strstr($pfNetworkPort->fields["ifstatus"], "testing") || strstr($pfNetworkPort->fields["ifinternalstatus"], "3")) {
echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/yellowbutton.png'/>";
}
}
}
echo "</td>";
break;
case 7:
echo "<td>" . $pfNetworkPort->fields["iflastchange"] . "</td>";
break;
case 8:
echo "<td>";
if ($pfNetworkPort->fields["ifinoctets"] == "0") {
echo "-";
} else {
echo $this->byteSize($pfNetworkPort->fields["ifinoctets"], 1000) . "o";
}
//.........这里部分代码省略.........
示例4: showForm
function showForm($ID, $options = array())
{
global $CFG_GLPI, $DB;
if (!self::canView()) {
return false;
}
$this->check($ID, READ);
$recursiveItems = $this->recursivelyGetItems();
if (count($recursiveItems) > 0) {
$lastItem = $recursiveItems[count($recursiveItems) - 1];
$lastItem_entities_id = $lastItem->getField('entities_id');
} else {
$lastItem_entities_id = $_SESSION['glpiactive_entity'];
}
$options['entities_id'] = $lastItem_entities_id;
$this->showFormHeader($options);
$options['canedit'] = false;
$options['candel'] = false;
$number_errors = 0;
foreach (self::getMotives() as $key => $name) {
if ($this->fields[$key] == 1) {
$number_errors++;
}
}
$motives = self::getMotives();
$interface_cell = "td";
$address_cell = "td";
$network_cell = "td";
$gateway_cell = "td";
$address = new IPAddress();
$netmask = new IPNetmask();
$number_real_errors = 0;
if (!$address->setAddressFromString($this->fields['ip']) || !$netmask->setNetmaskFromString($this->fields['netmask'], $address->getVersion())) {
unset($address);
unset($netmask);
} else {
$network = new IPNetwork();
$params = array("address" => $address, "netmask" => $netmask);
if (isset($this->fields["address"])) {
$params["exclude IDs"] = $this->fields["address"];
}
if (isset($this->fields["entities_id"])) {
$entity = $this->fields["entities_id"];
} else {
$entity = -1;
}
$networkports_ids = IPNetwork::searchNetworks("equals", $params, $entity, false);
if (count($networkports_ids) == 0) {
unset($network);
} else {
$network->getFromDB($networkports_ids[0]);
}
}
if ($this->fields['unknown_interface_type'] == 1) {
$options['canedit'] = true;
$number_real_errors++;
$interface_cell = "th";
echo "<tr class='tab_bg_1'><th>" . $motives['unknown_interface_type'] . "</th>\n" . "<td>" . __('Transform this network port to');
echo "</td><td colspan=2>";
Dropdown::showItemTypes('transform_to', NetworkPort::getNetworkPortInstantiations(), array('value' => "NetworkPortEthernet"));
echo "</td></tr>\n";
}
if ($this->fields['invalid_network'] == 1) {
$number_real_errors++;
$network_cell = "th";
$address_cell = "th";
echo "<tr class='tab_bg_1'><th>" . $motives['invalid_network'] . "</th>\n<td colspan=3>";
if (isset($network)) {
printf(__('Network port information conflicting with %s'), $network->getLink());
} else {
if (!isset($address) || !isset($netmask)) {
_e('Invalid address or netmask');
} else {
_e('No conflicting network');
}
echo " <a href='" . Toolbox::getItemTypeFormURL('IPNetwork') . "'>" . __('you may have to add a network') . "</a>";
}
echo "</td></tr>\n";
}
if ($this->fields['invalid_gateway'] == 1) {
$number_real_errors++;
$gateway_cell = "th";
echo "<tr class='tab_bg_1'><th>" . $motives['invalid_gateway'] . "</th>\n<td colspan=3>";
if (isset($network)) {
printf(__('Append a correct gateway to the network %s'), $network->getLink());
} else {
printf(__('%1$s: %2$s'), __('Unknown network'), "<a href='" . Toolbox::getItemTypeFormURL('IPNetwork') . "'>" . __('Add a network') . "\n </a>");
}
echo "</td></tr>\n";
}
if ($this->fields['invalid_address'] == 1) {
$number_real_errors++;
$address_cell = "th";
echo "<tr class='tab_bg_1'><th>" . $motives['invalid_address'] . "</th>\n<td colspan=3>";
$networkPort = new NetworkPort();
if ($networkPort->getFromDB($this->getID())) {
$number_real_errors++;
echo "<a href='" . $networkPort->getLinkURL() . "'>" . __('Add a correct IP to the network port') . "</a>";
} else {
_e('Unknown network port');
//.........这里部分代码省略.........
示例5: showForItem
/**
* Display form to unlock fields and links
*
* @param CommonDBTM $item the source item
**/
static function showForItem(CommonDBTM $item)
{
global $DB;
$ID = $item->getID();
$itemtype = $item->getType();
$header = false;
//If user doesn't have write right on the item, lock form must not be displayed
if (!$item->canCreate()) {
return false;
}
echo "<div width='50%'>";
echo "<form method='post' id='lock_form'\n name='lock_form' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
echo "<input type='hidden' name='id' value='{$ID}'>\n";
echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n";
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='2''>" . __('Locked items') . "</th></tr>";
//Use a hook to allow external inventory tools to manage per field lock
$results = Plugin::doHookFunction('display_locked_fields', array('item' => $item, 'header' => $header));
$header |= $results['header'];
//Special locks for computers only
if ($itemtype == 'Computer') {
//Locks for items recorded in glpi_computers_items table
$types = array('Monitor', 'Peripheral', 'Printer');
foreach ($types as $type) {
$params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID, 'itemtype' => $type);
$params['FIELDS'] = array('id', 'items_id');
$first = true;
foreach ($DB->request('glpi_computers_items', $params) as $line) {
$tmp = new $type();
$tmp->getFromDB($line['items_id']);
$header = true;
if ($first) {
echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
$first = false;
}
echo "<tr class='tab_bg_1'><td class='center' width='10'>";
echo "<input type='checkbox' name='Computer_Item[" . $line['id'] . "]'></td>";
echo "<td class='left' width='95%'>" . $tmp->getName() . "</td>";
echo "</tr>\n";
}
}
$types = array('ComputerDisk', 'ComputerVirtualMachine');
foreach ($types as $type) {
$params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
$params['FIELDS'] = array('id', 'name');
$first = true;
foreach ($DB->request(getTableForItemType($type), $params) as $line) {
$header = true;
if ($first) {
echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
$first = false;
}
echo "<tr class='tab_bg_1'><td class='center' width='10'>";
echo "<input type='checkbox' name='" . $type . "[" . $line['id'] . "]'></td>";
echo "<td class='left' width='95%'>" . $line['name'] . "</td>";
echo "</tr>\n";
}
}
//Software versions
$params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
$first = true;
$query = "SELECT `csv`.`id` AS `id`,\n `sv`.`name` AS `version`,\n `s`.`name` AS `software`\n FROM `glpi_computers_softwareversions` AS csv\n LEFT JOIN `glpi_softwareversions` AS sv\n ON (`csv`.`softwareversions_id` = `sv`.`id`)\n LEFT JOIN `glpi_softwares` AS s\n ON (`sv`.`softwares_id` = `s`.`id`)\n WHERE `csv`.`is_deleted` = '1'\n AND `csv`.`is_dynamic` = '1'\n AND `csv`.`computers_id` = '{$ID}'";
foreach ($DB->request($query) as $line) {
$header = true;
if ($first) {
echo "<tr><th colspan='2'>" . Software::getTypeName(2) . "</th></tr>\n";
$first = false;
}
echo "<tr class='tab_bg_1'><td class='center' width='10'>";
echo "<input type='checkbox' name='Computer_SoftwareVersion[" . $line['id'] . "]'></td>";
echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
echo "</tr>\n";
}
//Software licenses
$params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
$first = true;
$query = "SELECT `csv`.`id` AS `id`,\n `sv`.`name` AS `version`,\n `s`.`name` AS `software`\n FROM `glpi_computers_softwarelicenses` AS csv\n LEFT JOIN `glpi_softwarelicenses` AS sv\n ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n LEFT JOIN `glpi_softwares` AS s\n ON (`sv`.`softwares_id` = `s`.`id`)\n WHERE `csv`.`is_deleted` = '1'\n AND `csv`.`is_dynamic` = '1'\n AND `csv`.`computers_id` = '{$ID}'";
foreach ($DB->request($query) as $line) {
$header = true;
if ($first) {
echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n";
$first = false;
}
echo "<tr class='tab_bg_1'><td class='center' width='10'>";
echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>";
echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
echo "</tr>\n";
}
}
$first = true;
$item = new NetworkPort();
$params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype);
$params['FIELDS'] = array('id');
foreach ($DB->request('glpi_networkports', $params) as $line) {
$item->getFromDB($line['id']);
//.........这里部分代码省略.........
示例6: getInstantiationNetworkPortHTMLTable
/**
* \brief display the attached NetworkPort
*
* NetworkPortAlias and NetworkPortAggregate are based on other physical network ports
* (Ethernet or Wifi). This method displays the physical network ports.
**/
function getInstantiationNetworkPortHTMLTable()
{
$netports = array();
// Manage alias
if (isset($this->fields['networkports_id_alias'])) {
$links_id = $this->fields['networkports_id_alias'];
$netport = new NetworkPort();
if ($netport->getFromDB($links_id)) {
$netports[] = $netport->getLink();
}
}
// Manage aggregate
if (isset($this->fields['networkports_id_list'])) {
$links_id = $this->fields['networkports_id_list'];
$netport = new NetworkPort();
foreach ($links_id as $id) {
if ($netport->getFromDB($id)) {
$netports[] = $netport->getLink();
}
}
}
if (count($netports) > 0) {
return implode('<br>', $netports);
}
return " ";
}
示例7: 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;
}
}
}
}
示例8: displayGraphs
function displayGraphs($itemtype, $items_id)
{
global $CFG_GLPI;
$pmComponent = new PluginMonitoringComponent();
$pmConfig = new PluginMonitoringConfig();
$pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
$networkPort = new NetworkPort();
$item = new $itemtype();
$item->getFromDB($items_id);
$pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
PluginMonitoringToolbox::loadPreferences($pmComponent->fields['id']);
}
$css_width = '950';
if (isset($_GET['mobile'])) {
$css_width = '300';
}
echo "<table class='tab_cadre' width='" . $css_width . "'>";
echo "<tr class='tab_bg_1'>";
echo "<th>";
$title = Dropdown::getDropdownName(getTableForItemType('PluginMonitoringComponent'), $item->fields['plugin_monitoring_components_id']);
if (!is_null($item->fields['networkports_id']) && $item->fields['networkports_id'] > 0) {
$networkPort->getFromDB($item->fields['networkports_id']);
$title .= " [" . $networkPort->getLink() . "]";
}
$title .= ' ' . __('on', 'monitoring') . ' ';
$pmComponentscatalog_Host->getFromDB($item->fields["plugin_monitoring_componentscatalogs_hosts_id"]);
if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') {
$itemtype2 = $pmComponentscatalog_Host->fields['itemtype'];
$item2 = new $itemtype2();
$item2->getFromDB($pmComponentscatalog_Host->fields['items_id']);
$title .= str_replace("'", "\"", $item2->getLink() . " (" . $item2->getTypeName() . ")");
}
echo $title;
echo "</th>";
echo "<th width='200'>";
if (!isset($_GET['mobile'])) {
echo "<form method='post'>";
$a_timezones = PluginMonitoringConfig::getTimezones();
if (!isset($_SESSION['plugin_monitoring_timezone'])) {
$_SESSION['plugin_monitoring_timezone'] = '0';
}
$a_timezones_allowed = array();
$pmConfig->getFromDB(1);
$a_temp = importArrayFromDB($pmConfig->fields['timezones']);
foreach ($a_temp as $key) {
$a_timezones_allowed[$key] = $a_timezones[$key];
}
if (count($a_timezones_allowed) == '0') {
$a_timezones_allowed['0'] = $a_timezones['0'];
}
Dropdown::showFromArray('plugin_monitoring_timezone', $a_timezones_allowed, array('value' => $_SESSION['plugin_monitoring_timezone']));
echo " <input type='submit' name='update' value=\"" . __('Save') . "\" class='submit'>";
Html::closeForm();
}
echo "</th>";
echo "</tr>";
$timezone = '0';
if (isset($_SESSION['plugin_monitoring_timezone'])) {
$timezone = $_SESSION['plugin_monitoring_timezone'];
}
if (!isset($_GET['mobile'])) {
echo "<tr class='tab_bg_1'>";
echo "<th colspan='2'>";
echo "<div id='legendlink'><a onClick='\$(\"#options\").toggle();'>[ Options ]</a></div>";
echo "</th>";
echo "</tr>";
// * Display perfname
echo "<tr class='tab_bg_1'>";
echo "<td colspan='2'>";
echo "<div id='options' style='display:none'>";
PluginMonitoringToolbox::preferences($pmComponent->fields['id'], 0);
echo "</div>";
echo "</td>";
echo "</tr>";
// * Display date slider
echo "<tr class='tab_bg_1'>";
echo "<th colspan='2'>";
echo __('Select date', 'monitoring') . " - " . __('Select time', 'monitoring');
echo "</th>";
echo "</tr>";
echo "<tr class='tab_bg_1'>";
echo "<th colspan='2'>";
$start = time();
$oldvalue = current(getAllDatasFromTable('glpi_plugin_monitoring_serviceevents', "`plugin_monitoring_services_id`='" . $items_id . "'", false, 'date ASC LIMIT 1'));
$date = new DateTime($oldvalue['date']);
if ($date->getTimestamp() < $start) {
$start = $date->getTimestamp();
}
$nbdays = round((date('U') - $start) / 86400);
echo "<script type=\"text/javascript\">\n \$(function() {\n \$( \"#custom_date\" ).datepicker({ minDate: -" . $nbdays . ", maxDate: \"+0D\", dateFormat:'mm/dd/yy' });\n \$( \"#custom_time\" ).timepicker();\n\n });\n </script>";
echo '<center><input type="text" id="custom_date" value="' . date('m/d/Y') . '"> ' . ' <input type="text" id="custom_time" value="' . date('H:i') . '"></center>';
echo "</th>";
echo "</tr>";
}
$a_list = array();
$a_list["2h"] = __("Last 2 hours", "monitoring");
$a_list["12h"] = __("Last 12 hours", "monitoring");
$a_list["1d"] = __("Last 24 hours", "monitoring");
$a_list["1w"] = __("Last 7 days (average)", "monitoring");
//.........这里部分代码省略.........
示例9: NetworkPort
function post_deleteFromDB()
{
// Update to blank networking item
// clean datas of linked ports if network one
$np1 = new NetworkPort();
$np2 = new NetworkPort();
if ($np1->getFromDB($this->fields['networkports_id_1']) && $np2->getFromDB($this->fields['networkports_id_2'])) {
$npnet = NULL;
$npdev = NULL;
if ($np1->fields["itemtype"] != 'NetworkEquipment' && $np2->fields["itemtype"] == 'NetworkEquipment') {
$npnet = $np2;
$npdev = $np1;
}
if ($np2->fields["itemtype"] != 'NetworkEquipment' && $np1->fields["itemtype"] == 'NetworkEquipment') {
$npnet = $np2;
$npdev = $np1;
}
if ($npnet && $npdev) {
// If addresses are egal, was copied from device in GLPI 0.71 : clear it
// Unset MAC and IP from networking device
if ($npnet->fields['mac'] == $npdev->fields['mac']) {
$npnet->update(array('id' => $npnet->fields['id'], 'mac' => ''));
}
if ($np1->fields['ip'] == $np2->fields['ip']) {
$npnet->update(array('id' => $npnet->fields['id'], 'ip' => '', 'netmask' => '', 'subnet' => '', 'gateway' => ''));
}
// Unset netpoint from common device
$npdev->update(array('id' => $npdev->fields['id'], 'netpoints_id' => 0));
}
// Manage history
$name = NOT_AVAILABLE;
$dohistory = false;
if (class_exists($np2->fields["itemtype"])) {
$item = new $np2->fields["itemtype"]();
if ($item->getFromDB($np2->fields["items_id"])) {
$name = $item->getName();
$dohistory = $item->dohistory;
}
}
if ($dohistory) {
$changes[0] = 0;
$changes[1] = $name;
$changes[2] = '';
if ($np1->fields["itemtype"] == 'NetworkEquipment') {
$changes[1] = "#" . $np1->fields["name"] . " > " . $changes[1];
}
if ($np2->fields["itemtype"] == 'NetworkEquipment') {
$changes[1] = $changes[1] . " > #" . $np2->fields["name"];
}
Log::history($np1->fields["items_id"], $np1->fields["itemtype"], $changes, $np2->fields["itemtype"], HISTORY_DISCONNECT_DEVICE);
}
$name = NOT_AVAILABLE;
$dohistory = false;
if (class_exists($np1->fields["itemtype"])) {
$item = new $np1->fields["itemtype"]();
if ($item->getFromDB($np1->fields["items_id"])) {
$name = $item->getName();
$dohistory = $item->dohistory;
}
}
if ($dohistory) {
$changes[0] = 0;
$changes[1] = $name;
$changes[2] = '';
if ($np2->fields["itemtype"] == 'NetworkEquipment') {
$changes[1] = "#" . $np2->fields["name"] . " > " . $changes[1];
}
if ($np1->fields["itemtype"] == 'NetworkEquipment') {
$changes[1] = $changes[1] . " > #" . $np1->fields["name"];
}
Log::history($np2->fields["items_id"], $np2->fields["itemtype"], $changes, $np1->fields["itemtype"], HISTORY_DISCONNECT_DEVICE);
}
}
}
示例10: 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;
}
示例11: Infocom
function post_addItem()
{
global $DB, $CFG_GLPI;
// Manage add from template
if (isset($this->input["_oldID"])) {
// ADD Infocoms
$ic = new Infocom();
$ic->cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
// ADD Ports
$query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "'";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_array($result)) {
$np = new NetworkPort();
$npv = new NetworkPort_Vlan();
$np->getFromDB($data["id"]);
unset($np->fields["id"]);
unset($np->fields["ip"]);
unset($np->fields["mac"]);
unset($np->fields["netpoints_id"]);
$np->fields["items_id"] = $this->fields['id'];
$portid = $np->addToDB();
foreach ($DB->request('glpi_networkports_vlans', array('networkports_id' => $data["id"])) as $vlan) {
$npv->assignVlan($portid, $vlan['vlans_id']);
}
}
}
// ADD Contract
$query = "SELECT `contracts_id`\n FROM `glpi_contracts_items`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "'";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
$contractitem = new Contract_Item();
while ($data = $DB->fetch_array($result)) {
$contractitem->add(array('contracts_id' => $data["contracts_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
}
}
// ADD Documents
$query = "SELECT `documents_id`\n FROM `glpi_documents_items`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "'";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
$docitem = new Document_Item();
while ($data = $DB->fetch_array($result)) {
$docitem->add(array('documents_id' => $data["documents_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
}
}
}
}
示例12: linkComponentsToItem
function linkComponentsToItem($componentscatalogs_id, $componentscatalogs_hosts_id, $networkports_id = 0)
{
global $DB;
$pmService = new PluginMonitoringService();
$pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
$pmComponentscatalog_Host->getFromDB($componentscatalogs_hosts_id);
$query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_components`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'";
$result = $DB->query($query);
while ($data = $DB->fetch_array($result)) {
$input = array();
$itemtype = $pmComponentscatalog_Host->fields['itemtype'];
$item = new $itemtype();
$item->getFromDB($pmComponentscatalog_Host->fields['items_id']);
if ($networkports_id == 0) {
$input['entities_id'] = $item->fields['entities_id'];
$input['plugin_monitoring_componentscatalogs_hosts_id'] = $componentscatalogs_hosts_id;
$input['plugin_monitoring_components_id'] = $data['plugin_monitoring_components_id'];
$input['name'] = Dropdown::getDropdownName("glpi_plugin_monitoring_components", $data['plugin_monitoring_components_id']);
$input['state'] = 'WARNING';
$input['state_type'] = 'HARD';
$pmService->add($input);
} else {
if ($networkports_id > 0) {
$a_services = $pmService->find("`plugin_monitoring_components_id`='" . $data['plugin_monitoring_components_id'] . "'\n AND `plugin_monitoring_componentscatalogs_hosts_id`='" . $componentscatalogs_hosts_id . "'\n AND `networkports_id`='" . $networkports_id . "'", "", 1);
$item = new NetworkPort();
$item->getFromDB($networkports_id);
if (count($a_services) == 0) {
$input = array();
$input['networkports_id'] = $networkports_id;
$input['entities_id'] = $item->fields['entities_id'];
$input['plugin_monitoring_componentscatalogs_hosts_id'] = $componentscatalogs_hosts_id;
$input['plugin_monitoring_components_id'] = $data['plugin_monitoring_components_id'];
$input['name'] = Dropdown::getDropdownName("glpi_plugin_monitoring_components", $data['plugin_monitoring_components_id']);
$input['state'] = 'WARNING';
$input['state_type'] = 'HARD';
$pmService->add($input);
} else {
$a_service = current($a_services);
$queryu = "UPDATE `glpi_plugin_monitoring_services`\n SET `entities_id`='" . $item->fields['entities_id'] . "'\n WHERE `id`='" . $a_service['id'] . "'";
$DB->query($queryu);
}
}
}
}
}
示例13: ImportNetworkEquipment
/**
* @test
*/
public function ImportNetworkEquipment()
{
global $DB;
self::restore_database();
// Load session rights
$_SESSION['glpidefault_entity'] = 0;
Session::initEntityProfiles(2);
Session::changeProfile(4);
$pfUnmanaged = new PluginFusioninventoryUnmanaged();
$networkEquipment = new NetworkEquipment();
$networkPort = new NetworkPort();
$networkName = new NetworkName();
$iPAddress = new IPAddress();
$input = array('name' => 'switch', 'entities_id' => 0, 'item_type' => 'NetworkEquipment', 'sysdescr' => 'Cisco machin chose', 'locations_id' => 1, 'is_dynamic' => 1, 'serial' => 'XXS6BEF3', 'comment' => 'this is a comment', 'plugin_fusioninventory_configsecurities_id' => 1);
$unmanageds_id = $pfUnmanaged->add($input);
// * Add networkport
$input = array();
$input['itemtype'] = 'PluginFusioninventoryUnmanaged';
$input['items_id'] = $unmanageds_id;
$input['instantiation_type'] = 'NetworkPortEthernet';
$input['name'] = 'general';
$input['mac'] = '00:00:00:43:ae:0f';
$input['is_dynamic'] = 1;
$networkports_id = $networkPort->add($input);
$input = array();
$input['items_id'] = $networkports_id;
$input['itemtype'] = 'NetworkPort';
$input['name'] = '';
$input['is_dynamic'] = 1;
$networknames_id = $networkName->add($input);
$input = array();
$input['entities_id'] = 0;
$input['itemtype'] = 'NetworkName';
$input['items_id'] = $networknames_id;
$input['name'] = '192.168.20.1';
$input['is_dynamic'] = 1;
$iPAddress->add($input);
$pfUnmanaged->import($unmanageds_id);
$cnt = countElementsInTable("glpi_networkequipments");
$this->assertEquals(1, $cnt, "May have network equipment added");
$cnt = countElementsInTable("glpi_plugin_fusioninventory_unmanageds");
$this->assertEquals(0, $cnt, "Unknown device may be deleted");
$networkEquipment->getFromDB(1);
$this->assertEquals('XXS6BEF3', $networkEquipment->fields['serial'], "Serial");
$this->assertEquals('switch', $networkEquipment->fields['name'], "Name");
$this->assertEquals(1, $networkEquipment->fields['is_dynamic'], "is_dynamic");
$this->assertEquals(1, $networkEquipment->fields['locations_id'], "locations_id");
$this->assertEquals('this is a comment', $networkEquipment->fields['comment'], "comment");
$networkPort->getFromDB(1);
$a_reference = array('name' => 'general', 'id' => '1', 'items_id' => '1', 'itemtype' => 'NetworkEquipment', 'entities_id' => '0', 'is_recursive' => '0', 'logical_number' => '0', 'instantiation_type' => 'NetworkPortEthernet', 'mac' => '00:00:00:43:ae:0f', 'comment' => '', 'is_deleted' => '0', 'is_dynamic' => '1');
$this->assertEquals($a_reference, $networkPort->fields, "Networkport");
$networkName->getFromDB(1);
$a_reference = array('id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkPort', 'comment' => NULL, 'fqdns_id' => '0', 'is_deleted' => '0', 'is_dynamic' => '1', 'name' => '');
$this->assertEquals($a_reference, $networkName->fields, "Networkname");
$iPAddress->getFromDB(1);
$a_reference = array('name' => '192.168.20.1', 'id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkName', 'version' => '4', 'binary_0' => '0', 'binary_1' => '0', 'binary_2' => '65535', 'binary_3' => '3232240641', 'is_deleted' => '0', 'is_dynamic' => '1', 'mainitems_id' => '1', 'mainitemtype' => 'NetworkEquipment');
$this->assertEquals($a_reference, $iPAddress->fields, "IPAddress");
}
示例14: displayLine
static function displayLine($data, $displayhost = 1)
{
global $DB, $CFG_GLPI, $LANG;
$pMonitoringService = new PluginMonitoringService();
$networkPort = new NetworkPort();
$pMonitoringComponent = new PluginMonitoringComponent();
$pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
$pmServicegraph = new PluginMonitoringServicegraph();
$entity = new Entity();
$pMonitoringService->getFromDB($data['id']);
echo "<td width='32' class='center'>";
$shortstate = self::getState($data['state'], $data['state_type']);
echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/box_" . $shortstate . "_32.png'/>";
echo "</td>";
echo "<td>";
$entity->getFromDB($data['entities_id']);
echo $entity->fields['completename'];
echo "</td>";
$pMonitoringComponent->getFromDB($data['plugin_monitoring_components_id']);
echo "<td class='center'>";
$img = '';
$timezone = '0';
if (isset($_SESSION['plugin_monitoring_timezone'])) {
$timezone = $_SESSION['plugin_monitoring_timezone'];
}
$timezone_file = str_replace("+", ".", $timezone);
$img = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=PluginMonitoringService-" . $data['id'] . "-2h" . $timezone_file . ".png'/>";
echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/display.form.php?itemtype=PluginMonitoringService&items_id=" . $data['id'] . "'>";
if (file_exists(GLPI_ROOT . "/files/_plugins/monitoring/PluginMonitoringService-" . $data['id'] . "-2h" . $timezone_file . ".png") or $pMonitoringComponent->fields['graph_template'] != '') {
$img = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=PluginMonitoringService-" . $data['id'] . "-2h" . $timezone_file . ".png'/>";
showToolTip($img, array('img' => $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/stats_32.png"));
} else {
}
echo "</a>";
echo "</td>";
if ($displayhost == '1') {
$pmComponentscatalog_Host->getFromDB($data["plugin_monitoring_componentscatalogs_hosts_id"]);
if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') {
$itemtype = $pmComponentscatalog_Host->fields['itemtype'];
$item = new $itemtype();
$item->getFromDB($pmComponentscatalog_Host->fields['items_id']);
echo "<td>";
echo $item->getTypeName() . " : " . $item->getLink();
if (!is_null($pMonitoringService->fields['networkports_id']) and $pMonitoringService->fields['networkports_id'] > 0) {
$networkPort->getFromDB($pMonitoringService->fields['networkports_id']);
echo " [" . $networkPort->getLink() . "]";
}
echo "</td>";
} else {
echo "<td>" . $LANG['plugin_monitoring']['service'][0] . "</td>";
}
}
echo "<td>" . $pMonitoringComponent->getLink();
if (!is_null($pMonitoringService->fields['networkports_id']) and $pMonitoringService->fields['networkports_id'] > 0) {
$networkPort->getFromDB($pMonitoringService->fields['networkports_id']);
echo " [" . $networkPort->getLink() . "]";
}
echo "</td>";
// $nameitem = '';
// if (isset($itemmat->fields['name'])) {
// $nameitem = "[".$itemmat->getLink(1)."]";
// }
//if ($pMonitoringService->fields['plugin_monitoring_services_id'] == '0') {
//echo "<td>".$itemmat->getLink(1)."</td>";
// } else {
// $pMonitoringServiceH->getFromDB($pMonitoringService->fields['plugin_monitoring_services_id']);
// $itemtypemat = $pMonitoringServiceH->fields['itemtype'];
// $itemmat = new $itemtypemat();
// $itemmat->getFromDB($pMonitoringServiceH->fields['items_id']);
// echo "<td>".$pMonitoringService->getLink(1).$nameitem." ".$LANG['networking'][25]." ".$itemmat->getLink(1)."</td>";
// }
// unset($itemmat);
echo "<td class='center'>";
echo $data['state'];
echo "</td>";
echo "<td>";
echo convDate($data['last_check']) . ' ' . substr($data['last_check'], 11, 8);
echo "</td>";
echo "<td>";
echo $data['event'];
echo "</td>";
echo "<td align='center'>";
$segments = CalendarSegment::getSegmentsBetween($pMonitoringComponent->fields['calendars_id'], date('w', date('U')), date('H:i:s'), date('w', date('U')), date('H:i:s'));
if (count($segments) == '0') {
echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/service_pause.png' />";
} else {
echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/service_run.png' />";
}
echo "</td>";
if ($displayhost == '0') {
$pmUnavaibility = new PluginMonitoringUnavaibility();
$pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'currentmonth', 1);
$pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'lastmonth', 1);
$pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'currentyear', 1);
echo "<td>";
$a_arg = importArrayFromDB($pMonitoringService->fields['arguments']);
$cnt = '';
if (count($a_arg) > 0) {
$cnt = " (" . count($a_arg) . ")";
}
//.........这里部分代码省略.........
示例15: NetworkPortConnection
/**
* @test
*/
public function NetworkPortConnection()
{
global $DB;
$DB->connect();
$networkPort = new NetworkPort();
$networkPort_NetworkPort = new NetworkPort_NetworkPort();
$pfUnmanaged = new PluginFusioninventoryUnmanaged();
$a_networkports = $networkPort->find("`logical_number`='10001'");
$this->assertEquals(1, count($a_networkports), 'Number of networkport 10001 may be 1');
$a_networkport = current($a_networkports);
$opposites_id = $networkPort_NetworkPort->getOppositeContact($a_networkport['id']);
$networkPort->getFromDB($opposites_id);
$pfUnmanaged->getFromDB($networkPort->fields['items_id']);
$this->assertEquals(0, $pfUnmanaged->fields['hub'], 'May not be a hub');
$a_networkports = $networkPort->find("`items_id`='" . $pfUnmanaged->fields['id'] . "'\n AND `itemtype`='PluginFusioninventoryUnmanaged'");
$this->assertEquals(1, count($a_networkports), 'Number of networkport of unknown ports may be 1');
}