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; } } } }
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; }
/** * 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"; } echo " / "; if ($pfNetworkPort->fields["ifinoctets"] == "0") { echo "-"; } else { echo $this->byteSize($pfNetworkPort->fields["ifoutoctets"], 1000) . "o"; } echo "</td>"; break; case 9: $color = ''; if ($pfNetworkPort->fields["ifinerrors"] != "0" || $pfNetworkPort->fields["ifouterrors"] != "0") { $color = "background='#cf9b9b' class='tab_bg_1_2'"; } if ($pfNetworkPort->fields["ifinerrors"] == "0") { echo "<td " . $color . ">-"; } else { echo "<td " . $color . ">"; echo $pfNetworkPort->fields["ifinerrors"]; } echo " / "; if ($pfNetworkPort->fields["ifouterrors"] == "0") { echo "-"; } else { echo $pfNetworkPort->fields["ifouterrors"]; } echo "</td>"; break; case 10: if ($pfNetworkPort->fields["portduplex"] == 2) { echo "<td background='#cf9b9b' class='tab_bg_1_2'>"; echo __('Half', 'fusioninventory'); echo '</td>'; } else { if ($pfNetworkPort->fields["portduplex"] == 3) { echo '<td>'; echo __('Full', 'fusioninventory'); echo '</td>'; } else { echo "<td></td>"; } } break; case 11: // ** internal mac echo "<td>" . $networkPort->fields["mac"] . "</td>"; break; case 13: // ** Mac address and link to device which are connected to this port $opposite_port = $nw->getOppositeContact($data["id"]); if ($opposite_port != "" && $opposite_port != 0) { $networkPortOpposite = new NetworkPort(); if ($networkPortOpposite->getFromDB($opposite_port)) { $data_device = $networkPortOpposite->fields; $item = new $data_device["itemtype"](); $item->getFromDB($data_device["items_id"]); $link1 = $item->getLink(1); $link = str_replace($item->getName(0), $data_device["mac"], $item->getLink()); // * GetIP $a_networknames = current($networkName->find("`itemtype`='NetworkPort'\n AND `items_id`='" . $item->getID() . "'", "", 1)); $a_ipaddresses = current($iPAddress->find("`itemtype`='NetworkName'\n AND `items_id`='" . $a_networknames['id'] . "'", "", 1)); $link2 = str_replace($item->getName(0), $a_ipaddresses['name'], $item->getLink()); if ($data_device["itemtype"] == 'PluginFusioninventoryUnmanaged') { $icon = $this->getItemtypeIcon($item->fields["item_type"]); if ($item->getField("accepted") == "1") { echo "<td style='background:#bfec75'\n class='tab_bg_1_2'>" . $icon . $link1; } else { echo "<td background='#cf9b9b'\n class='tab_bg_1_2'>" . $icon . $link1; } if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } if ($item->getField("hub") == "1") { $this->displayHubConnections($data_device["items_id"], $background_img); } echo "</td>"; } else { $icon = $this->getItemtypeIcon($data_device["itemtype"]); echo "<td>" . $icon . $link1; if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } if ($data_device["itemtype"] == 'Phone') { $query_devicephone = "SELECT *\n FROM `glpi_networkports`\n WHERE `itemtype`='Phone'\n AND `items_id`='" . $data_device["items_id"] . "'\n AND `id`!='" . $data_device["id"] . "'\n LIMIT 1"; $result_devicephone = $DB->query($query_devicephone); if ($DB->numrows($result_devicephone) > 0) { $data_devicephone = $DB->fetch_assoc($result_devicephone); $computer_ports_id = $nw->getOppositeContact($data_devicephone["id"]); if ($computer_ports_id) { $networkport = new NetworkPort(); $networkport->getFromDB($computer_ports_id); if ($networkport->fields['itemtype'] == 'Computer') { echo "<hr/>"; echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/computer_icon.png' " . "style='float:left'/> "; $computer = new Computer(); $computer->getFromDB($networkport->fields["items_id"]); $link1 = $computer->getLink(1); $link = str_replace($computer->getName(0), $networkport->fields["mac"], $computer->getLink()); $link2 = str_replace($computer->getName(0), $networkport->fields["ip"], $computer->getLink()); echo $icon . $link1; if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } } } } } echo "</td>"; } } else { echo "<td></td>"; } } else { echo "<td></td>"; } break; case 14: // ** Connection status echo "<td>"; if (strstr($pfNetworkPort->fields["ifstatus"], "up") || strstr($pfNetworkPort->fields["ifstatus"], "1")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/wired_on.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "down") || strstr($pfNetworkPort->fields["ifstatus"], "2")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/wired_off.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "testing") || strstr($pfNetworkPort->fields["ifstatus"], "3")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/yellowbutton.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "dormant") || strstr($pfNetworkPort->fields["ifstatus"], "5")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/orangebutton.png'/>"; } } } } echo "</td>"; break; case 12: echo "<td>"; $canedit = Session::haveRight('networking', UPDATE); $used = array(); $query_vlan = "SELECT * FROM glpi_networkports_vlans\n WHERE networkports_id='" . $data["id"] . "'"; $result_vlan = $DB->query($query_vlan); if ($DB->numrows($result_vlan) > 0) { echo "<table cellpadding='0' cellspacing='0'>"; while ($line = $DB->fetch_array($result_vlan)) { $used[] = $line["vlans_id"]; $vlan = new Vlan(); $vlan->getFromDB($line["vlans_id"]); if ($line['tagged'] == '1') { $state = 'T'; } else { $state = 'U'; } echo "<tr><td>" . $vlan->fields['name'] . " [" . $vlan->fields['tag'] . "] " . $state; echo "</td><td>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?unassign_vlan=unassigned&id=" . $line["id"] . "'>"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/delete.png\" alt='" . __('Delete', 'fusioninventory') . "' title='" . __('Delete', 'fusioninventory') . "'></a>"; } else { echo " "; } echo "</td>"; echo "</tr>"; } echo "</table>"; } else { echo " "; } echo "</td>"; break; case 15: echo "<td align='center'>"; if ($pfNetworkPort->fields['ifstatus'] == 1) { echo __('Connected'); } else { if ($pfNetworkPort->fields['lastup'] == "0000-00-00 00:00:00") { echo '-'; } else { $time = strtotime(date('Y-m-d H:i:s')) - strtotime($pfNetworkPort->fields['lastup']); echo Html::timestampToString($time, FALSE); } } echo "</td>"; break; case 16: echo "<td>" . $pfNetworkPort->fields["ifalias"] . "</td>"; break; } } echo "</tr>"; }
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'); } echo "</td></tr>\n"; } if ($number_real_errors == 0) { echo "<tr class='tab_bg_1'><th colspan='3'>" . __('I don\'t understand why this migration error is not deleted.'); echo "</th><th>"; Html::showSimpleForm($this->getFormURL(), 'delete', __('You can delete this migration error'), array('id' => $this->getID())); echo "</th></tr>\n"; } else { echo "<tr class='tab_bg_1'><th>" . __('At all events') . "</th>\n"; echo "<td colspan='3'>"; Html::showSimpleForm($this->getFormURL(), 'delete', __('You can delete this migration error'), array('id' => $this->getID())); echo "</td></tr>\n"; } echo "<tr class='tab_bg_1'><td colspan='4'> </td></tr>\n"; echo "<tr class='tab_bg_1'><th colspan='4'>" . __('Original network port information') . "</th>" . "</tr>\n"; echo "<tr class='tab_bg_1'><td>"; $this->displayRecursiveItems($recursiveItems, 'Type'); echo "</td>\n<td>"; $this->displayRecursiveItems($recursiveItems, "Link"); echo "</td>\n"; echo "<td>" . __('Comments') . "</td>"; echo "<td class='middle'>" . $this->fields["comment"] . "</td></tr>\n"; echo "<tr class='tab_bg_1'><td>" . __('Network address') . "</td>\n"; echo "<{$network_cell}>" . $this->fields['subnet'] . "</{$network_cell}>\n"; echo "<td>" . IPNetmask::getTypeName(1) . "</td>\n"; echo "<{$network_cell}>" . $this->fields['netmask'] . "</{$network_cell}></tr>\n"; echo "<tr class='tab_bg_1'><td>" . IPAddress::getTypeName(1) . "</td>\n"; echo "<{$address_cell}>" . $this->fields['ip'] . "</{$address_cell}>\n"; echo "<td>" . __('Gateway') . "</td>\n"; echo "<{$gateway_cell}>" . $this->fields['gateway'] . "</{$gateway_cell}></tr>\n"; echo "<tr class='tab_bg_1'><td>" . __('Network interface') . "</td><{$interface_cell}>\n"; if (TableExists('glpi_networkinterfaces')) { $query = "SELECT `name`\n FROM `glpi_networkinterfaces`\n WHERE `id`='" . $this->fields['networkinterfaces_id'] . "'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); echo $row['name']; } else { _e('Unknown interface'); } } echo "</{$interface_cell}>"; echo "<{$interface_cell}></{$interface_cell}>"; echo "<{$interface_cell}></{$interface_cell}></tr>\n"; $this->showFormButtons($options); }
/** * 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']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . NetworkPort::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='NetworkPort[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $first = true; $item = new NetworkName(); $params = array('`glpi_networknames`.`is_dynamic`' => 1, '`glpi_networknames`.`is_deleted`' => 1, '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype); $params['FIELDS'] = array('glpi_networknames' => 'id'); foreach ($DB->request(array('glpi_networknames', 'glpi_networkports'), $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . NetworkName::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='NetworkName[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $first = true; $item = new IPAddress(); $params = array('`glpi_ipaddresses`.`is_dynamic`' => 1, '`glpi_ipaddresses`.`is_deleted`' => 1, '`glpi_ipaddresses`.`itemtype`' => 'Networkname', '`glpi_ipaddresses`.`items_id`' => '`glpi_networknames`.`id`', '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype); $params['FIELDS'] = array('glpi_ipaddresses' => 'id'); foreach ($DB->request(array('glpi_ipaddresses', 'glpi_networknames', 'glpi_networkports'), $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . IPAddress::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='IPAddress[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $types = Item_Devices::getDeviceTypes(); $nb = 0; foreach ($types as $old => $type) { $nb += countElementsInTable(getTableForItemType($type), "`items_id`='{$ID}'\n AND `itemtype`='{$itemtype}'\n AND `is_dynamic`='1'\n AND `is_deleted`='1'"); } if ($nb) { $header = true; echo "<tr><th colspan='2'>" . _n('Component', 'Components', 2) . "</th></tr>\n"; foreach ($types as $old => $type) { $associated_type = str_replace('Item_', '', $type); $associated_table = getTableForItemType($associated_type); $fk = getForeignKeyFieldForTable($associated_table); $query = "SELECT `i`.`id`,\n `t`.`designation` AS `name`\n FROM `" . getTableForItemType($type) . "` AS i\n LEFT JOIN `{$associated_table}` AS t\n ON (`t`.`id` = `i`.`{$fk}`)\n WHERE `itemtype` = '{$itemtype}'\n AND `items_id` = '{$ID}'\n AND `is_dynamic` = '1'\n AND `is_deleted` = '1'"; foreach ($DB->request($query) as $data) { echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='" . $type . "[" . $data['id'] . "]'></td>"; echo "<td class='left' width='95%'>"; printf(__('%1$s: %2$s'), $associated_type::getTypeName(), $data['name']); echo "</td></tr>\n"; } } } if ($header) { echo "</table>"; Html::openArrowMassives('lock_form', true); Html::closeArrowMassives(array('unlock' => _sx('button', 'Unlock'))); } else { echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='2'>" . __('No locked item') . "</td></tr>"; echo "</table>"; } Html::closeForm(); echo "</div>\n"; }
/** * \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 " "; }
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; } } } }
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"); // $a_list["1m"] = __("Last month (average)", "monitoring"); // $a_list["0y6m"] = __("Last 6 months (average)", "monitoring"); // $a_list["1y"] = __("Last year (average)", "monitoring"); foreach ($a_list as $time => $name) { echo "<tr class='tab_bg_1'>"; echo "<th colspan='2'>"; echo $name; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center' colspan='2' style='position: relative'>"; $pmServicegraph = new PluginMonitoringServicegraph(); $part = ''; $width = '950'; if (isset($_GET['mobile'])) { $width = '294'; } $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], $itemtype, $items_id, $timezone, $time, $part, $width); echo "</td>"; echo "</tr>"; } echo "</table>"; }
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); } } }
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; }
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'])); } } } }
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); } } } } }
/** * @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"); }
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) . ")"; } echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/servicearg.form.php?id=" . $data['id'] . "'>" . $LANG['plugin_monitoring']['service'][25] . $cnt . "</a>"; echo "</td>"; } }
/** * @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'); }
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); } } } }
/** * @param $mac * @param $name * @param $computers_id * @param $instantiation_type * @param $inst_input * @param $ips * @param $check_name * @param $dohistory * @param $already_known_ports * @return ID */ private static function updateNetworkPort($mac, $name, $computers_id, $instantiation_type, $inst_input, $ips, $check_name, $dohistory, $already_known_ports) { global $DB; $network_port = new NetworkPort(); // Then, find or create the base NetworkPort $query = "SELECT `id`, `is_dynamic`\n FROM `glpi_networkports`\n WHERE `itemtype` = 'Computer'\n AND `items_id` = '{$computers_id}'\n AND `mac` = '{$mac}'"; // If there is virtual ports, then, filter by port's name if ($check_name) { $query .= " AND `name` = '{$name}'"; } if (count($already_known_ports) > 0) { $query .= " AND `id` NOT IN (" . implode(',', $already_known_ports) . ")"; } // We order by is_dynamic to be sure to get the static ones first ! $query .= " ORDER BY `is_dynamic`, `id`"; $ports = $DB->request($query); if ($ports->numrows() == 0) { $port_input = array('name' => $name, 'mac' => $mac, 'items_id' => $computers_id, 'itemtype' => 'Computer', '_no_history' => !$dohistory, 'instantiation_type' => $instantiation_type, '_create_children' => 1, 'is_dynamic' => 1, 'is_deleted' => 0); $networkports_id = $network_port->add($port_input, array(), $dohistory); if ($networkports_id === false) { return -1; } $inst_input['networkports_id'] = $networkports_id; $instantiation = $network_port->getInstantiation(); $instantiation->update($inst_input); unset($instantiation); } else { $line = $ports->next(); $networkports_id = $line['id']; $network_port->getFromDB($networkports_id); if (!$check_name && $network_port->fields['name'] != $name) { $port_input = array('id' => $network_port->getID(), 'name' => $name, 'is_dynamic' => 1); $network_port->update($port_input); } if ($network_port->fields['instantiation_type'] != $instantiation_type && $network_port->fields['is_dynamic'] == 1) { $network_port->switchInstantiationType($instantiation_type); $inst_input['networkports_id'] = $network_port->getID(); $instantiation = $network_port->getInstantiation(); $instantiation->add($inst_input); unset($instantiation); } if ($network_port->fields['instantiation_type'] == $instantiation_type) { $instantiation = $network_port->getInstantiation(); $inst_input['id'] = $instantiation->getID(); $inst_input['networkports_id'] = $network_port->getID(); $instantiation->update($inst_input); unset($instantiation); } } if ($network_port->isNewItem()) { return -1; } $network_name = new NetworkName(); $query = "SELECT `id`, `is_dynamic`\n FROM `glpi_networknames`\n WHERE `itemtype` = 'NetworkPort'\n AND `items_id` = '{$networkports_id}'\n ORDER BY `is_dynamic`"; if (!$ips || count($ips) == 0) { foreach ($DB->request($query) as $line) { if ($line['is_dynamic']) { $network_name->delete($line, true, $dohistory); } } } else { $names = $DB->request($query); if ($names->numrows() == 0) { $name_input = array('itemtype' => 'NetworkPort', 'items_id' => $networkports_id, 'is_dynamic' => 1, 'is_deleted' => 0, '_no_history' => !$dohistory, 'name' => 'OCS-INVENTORY-NG'); $networknames_id = $network_name->add($name_input); } else { $line = $names->next(); $networknames_id = $line['id']; foreach ($names as $line) { if ($line['is_dynamic'] == 1 && $line['id'] != $networknames_id) { $network_port->delete($line, true, $dohistory); } } } $ip_address = new IPAddress(); $already_known_addresses = array(); $query = "SELECT `id`, `name`, `is_dynamic`, `mainitems_id`\n FROM `glpi_ipaddresses`\n WHERE `itemtype` = 'NetworkName'\n AND `items_id` = '{$networknames_id}'\n ORDER BY `is_dynamic`"; foreach ($DB->request($query) as $line) { if (in_array($line['name'], $ips) && !empty($line['mainitems_id'])) { $already_known_addresses[] = $line['id']; $ips = array_diff($ips, array($line['name'])); } elseif ($line['is_dynamic'] == 1) { $ip_address->delete($line, true, $dohistory); } } } if ($ips) { foreach ($ips as $ip) { $ip_input = array('name' => $ip, 'itemtype' => 'NetworkName', 'items_id' => $networknames_id, '_no_history' => !$dohistory, 'is_dynamic' => 1, 'is_deleted' => 0); $ip_address->add($ip_input); } } return $network_port->getID(); }
function configureNodesLinks($weathermaps_id) { global $DB, $CFG_GLPI; $networkPort = new NetworkPort(); $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $this->getFromDB($weathermaps_id); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='2'>"; echo __('Nodes and links', 'monitoring'); echo "</th>"; echo "</tr>"; $this->generateWeathermap($weathermaps_id, 1, 1); $map = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=weathermap-" . $weathermaps_id . ".png'/>"; echo "<tr class='tab_bg_1'>"; echo "<td valign='top' width='10'>"; if ($this->fields['background'] == '') { echo '<script language="JavaScript" type="text/JavaScript"> function FindPosition(oElement) { if(typeof( oElement.offsetParent ) != "undefined") { for(var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) { posX += oElement.offsetLeft; posY += oElement.offsetTop; } return [ posX, posY ]; } else { return [ oElement.x, oElement.y ]; } } function GetCoordinates(e) { var PosX = 0; var PosY = 0; var ImgPos; ImgPos = FindPosition(myImg); if (!e) var e = window.event; if (e.pageX || e.pageY) { PosX = e.pageX; PosY = e.pageY; } else if (e.clientX || e.clientY) { PosX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; PosY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } PosX = PosX - ImgPos[0]; PosY = PosY - ImgPos[1]; document.pointform.x.value = PosX; document.pointform.y.value = PosY; } var myImg = document.getElementById("myImgId"); myImg.onmousedown = GetCoordinates; </script>'; echo "<div><img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=weathermap-" . $weathermaps_id . ".png'/>"; echo "<div style='position: absolute; top:40px;' id='myImgId' >\n <table class='gridweathermap' width='" . $this->fields['width'] . "' \n height='" . $this->fields['height'] . "'>"; $line = ''; $nbcol = ceil($this->fields['width'] / 15); for ($num = 0; $num < $nbcol; $num++) { $line .= "<td></td>"; } $line = '<tr>' . $line . '</tr>'; $nbline = ceil($this->fields['height'] / 15); for ($num = 0; $num < $nbline; $num++) { echo $line; } echo "</table></div></div>"; } else { echo '<div id="pointer_div" onclick="point_it(event)" style = "background-image:url(\'' . $this->fields['background'] . '\');"> <img id="cross" style="position:relative;visibility:hidden;z-index:2;"> ' . $map . '</div>'; echo '<script language="JavaScript"> function point_it(event){ pos_x = event.offsetX?(event.offsetX):event.pageX; pos_y = event.offsetY?(event.offsetY):event.pageY; document.getElementById("cross").style.left = (pos_x-1) ; document.getElementById("cross").style.top = (pos_y-15) ; var topValue= 0; var leftValue= 0; var obj = document.getElementById("pointer_div"); while(obj){ leftValue+= obj.offsetLeft; topValue+= obj.offsetTop; obj= obj.offsetParent; } document.pointform.x.value = pos_x-leftValue; document.pointform.y.value = pos_y-topValue; } </script>'; } echo "</td>"; echo "<td valign='top'>"; echo "<div style='position: fixed;top: 30px;right: 0;z-index:999;' >"; echo "<table class='tab_cadre' width='100%'>"; echo "<tr>"; echo "<td>"; echo "<a onClick='Ext.get(\"weathermapform\").toggle();'>\n <img src='" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png' /> \n " . __('Display weathermap form', 'monitoring') . "\n <img src='" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png' /></a>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; echo "<div style='position: fixed;top: 50px;right: 0;z-index:1000;' id='weathermapform' >"; echo '<form name="pointform" method="post" action="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/front/weathermapnode.form.php">'; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<table class='tab_cadre' width='100%'>"; echo "<tr>"; echo "<th colspan='2'>"; echo "x : "; echo '<input type="text" name="x" size="4" />'; echo " "; echo "y : "; echo '<input type="text" name="y" size="4" />'; echo "</th>"; echo "</tr>"; // * Add node echo "<tr>"; echo "<th colspan='2'>"; echo "<input type='hidden' name='plugin_monitoring_weathermaps_id' value='" . $weathermaps_id . "' />"; echo __('Add a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Node', 'monitoring') . " :"; echo "</td>"; echo "<td>"; Dropdown::showAllItems("items_id"); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Name') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='name' value='' />"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Change node position echo "<tr>"; echo "<th colspan='2'>"; echo __('Edit a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2' align='center'>"; $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; if ($itemtype == '0') { $pmWeathermapnode->delete($data); } else { $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } } $rand = Dropdown::showFromArray('id_update', $elements); $params = array('items_id' => '__VALUE__', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_id_update{$rand}", "show_updatenode{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownWnode.php", $params, false); echo "<span id='show_updatenode{$rand}'></span>\n"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='update' value=\"" . __('Save') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Delete node echo "<tr>"; echo "<th colspan='2'>"; echo __('Delete a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "</td>"; echo "<td>"; $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $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(); } $elements[$data['id']] = $name; } Dropdown::showFromArray('id', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='purge' value=\"" . __('Delete permanently') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo '<form name="formlink" method="post" action="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/front/weathermaplink.form.php">'; echo "<table class='tab_cadre' width='100%'>"; // *Add Link echo "<tr>"; echo "<th colspan='2'>"; echo __('Add a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Source', 'monitoring') . "* :"; echo "</td>"; echo "<td>"; $query = "SELECT `glpi_plugin_monitoring_weathermapnodes`.`id` as `id`,\n `glpi_plugin_monitoring_weathermapnodes`.`name` as `name`,\n `glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`, \n `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id`,\n `glpi_plugin_monitoring_services`.`id` as `services_id`,\n `glpi_plugin_monitoring_components`.`name` as `components_name`,\n `plugin_monitoring_commands_id`, `glpi_plugin_monitoring_components`.`arguments`,\n `glpi_plugin_monitoring_services`.`networkports_id`\n FROM `glpi_plugin_monitoring_weathermapnodes`\n \n LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`\n ON (`glpi_plugin_monitoring_weathermapnodes`.`items_id`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id`\n AND `glpi_plugin_monitoring_weathermapnodes`.`itemtype`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`)\n \n LEFT JOIN `glpi_plugin_monitoring_services` \n ON `plugin_monitoring_componentscatalogs_hosts_id`= `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`\n\n LEFT JOIN `glpi_plugin_monitoring_components` \n ON `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`\n \n\n WHERE `is_weathermap` = '1'\n AND `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `itemtype`,`items_id`,`glpi_plugin_monitoring_components`.`name`"; $elements = array(); $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']); } } } } } } } } } if ($device_connected == '') { $networkPort->getFromDB($data['networkports_id']); $elements2[$data['id'] . "-" . $data['services_id']] = $name . " [" . $networkPort->getfield('name') . "] (" . $data['components_name'] . ")"; } else { $networkPort->getFromDB($data['networkports_id']); $elements[$data['id'] . "-" . $data['services_id']] = $name . " [" . $networkPort->getfield('name') . "] (" . $data['components_name'] . ") > " . $device_connected; } } if (count($elements) > 1 and count($elements2) > 0) { $elements = array_merge($elements, array('0' => Dropdown::EMPTY_VALUE)); $elements = array_merge($elements, $elements2); } else { $elements = array_merge($elements, $elements2); } Dropdown::showFromArray('linksource', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Destination', 'monitoring') . " :"; echo "</td>"; echo "<td>"; echo "<div id='nodedestination'>"; $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $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(); } $elements[$data['id']] = $name; } Dropdown::showFromArray('plugin_monitoring_weathermapnodes_id_2', $elements); echo "</div>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Max bandwidth input', 'monitoring') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='bandwidth_in' value=''/>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Max bandwidth output', 'monitoring') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='bandwidth_out' value=''/>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Edit link echo "<tr>"; echo "<th colspan='2'>"; echo __('Edit a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2' align='center'>"; $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $query = "SELECT `glpi_plugin_monitoring_weathermaplinks`.`id` as `id`,\n `itemtype`, `items_id`, `name`, `plugin_monitoring_weathermapnodes_id_2`\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_weathermaps_id` = '" . $weathermaps_id . "'"; $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name1 = $data['name']; if ($name1 == '') { $name1 = $item->getName(); } $pmWeathermapnode->getFromDB($data['plugin_monitoring_weathermapnodes_id_2']); $itemtype = $pmWeathermapnode->fields['itemtype']; $item = new $itemtype(); $item->getFromDB($pmWeathermapnode->fields['items_id']); $name2 = $pmWeathermapnode->fields['name']; if ($name2 == '') { $name2 = $item->getName(); } $elements[$data['id']] = $name1 . " - " . $name2; } $rand = Dropdown::showFromArray('id_update', $elements); $params = array('items_id' => '__VALUE__', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_id_update{$rand}", "show_updatelink{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownWlink.php", $params, false); echo "<span id='show_updatelink{$rand}'></span>\n"; echo "</td>"; echo "</tr>"; // * Delete link echo "<tr>"; echo "<th colspan='2'>"; echo __('Delete a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "Link :"; echo "</td>"; echo "<td>"; Dropdown::showFromArray('id', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='purge' value=\"" . __('Delete permanently') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; echo "</td>"; echo "</tr>"; }
/** * Remove all connections on a hub * * @param $hub_id integer id of the hub * @param $pfNetworkport object Informations of the network port * * @return nothing * **/ function releaseHub($hub_id, $pfNetworkport, $a_mac) { $Netport = new NetworkPort(); $nn = new NetworkPort_NetworkPort(); $a_macOnSwitch = array(); foreach ($a_mac as $ifmac) { $a_macOnSwitch["{$ifmac}"] = 1; } // get all ports of hub $releasePorts = array(); $a_ports = $Netport->find("`items_id`='" . $hub_id . "' AND `itemtype`='" . $this->getType() . "' " . "AND (`name` != 'Link' OR `name` IS NULL)"); foreach (array_keys($a_ports) as $ports_id) { $id = $nn->getOppositeContact($ports_id); if ($id) { $Netport->getFromDB($id); if (!isset($a_macOnSwitch[$Netport->fields["mac"]])) { $releasePorts[$ports_id] = 1; } } } }
/** * Display graphs of services associated with host * * @param $itemtype value type of item * @param $items_id integer id of the object * **/ function showGraphsByHost($itemtype, $items_id) { global $CFG_GLPI,$DB; PluginMonitoringToolbox::loadLib(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponent = new PluginMonitoringComponent(); $pmServicegraph = new PluginMonitoringServicegraph(); $networkPort = new NetworkPort(); $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts` WHERE `items_id`='".$items_id."' AND `itemtype`='".$itemtype."'"; $result = $DB->query($query); 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 "<table class='tab_cadre_fixe'>"; while ($data=$DB->fetch_array($result)) { $pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']); $querys = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services` LEFT JOIN `glpi_plugin_monitoring_components` on `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id` WHERE `plugin_monitoring_componentscatalogs_hosts_id`='".$data['id']."' ORDER BY `name`"; $results = $DB->query($querys); while ($datas=$DB->fetch_array($results)) { $pmComponent->getFromDB($datas['plugin_monitoring_components_id']); if ($pmComponent->fields['graph_template'] != 0) { echo "<tr>"; echo "<td>"; echo "<table class='tab_cadre'>"; echo "<tr class='tab_bg_3'>"; echo "<th>"; echo "<a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/display.form.php?itemtype=PluginMonitoringService&items_id=".$datas['id']."'>"; echo $pmComponent->fields['name']; echo "</a>"; if (!is_null($datas['networkports_id']) && $datas['networkports_id'] > 0) { $networkPort->getFromDB($datas['networkports_id']); echo " [".$networkPort->getLink()."]"; } echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td style='position: relative'>"; $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $datas['id'], "0", "2h", "", 920); echo "</td>"; echo "</tr>"; echo "</table>"; echo "</td>"; echo "</tr>"; } } } echo "</tr>"; echo "</table>"; }
function configureNodesLinks($weathermaps_id) { global $DB,$CFG_GLPI; $networkPort = new NetworkPort(); $this->getFromDB($weathermaps_id); $style = ''; if ($this->fields['width'] > 950) { $style = ";position:relative;left:-".(($this->fields['width'] - 950) / 2)."px"; } echo "<table class='tab_cadre' style='width:". $this->fields['width']."px;height:".$this->fields['height']."px". $style."'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='2'>"; echo __('Nodes and links', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td valign='top'>"; echo "<div>"; PluginMonitoringToolbox::loadLib(); $this->drawMap($weathermaps_id, 100, 1); echo "</div>"; echo "</td>"; echo "<td valign='top'>"; echo "<div style='position: fixed;top: 30px;right: 0;z-index:999;' >"; echo "<table class='tab_cadre' width='100%'>"; echo "<tr>"; echo "<td>"; echo "<a onClick='Ext.get(\"weathermapform\").toggle();'> <img src='".$CFG_GLPI["root_doc"]."/pics/deplier_down.png' /> ".__('Display weathermap form', 'monitoring')." <img src='".$CFG_GLPI["root_doc"]."/pics/deplier_down.png' /></a>"; echo "</td>"; echo "</tr>"; echo"</table>"; echo "</div>"; echo "<div style='position: fixed;top: 50px;right: 0;z-index:1000;' id='weathermapform' >"; echo '<form name="pointform" method="post" action="'.$CFG_GLPI['root_doc'].'/plugins/monitoring/front/weathermapnode.form.php">'; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<table class='tab_cadre' width='100%'>"; echo "<tr>"; echo "<th colspan='2'>"; echo "x : "; echo '<input type="text" name="x" size="4" value="50" />'; echo " "; echo "y : "; echo '<input type="text" name="y" size="4" value="50"/>'; echo "</th>"; echo "</tr>"; // * Add node echo "<tr>"; echo "<th colspan='2'>"; echo "<input type='hidden' name='plugin_monitoring_weathermaps_id' value='".$weathermaps_id."' />"; echo __('Add a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Node', 'monitoring')." :"; echo "</td>"; echo "<td>"; Dropdown::showAllItems("items_id"); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Name')." :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='name' value='' />"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Position of label', 'monitoring')." :"; echo "</td>"; echo "<td>"; $positions = array( 'middle' => __('Center', 'monitoring'), 'start' => __('Right', 'monitoring'), 'end' => __('Left', 'monitoring') ); Dropdown::showFromArray('position', $positions); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='add' value=\"".__('Add')."\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Change node position echo "<tr>"; echo "<th colspan='2'>"; echo __('Edit a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2' align='center'>"; $query = "SELECT * FROM `".getTableForItemType("PluginMonitoringWeathermapnode")."` WHERE `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $itemtype = $data['itemtype']; if ($itemtype == '0') { $pmWeathermapnode->delete($data); } else { $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } } $rand = Dropdown::showFromArray('id_update', $elements); $params = array('items_id' => '__VALUE__', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_id_update$rand", "show_updatenode$rand", $CFG_GLPI["root_doc"]."/plugins/monitoring/ajax/dropdownWnode.php", $params, TRUE); echo "<span id='show_updatenode$rand'></span>\n"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='update' value=\"".__('Save')."\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Delete node echo "<tr>"; echo "<th colspan='2'>"; echo __('Delete a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "</td>"; echo "<td>"; $query = "SELECT * FROM `".getTableForItemType("PluginMonitoringWeathermapnode")."` WHERE `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $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(); } $elements[$data['id']] = $name; } Dropdown::showFromArray('id', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='purge' value=\"".__('Delete permanently')."\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo '<form name="formlink" method="post" action="'.$CFG_GLPI['root_doc'].'/plugins/monitoring/front/weathermaplink.form.php">'; echo "<table class='tab_cadre' width='100%'>"; // *Add Link echo "<tr>"; echo "<th colspan='2'>"; echo __('Add a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Source', 'monitoring')."* :"; echo "</td>"; echo "<td>"; $query = "SELECT `glpi_plugin_monitoring_weathermapnodes`.`id` as `id`, `glpi_plugin_monitoring_weathermapnodes`.`name` as `name`, `glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`, `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id`, `glpi_plugin_monitoring_services`.`id` as `services_id`, `glpi_plugin_monitoring_components`.`name` as `components_name`, `plugin_monitoring_commands_id`, `glpi_plugin_monitoring_components`.`arguments`, `glpi_plugin_monitoring_services`.`networkports_id` FROM `glpi_plugin_monitoring_weathermapnodes` LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts` ON (`glpi_plugin_monitoring_weathermapnodes`.`items_id`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id` AND `glpi_plugin_monitoring_weathermapnodes`.`itemtype`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`) LEFT JOIN `glpi_plugin_monitoring_services` ON `plugin_monitoring_componentscatalogs_hosts_id`= `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` LEFT JOIN `glpi_plugin_monitoring_components` ON `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id` WHERE `is_weathermap` = '1' AND `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' ORDER BY `itemtype`,`items_id`,`glpi_plugin_monitoring_components`.`name`"; $elements = array(); $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."' 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']."' 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` FROM `glpi_plugin_monitoring_weathermaplinks` LEFT JOIN `glpi_plugin_monitoring_weathermapnodes` ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1` WHERE ((`plugin_monitoring_weathermapnodes_id_1`='".$data['id']."' AND `plugin_monitoring_weathermapnodes_id_2`='".$a_node['id']."') OR (`plugin_monitoring_weathermapnodes_id_1`='".$a_node['id']."' AND `plugin_monitoring_weathermapnodes_id_2`='".$data['id']."')) AND `plugin_monitoring_weathermaps_id` = '".$weathermaps_id."'"; $resultl = $DB->query($queryl); if ($DB->numrows($resultl) == '0') { $device_connected = $pmWeathermapnode->getNodeName($a_node['id']); } } } } } } } } } if ($device_connected == '') { $networkPort->getFromDB($data['networkports_id']); $elements2[$data['id']."-".$data['services_id']] = $name." [".$networkPort->getfield('name')."] (".$data['components_name'].")"; } else { $networkPort->getFromDB($data['networkports_id']); $elements[$data['id']."-".$data['services_id']] = $name." [".$networkPort->getfield('name')."] (".$data['components_name'].") > ".$device_connected; } } if (count($elements) > 1 AND count($elements2) > 0) { $elements = array_merge($elements,array('0'=>Dropdown::EMPTY_VALUE)); $elements = array_merge($elements, $elements2); } else { $elements = array_merge($elements, $elements2); } Dropdown::showFromArray('linksource', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Destination', 'monitoring')." :"; echo "</td>"; echo "<td>"; echo "<div id='nodedestination'>"; $query = "SELECT * FROM `".getTableForItemType("PluginMonitoringWeathermapnode")."` WHERE `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $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(); } $elements[$data['id']] = $name; } Dropdown::showFromArray('plugin_monitoring_weathermapnodes_id_2', $elements); echo "</div>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Max bandwidth input', 'monitoring')." :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='bandwidth_in' value=''/>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Max bandwidth output', 'monitoring')." :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='bandwidth_out' value=''/>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='add' value=\"".__('Add')."\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Edit link echo "<tr>"; echo "<th colspan='2'>"; echo __('Edit a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2' align='center'>"; $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $query = "SELECT `glpi_plugin_monitoring_weathermaplinks`.`id` as `id`, `itemtype`, `items_id`, `name`, `plugin_monitoring_weathermapnodes_id_2` FROM `glpi_plugin_monitoring_weathermaplinks` LEFT JOIN `glpi_plugin_monitoring_weathermapnodes` ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1` WHERE `plugin_monitoring_weathermaps_id` = '".$weathermaps_id."'"; $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name1 = $data['name']; if ($name1 == '') { $name1 = $item->getName(); } $pmWeathermapnode->getFromDB($data['plugin_monitoring_weathermapnodes_id_2']); $itemtype = $pmWeathermapnode->fields['itemtype']; $item = new $itemtype(); $item->getFromDB($pmWeathermapnode->fields['items_id']); $name2 = $pmWeathermapnode->fields['name']; if ($name2 == '') { $name2 = $item->getName(); } $elements[$data['id']] = $name1." - ".$name2; } $rand = Dropdown::showFromArray('id_update', $elements); $params = array('items_id' => '__VALUE__', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_id_update$rand", "show_updatelink$rand", $CFG_GLPI["root_doc"]."/plugins/monitoring/ajax/dropdownWlink.php", $params, TRUE); echo "<span id='show_updatelink$rand'></span>\n"; echo "</td>"; echo "</tr>"; // * Delete link echo "<tr>"; echo "<th colspan='2'>"; echo __('Delete a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Link', 'monitoring')." :"; echo "</td>"; echo "<td>"; Dropdown::showFromArray('id', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='purge' value=\"".__('Delete permanently')."\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; echo "</td>"; echo "</tr>"; echo "</table>"; }
/** * Function used to detect if port has multiple mac connected */ static function isPortHasMultipleMac($networkports_id) { $nw = new NetworkPort_NetworkPort(); $networkPort = new NetworkPort(); $is_multiple = FALSE; $opposite_port = $nw->getOppositeContact($networkports_id); if ($opposite_port != "" && $opposite_port != 0) { $networkPort->getFromDB($opposite_port); if ($networkPort->fields["itemtype"] == 'PluginFusioninventoryUnmanaged') { $pfUnmanaged = new PluginFusioninventoryUnmanaged(); if ($pfUnmanaged->getFromDB($networkPort->fields['items_id'])) { if ($pfUnmanaged->fields['hub'] == 1) { $is_multiple = TRUE; } } } } return $is_multiple; }
static function displayLine($data, $displayhost = 1) { global $DB, $CFG_GLPI; $pMonitoringService = new PluginMonitoringService(); $networkPort = new NetworkPort(); $pMonitoringComponent = new PluginMonitoringComponent(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $entity = new Entity(); $pMonitoringService->getFromDB($data['id']); echo "<td width='32' class='center'>"; $shortstate = self::getState($data['state'], $data['state_type'], $data['event'], $data['is_acknowledged']); $alt = __('Ok', 'monitoring'); if ($shortstate == 'orange') { $alt = __('Warning (data)', 'monitoring'); } else { if ($shortstate == 'yellow') { $alt = __('Warning (connection)', 'monitoring'); } else { if ($shortstate == 'red') { $alt = __('Critical', 'monitoring'); } else { if ($shortstate == 'redblue') { $alt = __('Critical / Acknowledge', 'monitoring'); } } } } echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/box_" . $shortstate . "_32.png'\n title='" . $alt . "' alt='" . $alt . "' />"; 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'>"; $timezone = '0'; if (isset($_SESSION['plugin_monitoring_timezone'])) { $timezone = $_SESSION['plugin_monitoring_timezone']; } if ($pMonitoringComponent->fields['graph_template'] != '') { echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/display.form.php?itemtype=PluginMonitoringService&items_id=" . $data['id'] . "'>"; $pmServicegraph = new PluginMonitoringServicegraph(); ob_start(); $pmServicegraph->displayGraph($pMonitoringComponent->fields['graph_template'], "PluginMonitoringService", $data['id'], "0", '2h', "div", "600"); $div = ob_get_contents(); ob_end_clean(); $chart = "<table width='600' class='tab_cadre'><tr><td>" . $div . "</td></tr></table>"; Html::showToolTip($chart, array('img' => $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/stats_32.png")); $pmServicegraph->displayGraph($pMonitoringComponent->fields['graph_template'], "PluginMonitoringService", $data['id'], "0", '2h', "js"); } 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>" . __('Resources', 'monitoring') . "</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." ".__('on', 'monitoring')." ".$itemmat->getLink(1)."</td>"; // } // unset($itemmat); echo "<td class='center'>"; if ($shortstate == 'red') { echo "<table>"; echo "<tr>"; echo "<td>"; echo $data['state']; echo "</td>"; echo "<td>"; echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/acknowledge.form.php?id=" . $data['id'] . "'>" . "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/acknowledge_checked.png'" . " alt='" . __('Define an acknowledge', 'monitoring') . "'" . " title='" . __('Define an acknowledge', 'monitoring') . "'/>" . "</a>"; echo "</td>"; echo "</tr>"; echo "</table>"; } else { echo $data['state']; } echo "</td>"; echo "<td>"; echo Html::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 class='center'>"; echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/unavaibility.php?" . "field[0]=2&searchtype[0]=equals&contains[0]=" . $pMonitoringService->fields['id'] . "&sort=3&order=DESC&itemtype=PluginMonitoringUnavaibility'>\n <img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/info.png'/></a>"; echo "</td>"; } echo "<td>"; if ($shortstate == 'redblue') { echo "<i>" . _n('User', 'Users', 1) . " : </i>"; $user = new User(); $user->getFromDB($data['acknowledge_users_id']); echo $user->getName(1); echo "<br/>"; echo "<i>" . __('Comments') . " : </i>" . $data['acknowledge_comment']; } echo "</td>"; if ($displayhost == '0') { echo "<td>"; if (PluginMonitoringProfile::haveRight("componentscatalog", 'w')) { $a_arg = importArrayFromDB($pMonitoringService->fields['arguments']); $cnt = ''; if (count($a_arg) > 0) { $cnt = " (" . count($a_arg) . ")"; } echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/servicearg.form.php?id=" . $data['id'] . "'>" . __('Configure', 'monitoring') . $cnt . "</a>"; } echo "</td>"; } }
function post_addItem() { global $DB; // Manage add from template if (isset($this->input["_oldID"])) { // ADD Infocoms $ic = new Infocom(); if ($this->canUseInfocoms() && $ic->getFromDBforDevice($this->type, $this->input["_oldID"])) { $ic->fields["items_id"] = $this->fields['id']; unset($ic->fields["id"]); if (isset($ic->fields["immo_number"])) { $ic->fields["immo_number"] = autoName($ic->fields["immo_number"], "immo_number", 1, 'Infocom', $this->input['entities_id']); } if (empty($ic->fields['use_date'])) { unset($ic->fields['use_date']); } if (empty($ic->fields['buy_date'])) { unset($ic->fields['buy_date']); } $ic->addToDB(); } foreach (array('Document_Item' => 'documents_id', 'Contract_Item' => 'contracts_id') as $type => $fk) { $item = new $type(); foreach ($item->find("items_id='" . $this->input["_oldID"] . "'\n AND itemtype='" . $this->type . "'") as $tmpid => $data) { $tmp = array(); $tmp['items_id'] = $this->input["_oldID"]; $tmp['itemtype'] = $type; $tmp[$fk] = $data[$fk]; $item->add($tmp); } } if ($this->canUseNetworkPorts()) { // ADD Ports $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . get_called_class() . "';"; $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']); } } } } } }
/** * @param $row HTMLTableRow object (default NULL) * @param $item CommonDBTM object (default NULL) * @param $father HTMLTableCell object (default NULL) * @param $options array **/ static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array()) { global $DB, $CFG_GLPI; if ($item !== NULL && $item->getType() == 'IPNetwork') { $queries = array(); foreach ($CFG_GLPI["networkport_types"] as $itemtype) { $table = getTableForItemType($itemtype); $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n ADDR.`binary_1` AS binary_1,\n ADDR.`binary_2` AS binary_2,\n ADDR.`binary_3` AS binary_3,\n ADDR.`name` AS ip,\n ADDR.`id` AS id,\n ADDR.`itemtype` AS addr_item_type,\n ADDR.`items_id` AS addr_item_id,\n `glpi_entities`.`completename` AS entity,\n NAME.`id` AS name_id,\n PORT.`id` AS port_id,\n ITEM.`id` AS item_id,\n '{$itemtype}' AS item_type\n FROM `glpi_ipaddresses_ipnetworks` AS LINK\n JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n AND ADDR.`itemtype` = 'NetworkName'\n AND ADDR.`is_deleted` = '0')\n LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n AND NAME.`itemtype` = 'NetworkPort')\n JOIN `glpi_networkports` AS PORT ON (NAME.`items_id` = PORT.`id`\n AND PORT.`itemtype` = '{$itemtype}')\n JOIN `{$table}` AS ITEM ON (ITEM.`id` = PORT.`items_id`)\n WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')"; } $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n ADDR.`binary_1` AS binary_1,\n ADDR.`binary_2` AS binary_2,\n ADDR.`binary_3` AS binary_3,\n ADDR.`name` AS ip,\n ADDR.`id` AS id,\n ADDR.`itemtype` AS addr_item_type,\n ADDR.`items_id` AS addr_item_id,\n `glpi_entities`.`completename` AS entity,\n NAME.`id` AS name_id,\n PORT.`id` AS port_id,\n NULL AS item_id,\n NULL AS item_type\n FROM `glpi_ipaddresses_ipnetworks` AS LINK\n JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n AND ADDR.`itemtype` = 'NetworkName'\n AND ADDR.`is_deleted` = '0')\n LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n AND NAME.`itemtype` = 'NetworkPort')\n JOIN `glpi_networkports` AS PORT\n ON (NAME.`items_id` = PORT.`id`\n AND PORT.`itemtype`\n NOT IN ('" . implode("', '", $CFG_GLPI["networkport_types"]) . "'))\n WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')"; $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n ADDR.`binary_1` AS binary_1,\n ADDR.`binary_2` AS binary_2,\n ADDR.`binary_3` AS binary_3,\n ADDR.`name` AS ip,\n ADDR.`id` AS id,\n ADDR.`itemtype` AS addr_item_type,\n ADDR.`items_id` AS addr_item_id,\n `glpi_entities`.`completename` AS entity,\n NAME.`id` AS name_id,\n NULL AS port_id,\n NULL AS item_id,\n NULL AS item_type\n FROM `glpi_ipaddresses_ipnetworks` AS LINK\n JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n AND ADDR.`itemtype` = 'NetworkName'\n AND ADDR.`is_deleted` = '0')\n LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n AND NAME.`itemtype` != 'NetworkPort')\n WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')"; $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n ADDR.`binary_1` AS binary_1,\n ADDR.`binary_2` AS binary_2,\n ADDR.`binary_3` AS binary_3,\n ADDR.`name` AS ip,\n ADDR.`id` AS id,\n ADDR.`itemtype` AS addr_item_type,\n ADDR.`items_id` AS addr_item_id,\n `glpi_entities`.`completename` AS entity,\n NULL AS name_id,\n NULL AS port_id,\n NULL AS item_id,\n NULL AS item_type\n FROM `glpi_ipaddresses_ipnetworks` AS LINK\n JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n AND ADDR.`itemtype` != 'NetworkName'\n AND ADDR.`is_deleted` = '0')\n LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')"; $query = implode('UNION ', $queries); if ($options['order'] == 'ip' || $options['order'] == 'itemtype') { $query .= " ORDER BY binary_0, binary_1, binary_2, binary_3"; } if (isset($options['SQL_options'])) { $query .= "\n" . $options['SQL_options']; } $canedit = isset($options['canedit']) && $options['canedit']; $options['createRow'] = false; $address = new self(); $ipaddress = new self(); $networkname = new NetworkName(); $networkport = new NetworkPort(); $item = NULL; foreach ($DB->request($query) as $line) { unset($row); if ($options['order'] == 'itemtype' && !empty($line['item_type'])) { $row = $options['group_' . $line['item_type']]->createRow(); } if (!isset($row)) { $row = $options['group_None']->createRow(); } $ip_header = $row->getGroup()->getSuperHeaderByName('IP Address'); $item_header = $row->getGroup()->getHeaderByName('Item', 'Item'); $port_header = $row->getGroup()->getHeaderByName('Item', 'NetworkPort'); $name_header = $row->getGroup()->getHeaderByName('Item', 'NetworkName'); $entity_header = $row->getGroup()->getHeaderByName('Item', 'Entity'); $row->addCell($ip_header, $line['ip'], $father); if (!empty($line['name_id'])) { $networkname->getFromDB($line['name_id']); $row->addCell($name_header, $networkname->getLink(), $father); if (!empty($line['port_id'])) { $networkport->getFromDB($line['port_id']); $row->addCell($port_header, $networkport->getLink(), $father); if (!empty($line['item_id']) && !empty($line['item_type'])) { $itemtype = $line['item_type']; $item = new $itemtype(); $item->getFromDB($line['item_id']); $row->addCell($item_header, $item->getLink(), $father); } } $row->addCell($entity_header, $line['entity'], $father); } else { if (!empty($line['addr_item_id']) && !empty($line['addr_item_type'])) { $itemtype = $line['addr_item_type']; $item = new $itemtype(); $item->getFromDB($line['addr_item_id']); if ($item instanceof CommonDBChild) { $items = $item->recursivelyGetItems(); $elements = array($item->getLink()); foreach ($items as $item_) { $elements[] = $item_->getLink(); } $row->addCell($item_header, implode(' > ', $elements), $father); } else { $row->addCell($item_header, $item->getLink(), $father); } $row->addCell($entity_header, $line['entity'], $father); } } } } else { if (isset($options['dont_display']['IPAddress'])) { return; } $header = $row->getGroup()->getHeaderByName('Internet', __CLASS__); if (!$header) { return; } if (empty($item)) { if (empty($father)) { return; } $item = $father->getItem(); } $query = "SELECT `id`\n FROM `glpi_ipaddresses`\n WHERE `items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'\n AND `is_deleted` = '0'"; $canedit = isset($options['canedit']) && $options['canedit']; $createRow = isset($options['createRow']) && $options['createRow']; $options['createRow'] = false; $address = new self(); foreach ($DB->request($query) as $ipaddress) { if ($address->getFromDB($ipaddress['id'])) { if ($createRow) { $row = $row->createRow(); } $content = $address->fields['name']; $this_cell = $row->addCell($header, $content, $father); if (isset($options['display_isDynamic']) && $options['display_isDynamic']) { $dyn_header = $row->getGroup()->getHeaderByName('Internet', __CLASS__ . '_dynamic'); $this_cell = $row->addCell($dyn_header, Dropdown::getYesNo($address->fields['is_dynamic']), $this_cell); } IPNetwork::getHTMLTableCellsForItem($row, $address, $this_cell, $options); } } } }
static function getItemsDynamicly($parm) { global $DB; $pmCc_Rule = new PluginMonitoringComponentscatalog_rule(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmSearch = new PluginMonitoringSearch(); $pmService = new PluginMonitoringService(); $devices_present = array(); $devicesnetworkport_present = array(); if ($pmCc_Rule->getFromDB($parm->fields['id'])) { // Load right entity $pmComponentscatalog->getFromDB($pmCc_Rule->fields['plugin_monitoring_componentscalalog_id']); $default_entity = 0; if (isset($_SESSION['glpiactive_entity'])) { $default_entity = $_SESSION['glpiactive_entity']; } $entities_isrecursive = 0; if (isset($_SESSION['glpiactiveentities']) and count($_SESSION['glpiactiveentities']) > 1) { $entities_isrecursive = 1; } Session::changeActiveEntities($pmComponentscatalog->fields['entities_id'], $pmComponentscatalog->fields['is_recursive']); $get_tmp = ''; $itemtype = $pmCc_Rule->fields['itemtype']; if (isset($_GET)) { $get_tmp = $_GET; } if (isset($_SESSION["glpisearchcount"][$pmCc_Rule->fields['itemtype']])) { unset($_SESSION["glpisearchcount"][$pmCc_Rule->fields['itemtype']]); } if (isset($_SESSION["glpisearchcount2"][$pmCc_Rule->fields['itemtype']])) { unset($_SESSION["glpisearchcount2"][$pmCc_Rule->fields['itemtype']]); } $_GET = importArrayFromDB($pmCc_Rule->fields['condition']); $_GET["glpisearchcount"] = count($_GET['field']); if (isset($_GET['field2'])) { $_GET["glpisearchcount2"] = count($_GET['field2']); } Search::manageGetValues($pmCc_Rule->fields['itemtype']); $queryd = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"] . "'\n AND `itemtype`='" . $pmCc_Rule->fields['itemtype'] . "'\n AND `is_static`='0'"; $result = $DB->query($queryd); while ($data = $DB->fetch_array($result)) { $devices_present[$data['id']] = 1; } $queryd = "SELECT `glpi_plugin_monitoring_services`.`id` 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_componentscalalog_id`='" . $pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"] . "'\n AND `itemtype`='NetworkEquipment'\n AND `is_static`='0'"; $result = $DB->query($queryd); while ($data = $DB->fetch_array($result)) { $devicesnetworkport_present[$data['id']] = 1; } $glpilist_limit = $_SESSION['glpilist_limit']; $_SESSION['glpilist_limit'] = 500000; $result = $pmSearch->constructSQL($itemtype, $_GET); $_SESSION['glpilist_limit'] = $glpilist_limit; while ($data = $DB->fetch_array($result)) { $networkports_id = 0; $itemtype_device = $pmCc_Rule->fields['itemtype']; $items_id_device = $data['id']; if ($itemtype_device == 'PluginMonitoringNetworkport') { // $queryh = "SELECT `itemtype`, `items_id`, // `glpi_plugin_monitoring_services`.`id`, // `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` as hid // FROM `glpi_plugin_monitoring_componentscatalogs_hosts` // LEFT JOIN `glpi_plugin_monitoring_services` // ON `plugin_monitoring_componentscatalogs_hosts_id` = // `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` // WHERE `plugin_monitoring_componentscalalog_id`='".$pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"]."' // AND `itemtype`='".$itemtype_device."' // AND `items_id`='".$items_id_device."' // AND `glpi_plugin_monitoring_services`.`id` IS NULL"; // $resulth = $DB->query($queryh); // while ($datah=$DB->fetch_array($resulth)) { // $pmComponentscatalog_Host->delete(array('id'=>$datah['hid'])); // } $pmNetworkport = new PluginMonitoringNetworkport(); $pmNetworkport->getFromDB($data['id']); $itemtype_device = $pmNetworkport->fields['itemtype']; $items_id_device = $pmNetworkport->fields['items_id']; $networkports_id = $pmNetworkport->fields['networkports_id']; $networkPort = new NetworkPort(); if ($networkPort->getFromDB($networkports_id)) { $querynet = "SELECT `itemtype`, `items_id`,\n `glpi_plugin_monitoring_services`.`id` \n 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_componentscalalog_id`='" . $pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"] . "'\n AND `itemtype`='" . $itemtype_device . "'\n AND `items_id`='" . $items_id_device . "'\n AND `networkports_id`='" . $networkports_id . "'\n LIMIT 1"; $resultnet = $DB->query($querynet); if ($DB->numrows($resultnet) == 0) { $input = array(); $input['plugin_monitoring_componentscalalog_id'] = $pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"]; $input['is_static'] = '0'; $input['items_id'] = $items_id_device; $input['itemtype'] = $itemtype_device; $componentscatalogs_hosts_id = $pmComponentscatalog_Host->add($input); $pmComponentscatalog_Host->linkComponentsToItem($pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"], $componentscatalogs_hosts_id, $networkports_id); } else { $data2 = $DB->fetch_assoc($resultnet); // modify entity of services (if entity of device is changed) $itemtype = $data2['itemtype']; $item = new $itemtype(); $item->getFromDB($data2['items_id']); $queryu = "UPDATE `glpi_plugin_monitoring_services`\n SET `entities_id`='" . $item->fields['entities_id'] . "'\n WHERE `id`='" . $data2['id'] . "'"; $DB->query($queryu); unset($devicesnetworkport_present[$data2['id']]); } } else { $pmNetworkport->delete($pmNetworkport->fields); } // Reload current entity Session::changeActiveEntities($default_entity, $entities_isrecursive); } else { $queryh = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"] . "'\n AND `itemtype`='" . $itemtype_device . "'\n AND `items_id`='" . $items_id_device . "'\n LIMIT 1"; $resulth = $DB->query($queryh); if ($DB->numrows($resulth) == '0') { $input = array(); $input['plugin_monitoring_componentscalalog_id'] = $pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"]; $input['is_static'] = '0'; $input['items_id'] = $items_id_device; $input['itemtype'] = $itemtype_device; $componentscatalogs_hosts_id = $pmComponentscatalog_Host->add($input); $pmComponentscatalog_Host->linkComponentsToItem($pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"], $componentscatalogs_hosts_id, $networkports_id); } else { $data2 = $DB->fetch_assoc($resulth); // modify entity of services (if entity of device is changed) $itemtype = $data2['itemtype']; $item = new $itemtype(); $item->getFromDB($data2['items_id']); $queryu = "UPDATE `glpi_plugin_monitoring_services`\n SET `entities_id`='" . $item->fields['entities_id'] . "'\n WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $data2['id'] . "'"; $DB->query($queryu); unset($devices_present[$data2['id']]); } } } // Reload current entity Session::changeActiveEntities($default_entity, $entities_isrecursive); foreach ($devicesnetworkport_present as $id => $num) { $_SESSION['plugin_monitoring_hosts']['itemtype'] = $itemtype_device; $_SESSION['plugin_monitoring_hosts']['items_id'] = $items_id_device; $pmService->delete(array('id' => $id)); } } else { // Purge $queryd = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $parm->fields["plugin_monitoring_componentscalalog_id"] . "'\n AND `itemtype`='" . $parm->fields['itemtype'] . "'\n AND `is_static`='0'"; $result = $DB->query($queryd); while ($data = $DB->fetch_array($result)) { $devices_present[$data['id']] = 1; } } foreach ($devices_present as $id => $num) { $pmComponentscatalog_Host->delete(array('id' => $id)); } return true; }
static function showHistory($ID_port) { global $DB, $CFG_GLPI; $np = new NetworkPort(); $query = "\n SELECT * FROM(\n SELECT * FROM (\n SELECT `id`, `date_mod`, `plugin_fusioninventory_agentprocesses_id`,\n `networkports_id_source`, `networkports_id_destination`,\n `creation` as `field`, NULL as `value_old`, NULL as `value_new`\n FROM `glpi_plugin_fusioninventory_networkportconnectionlogs`\n WHERE `networkports_id_source`='" . $ID_port . "'\n OR `networkports_id_destination`='" . $ID_port . "'\n ORDER BY `date_mod` DESC\n )\n AS `DerivedTable1`\n UNION ALL\n SELECT * FROM (\n SELECT `glpi_plugin_fusioninventory_networkportlogs`.`id`,\n `date_mod` as `date_mod`, `plugin_fusioninventory_agentprocesses_id`,\n `networkports_id` AS `networkports_id_source`,\n NULL as `networkports_id_destination`,\n `name` AS `field`, `value_old`, `value_new`\n FROM `glpi_plugin_fusioninventory_networkportlogs`\n LEFT JOIN `glpi_plugin_fusioninventory_mappings`\n ON `glpi_plugin_fusioninventory_networkportlogs`." . "`plugin_fusioninventory_mappings_id` =\n `glpi_plugin_fusioninventory_mappings`.`id`\n WHERE `networkports_id`='" . $ID_port . "'\n ORDER BY `date_mod` DESC\n )\n AS `DerivedTable2`)\n AS `MainTable`\n ORDER BY `date_mod` DESC, `id` DESC"; $text = "<table class='tab_cadre' cellpadding='5' width='950'>"; $text .= "<tr class='tab_bg_1'>"; $text .= "<th colspan='8'>"; $text .= "Historique"; $text .= "</th>"; $text .= "</tr>"; $text .= "<tr class='tab_bg_1'>"; $text .= "<th>" . __('Connection') . "</th>"; $text .= "<th>" . __('Item') . "</th>"; $text .= "<th>" . __('Field') . "</th>"; $text .= "<th></th>"; $text .= "<th></th>"; $text .= "<th></th>"; $text .= "<th>" . __('Date') . "</th>"; $text .= "</tr>"; $result = $DB->query($query); if ($result) { while ($data = $DB->fetch_array($result)) { $text .= "<tr class='tab_bg_1'>"; if (!empty($data["networkports_id_destination"])) { // Connections and disconnections $imgfolder = $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics"; if ($data['field'] == '1') { $text .= "<td align='center'><img src='" . $imgfolder . "/connection_ok.png'/></td>"; } else { $text .= "<td align='center'><img src='" . $imgfolder . "/connection_notok.png'/></td>"; } if ($ID_port == $data["networkports_id_source"]) { if ($np->getFromDB($data["networkports_id_destination"])) { //if (isset($np->fields["items_id"])) { $item = new $np->fields["itemtype"](); $item->getFromDB($np->fields["items_id"]); $link1 = $item->getLink(1); $link = "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $np->fields["id"] . "\">"; if (rtrim($np->fields["name"]) != "") { $link .= $np->fields["name"]; } else { $link .= __('Without name'); } $link .= "</a>"; $text .= "<td align='center'>" . $link . " " . __('on', 'fusioninventory') . " " . $link1 . "</td>"; } else { $text .= "<td align='center'><font color='#ff0000'>" . __('Deleted') . "</font></td>"; } } else { if ($ID_port == $data["networkports_id_destination"]) { $np->getFromDB($data["networkports_id_source"]); if (isset($np->fields["items_id"])) { $item = new $np->fields["itemtype"](); $item->getFromDB($np->fields["items_id"]); $link1 = $item->getLink(1); $link = "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $np->fields["id"] . "\">"; if (rtrim($np->fields["name"]) != "") { $link .= $np->fields["name"]; } else { $link .= __('Without name'); } $link .= "</a>"; $text .= "<td align='center'>" . $link . " " . __('on', 'fusioninventory') . " " . $link1 . "</td>"; } else { $text .= "<td align='center'><font color='#ff0000'>" . __('Deleted') . "</font></td>"; } } } $text .= "<td align='center' colspan='4'></td>"; $text .= "<td align='center'>" . Html::convDateTime($data["date_mod"]) . "</td>"; } else { // Changes values $text .= "<td align='center' colspan='2'></td>"; // $text .= "<td align='center'>". // $FUSIONINVENTORY_MAPPING[NETWORKING_TYPE][$data["field"]]['name']."</td>"; $mapping = new PluginFusioninventoryMapping(); $mapfields = $mapping->get('NetworkEquipment', $data["field"]); if ($mapfields != FALSE) { $text .= "<td align='center'>" . $mapping->getTranslation($mapfields) . "</td>"; } else { $text .= "<td align='center'></td>"; } $text .= "<td align='center'>" . $data["value_old"] . "</td>"; $text .= "<td align='center'>-></td>"; $text .= "<td align='center'>" . $data["value_new"] . "</td>"; $text .= "<td align='center'>" . Html::convDateTime($data["date_mod"]) . "</td>"; } $text .= "</tr>"; } } $text .= "</table>"; return $text; }
public function Cisco1Unmanaged() { global $DB; $DB->connect(); self::restore_database(); $a_lldp = array('ifdescr' => 'GigabitEthernet0/10', 'logical_number' => '', 'sysdescr' => '', 'model' => '', 'ip' => '192.168.200.124', 'mac' => '', 'name' => ''); $pfINetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib(); $networkEquipment = new NetworkEquipment(); $networkport = new NetworkPort(); $networkName = new NetworkName(); $iPAddress = new IPAddress(); $pfNetworkPort = new PluginFusioninventoryNetworkPort(); $pfUnmanaged = new PluginFusioninventoryUnmanaged(); // Nortel switch $networkequipments_id = $networkEquipment->add(array('name' => 'cisco1', 'entities_id' => 0)); $networkports_id = $networkport->add(array('itemtype' => 'NetworkEquipment', 'items_id' => $networkequipments_id, 'entities_id' => 0)); // Unmanaged $unmanageds_id = $pfUnmanaged->add(array('name' => 'otherswitch', 'entities_id' => 0)); $networkports_unknown_id = $networkport->add(array('itemtype' => 'PluginFusioninventoryUnmanaged', 'items_id' => $unmanageds_id, 'entities_id' => 0)); $networknames_id = $networkName->add(array('entities_id' => 0, 'itemtype' => 'NetworkPort', 'items_id' => $networkports_unknown_id)); $iPAddress->add(array('entities_id' => 0, 'itemtype' => 'NetworkName', 'items_id' => $networknames_id, 'name' => '192.168.200.124')); $pfINetworkEquipmentLib->importConnectionLLDP($a_lldp, $networkports_id); $a_portslinks = getAllDatasFromTable('glpi_networkports_networkports'); $this->assertEquals(1, count($a_portslinks), 'May have 1 connection between 2 network ports'); $a_networkports = getAllDatasFromTable('glpi_networkports'); $this->assertEquals(3, count($a_networkports), 'May have 3 network ports (' . print_r($a_networkports, TRUE) . ')'); $a_unkowns = getAllDatasFromTable('glpi_plugin_fusioninventory_unmanageds'); $this->assertEquals(1, count($a_unkowns), 'May have only one unknown device (' . print_r($a_unkowns, TRUE) . ')'); $a_networkport_ref = array('id' => '3', 'items_id' => $unmanageds_id, 'itemtype' => 'PluginFusioninventoryUnmanaged', 'entities_id' => '0', 'is_recursive' => '0', 'logical_number' => '0', 'name' => 'GigabitEthernet0/10', 'instantiation_type' => 'NetworkPortEthernet', 'mac' => NULL, 'comment' => NULL, 'is_deleted' => '0', 'is_dynamic' => '0'); $networkport->getFromDB(3); $this->assertEquals($a_networkport_ref, $networkport->fields, 'New unknown port created'); $a_ref = array('id' => 1, 'networkports_id_1' => $networkports_id, 'networkports_id_2' => 3); $this->assertEquals($a_ref, current($a_portslinks), 'Link port'); }
function generateServicesCfg($file=0, $tag='') { global $DB; PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Starting generateServicesCfg services ($tag) ...\n" ); $pMonitoringCommand = new PluginMonitoringCommand(); $pmEventhandler = new PluginMonitoringEventhandler(); $pMonitoringCheck = new PluginMonitoringCheck(); $pmComponent = new PluginMonitoringComponent(); $pmEntity = new PluginMonitoringEntity(); $pmContact_Item = new PluginMonitoringContact_Item(); $networkPort = new NetworkPort(); $pmService = new PluginMonitoringService(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmHostconfig = new PluginMonitoringHostconfig(); $calendar = new Calendar(); $user = new User(); $profile_User = new Profile_User(); $a_services = array(); $i=0; // TODO: only contacts in allowed entities ... // Prepare individual contacts $a_contacts_entities = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog' 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; } // Prepare groups contacts $group = new Group(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog' AND `groups_id`>0"); foreach ($a_list_contact as $data) { $group->getFromDB($data['groups_id']); if ($group->fields['is_recursive'] == 1) { $contactentities = getSonsOf('glpi_entities', $group->fields['entities_id']); } else { $contactentities = array($group->fields['entities_id'] => $group->fields['entities_id']); } $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if (isset($a_contacts_entities[$data['items_id']][$datag['users_id']])) { $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$datag['users_id']]); } $a_contacts_entities[$data['items_id']][$datag['users_id']] = $contactentities; } } $a_entities_allowed = $pmEntity->getEntitiesByTag($tag); // Toolbox::logInFile("pm-shinken", " Allowed entities:\n"); $a_entities_list = array(); foreach ($a_entities_allowed as $entity) { $a_entities_list = getSonsOf("glpi_entities", $entity); } $where = ''; if (! isset($a_entities_allowed['-1'])) { $where = getEntitiesRestrictRequest("WHERE", "glpi_plugin_monitoring_services", '', $a_entities_list); } // -------------------------------------------------- // "Normal" services .... $query = "SELECT * FROM `glpi_plugin_monitoring_services` $where"; PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Services: $query\n" ); $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { // Toolbox::logInFile("pm-shinken", " - fetch service ".$data['id']."\n"); // if (isset($a_entities_allowed['-1']) // OR isset($a_entities_allowed[$item->fields['entities_id']])) { $notadd = 0; $notadddescription = ''; $a_component = current($pmComponent->find("`id`='".$data['plugin_monitoring_components_id']."'", "", 1)); if (empty($a_component)) { continue; } $a_hostname = array(); $a_hostname_type = array(); $a_hostname_id = array(); $queryh = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts` WHERE `id` = '".$data['plugin_monitoring_componentscatalogs_hosts_id']."' LIMIT 1"; $resulth = $DB->query($queryh); $hostname = ''; $plugin_monitoring_componentscatalogs_id = 0; while ($datah=$DB->fetch_array($resulth)) { $itemtype = $datah['itemtype']; $item = new $itemtype(); if ($item->getFromDB($datah['items_id'])) { // if (isset($a_entities_allowed['-1']) // OR isset($a_entities_allowed[$item->fields['entities_id']])) { // Fix if hostname is not defined ... if (! empty($item->fields['name'])) { $a_hostname[] = preg_replace("/[^A-Za-z0-9\-_]/","",$item->fields['name']); $a_hostname_type[] = $datah['itemtype']; $a_hostname_id[] = $datah['items_id']; $hostname = $item->fields['name']; $plugin_monitoring_componentscatalogs_id = $datah['plugin_monitoring_componentscalalog_id']; } // } } } if (count($a_hostname) > 0) { if (isset($_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']])) { $a_services[$i]['use'] = $_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']]; } $a_services[$i]['host_name'] = implode(",", array_unique($a_hostname)); $a_services[$i]['_HOSTITEMSID'] = implode(",", array_unique($a_hostname_id)); $a_services[$i]['_HOSTITEMTYPE'] = implode(",", array_unique($a_hostname_type)); // Define display_name / service_description $a_services[$i]['service_description'] = (! empty($a_component['description'])) ? $a_component['description'] : preg_replace("/[^A-Za-z0-9\-_]/","",$a_component['name']); // In case have multiple networkt port, may have description different, else be dropped by shinken if ($data['networkports_id'] > 0) { $networkPort->getFromDB($data['networkports_id']); $a_services[$i]['service_description'] .= '-'.preg_replace("/[^A-Za-z0-9\-_]/", "", $networkPort->fields['name']); } $a_services[$i]['display_name'] = $a_component['name']; // $a_services[$i]['_ENTITIESID'] = $item->fields['entities_id']; // $a_services[$i]['_ITEMSID'] = $data['id']; // $a_services[$i]['_ITEMTYPE'] = 'Service'; PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - add service ".$a_services[$i]['service_description']." on ".$a_services[$i]['host_name']."\n" ); if (isset(self::$shinkenParameters['glpi']['entityId'])) { $a_services[$i][self::$shinkenParameters['glpi']['entityId']] = $item->fields['entities_id']; } if (isset(self::$shinkenParameters['glpi']['itemType'])) { $a_services[$i][self::$shinkenParameters['glpi']['itemType']] = 'Service'; } if (isset(self::$shinkenParameters['glpi']['itemId'])) { $a_services[$i][self::$shinkenParameters['glpi']['itemId']] = $data['id']; } // Manage freshness if ($a_component['freshness_count'] == 0) { $a_services[$i]['check_freshness'] = '0'; $a_services[$i]['freshness_threshold'] = '3600'; } else { $multiple = 1; if ($a_component['freshness_type'] == 'seconds') { $multiple = 1; } else if ($a_component['freshness_type'] == 'minutes') { $multiple = 60; } else if ($a_component['freshness_type'] == 'hours') { $multiple = 3600; } else if ($a_component['freshness_type'] == 'days') { $multiple = 86400; } $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = (string)($a_component['freshness_count'] * $multiple); } $pMonitoringCommand->getFromDB($a_component['plugin_monitoring_commands_id']); // Manage arguments $array = array(); preg_match_all("/\\$(ARG\d+)\\$/", $pMonitoringCommand->fields['command_line'], $array); sort($array[0]); $a_arguments = importArrayFromDB($a_component['arguments']); $a_argumentscustom = importArrayFromDB($data['arguments']); foreach ($a_argumentscustom as $key=>$value) { $a_arguments[$key] = $value; } foreach ($a_arguments as $key=>$value) { $a_arguments[$key] = str_replace('!', '\!', html_entity_decode($value)); } $args = ''; foreach ($array[0] as $arg) { if ($arg != '$PLUGINSDIR$' AND $arg != '$NAGIOSPLUGINSDIR$' AND $arg != '$HOSTADDRESS$' AND $arg != '$MYSQLUSER$' AND $arg != '$MYSQLPASSWORD$') { $arg = str_replace('$', '', $arg); if (!isset($a_arguments[$arg])) { $args .= '!'; } else { if (strstr($a_arguments[$arg], "[[HOSTNAME]]")) { $a_arguments[$arg] = str_replace("[[HOSTNAME]]", $hostname, $a_arguments[$arg]); } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTDESCR]]")){ if (class_exists("PluginFusioninventoryNetworkPort")) { $pfNetworkPort = new PluginFusioninventoryNetworkPort(); $pfNetworkPort->loadNetworkport($data['networkports_id']); $descr = $pfNetworkPort->getValue("ifdescr"); $a_arguments[$arg] = str_replace("[[NETWORKPORTDESCR]]", $descr, $a_arguments[$arg]); } } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTNUM]]")){ $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $logicalnum = $pfNetworkPort->fields['logical_number']; $a_arguments[$arg] = str_replace("[[NETWORKPORTNUM]]", $logicalnum, $a_arguments[$arg]); } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTNAME]]")){ if (isset($data['networkports_id']) && $data['networkports_id'] > 0) { $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $portname = $pfNetworkPort->fields['name']; $a_arguments[$arg] = str_replace("[[NETWORKPORTNAME]]", $portname, $a_arguments[$arg]); } else if ($a_services[$i]['_HOSTITEMTYPE'] == 'Computer') { // Get networkportname of networkcard defined $pmHostaddress = new PluginMonitoringHostaddress(); $a_hostaddresses = $pmHostaddress->find("`itemtype`='Computer'" . " AND `items_id`='".$a_services[$i]['_HOSTITEMSID']."'", '', 1); if (count($a_hostaddresses) == 1) { $a_hostaddress = current($a_hostaddresses); if ($a_hostaddress['networkports_id'] > 0) { $networkPort = new NetworkPort(); $networkPort->getFromDB($a_hostaddress['networkports_id']); $a_arguments[$arg] = str_replace("[[NETWORKPORTNAME]]", $networkPort->fields['name'], $a_arguments[$arg]); } } } } else if (strstr($a_arguments[$arg], "[")) { $a_arguments[$arg] = PluginMonitoringService::convertArgument($data['id'], $a_arguments[$arg]); } if ($a_arguments == '') { $notadd = 1; if ($notadddescription != '') { $notadddescription .= ", "; } $notadddescription .= "Argument ".$a_arguments[$arg]." do not have value"; } $args .= '!'.$a_arguments[$arg]; if ($a_arguments[$arg] == '' AND $a_component['alias_command'] != '') { $args .= $a_component['alias_command']; } } } } // End manage arguments if ($a_component['remotesystem'] == 'nrpe') { if ($a_component['alias_command'] != '') { $alias_command = $a_component['alias_command']; if (strstr($alias_command, '[[IP]]')) { $split = explode('-', current($a_hostname)); $ip = PluginMonitoringHostaddress::getIp($split[1], $split[0], ''); $alias_command = str_replace("[[IP]]", $ip, $alias_command); } $a_services[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . "check_nrpe!".$alias_command; } else { $a_services[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . "check_nrpe!".$pMonitoringCommand->fields['command_name']; } } else { $a_services[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . $pMonitoringCommand->fields['command_name'].$args; } // * Manage event handler if ($a_component['plugin_monitoring_eventhandlers_id'] > 0) { if ($pmEventhandler->getFromDB($a_component['plugin_monitoring_eventhandlers_id'])) { $a_services[$i]['event_handler'] = $pmEventhandler->fields['command_name']; } } if (! empty(self::$shinkenParameters['shinken']['services']['process_perf_data'])) $a_services[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['services']['process_perf_data']; if (! empty(self::$shinkenParameters['shinken']['services']['notes'])) $a_services[$i]['notes'] = self::$shinkenParameters['shinken']['services']['notes']; if (! empty(self::$shinkenParameters['shinken']['services']['notes_url'])) $a_services[$i]['notes_url'] = self::$shinkenParameters['shinken']['services']['notes_url']; if (! empty(self::$shinkenParameters['shinken']['services']['action_url'])) $a_services[$i]['action_url'] = self::$shinkenParameters['shinken']['services']['action_url']; if (! empty(self::$shinkenParameters['shinken']['services']['icon_image'])) $a_services[$i]['icon_image'] = self::$shinkenParameters['shinken']['services']['icon_image']; if (! empty(self::$shinkenParameters['shinken']['services']['icon_image_alt'])) $a_services[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['services']['icon_image_alt']; // * Contacts $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog' AND `items_id`='".$plugin_monitoring_componentscatalogs_id."'"); foreach ($a_list_contact as $data_contact) { if ($data_contact['users_id'] > 0) { if (isset($a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$data_contact['users_id']])) { if (in_array($data['entities_id'], $a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } else if ($data_contact['groups_id'] > 0) { $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data_contact['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if (in_array($data['entities_id'], $a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$datag['users_id']])) { $user->getFromDB($datag['users_id']); $a_contacts[] = $user->fields['name']; } } } } $a_contacts_unique = array_unique($a_contacts); $a_services[$i]['contacts'] = implode(',', $a_contacts_unique); // ** If shinken not use templates or template not defined : if (!isset($_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']])) { $pMonitoringCheck->getFromDB($a_component['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; if ($calendar->getFromDB($a_component['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } $a_services[$i]['notification_interval'] = '30'; $a_services[$i]['notification_period'] = "24x7"; $a_services[$i]['notification_options'] = 'w,u,c,r,f,s'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '3600'; $a_services[$i]['notifications_enabled'] = '1'; if (isset($a_services[$i]['event_handler'])) { $a_services[$i]['event_handler_enabled'] = '1'; } else { $a_services[$i]['event_handler_enabled'] = '0'; // $a_services[$i]['event_handler_enabled'] = ''; } $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; // $a_services[$i]['_httpstink'] = 'NO'; } else { // Notification options $a_services[$i]['notification_interval'] = '30'; $pmComponentscatalog->getFromDB($plugin_monitoring_componentscatalogs_id); if ($pmComponentscatalog->fields['notification_interval'] != '30') { $a_services[$i]['notification_interval'] = $pmComponentscatalog->fields['notification_interval']; } $a_services[$i]['notification_period'] = '24x7'; $a_services[$i]['check_period'] = '24x7'; if ($calendar->getFromDB($a_component['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } } // WebUI user interface ... if (isset(self::$shinkenParameters['webui']['serviceIcons']['name'])) { $a_services[$i][self::$shinkenParameters['webui']['serviceIcons']['name']] = self::$shinkenParameters['webui']['serviceIcons']['value']; } if ($notadd == '1') { unset($a_services[$i]); $input = array(); $input['id'] = $data['id']; $input['event'] = $notadddescription; $input['state'] = "CRITICAL"; $input['state_type'] = "HARD"; $pmService->update($input); } else { $i++; } } // } } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateServicesCfg services\n" ); PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Starting generateServicesCfg business rules ...\n" ); // -------------------------------------------------- // Business rules services ... $pmService = new PluginMonitoringService(); $pmServicescatalog = new PluginMonitoringServicescatalog(); $pmBusinessrulegroup = new PluginMonitoringBusinessrulegroup(); $pmBusinessrule = new PluginMonitoringBusinessrule(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmBusinessrule_component = new PluginMonitoringBusinessrule_component(); // Prepare individual contacts $a_contacts_entities = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog' 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; } // Prepare groups contacts $group = new Group(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog' AND `groups_id`>0"); foreach ($a_list_contact as $data) { $group->getFromDB($data['groups_id']); if ($group->fields['is_recursive'] == 1) { $contactentities = getSonsOf('glpi_entities', $group->fields['entities_id']); } else { $contactentities = array($group->fields['entities_id'] => $group->fields['entities_id']); } $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if (isset($a_contacts_entities[$data['items_id']][$datag['users_id']])) { $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$datag['users_id']]); } $a_contacts_entities[$data['items_id']][$datag['users_id']] = $contactentities; } } // Services catalogs $a_listBA = $pmServicescatalog->find("`is_generic`='0'"); foreach ($a_listBA as $dataBA) { if (isset($a_entities_allowed['-1']) OR isset($a_entities_allowed[$dataBA['entities_id']])) { $a_grouplist = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='".$dataBA['id']."'"); $a_group = array(); foreach ($a_grouplist as $gdata) { $pmBusinessrule_component->replayDynamicServices($gdata['id']); $a_listBR = $pmBusinessrule->find( "`plugin_monitoring_businessrulegroups_id`='".$gdata['id']."'"); foreach ($a_listBR as $dataBR) { if ($pmService->getFromDB($dataBR['plugin_monitoring_services_id'])) { if ($pmService->getHostName() != '') { $hostname = preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getHostName()); if ($gdata['operator'] == 'and' OR $gdata['operator'] == 'or' OR strstr($gdata['operator'], ' of:')) { $operator = '|'; if ($gdata['operator'] == 'and') { $operator = '&'; } if (!isset($a_group[$gdata['id']])) { $a_group[$gdata['id']] = ''; if (strstr($gdata['operator'], ' of:')) { $a_group[$gdata['id']] = $gdata['operator']; } $a_group[$gdata['id']] .= $hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getName(array('shinken'=>true))); } else { $a_group[$gdata['id']] .= $operator.$hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getName(array('shinken'=>true))); } } else { $a_group[$gdata['id']] = $gdata['operator']." ".$hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$item->getName()); } } } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - SC group : ".$a_group[$gdata['id']]."\n" ); } } if (count($a_group) > 0) { $pMonitoringCheck->getFromDB($dataBA['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; if ($calendar->getFromDB($dataBA['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } $a_services[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['bp_host']; $a_services[$i]['business_impact'] = $dataBA['business_priority']; $a_services[$i]['service_description'] = preg_replace("/[^A-Za-z0-9\-_]/","",$dataBA['name']); $a_services[$i]['_ENTITIESID'] = $dataBA['id']; $a_services[$i]['_ITEMSID'] = $dataBA['id']; $a_services[$i]['_ITEMTYPE'] = 'ServiceCatalog'; $command = "bp_rule!"; foreach ($a_group as $key=>$value) { if (!strstr($value, "&") AND !strstr($value, "|")) { $a_group[$key] = trim($value); } else { $a_group[$key] = "(".trim($value).")"; } } $a_services[$i]['check_command'] = $command.implode("&", $a_group); if ($dataBA['notification_interval'] != '30') { $a_services[$i]['notification_interval'] = $dataBA['notification_interval']; } else { $a_services[$i]['notification_interval'] = '30'; } $a_services[$i]['notification_period'] = "24x7"; $a_services[$i]['notification_options'] = 'w,u,c,r,f,s'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '3600'; $a_services[$i]['notifications_enabled'] = '1'; $a_services[$i]['event_handler_enabled'] = '0'; //$a_services[$i]['event_handler'] = 'super_event_kill_everyone!DIE'; $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; // $a_services[$i]['_httpstink'] = 'NO'; // * Contacts $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog' AND `items_id`='".$dataBA['id']."'"); foreach ($a_list_contact as $data_contact) { if ($data_contact['users_id'] > 0) { if (isset($a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } else if ($data_contact['groups_id'] > 0) { $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data_contact['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$datag['users_id']])) { $user->getFromDB($datag['users_id']); $a_contacts[] = $user->fields['name']; } } } } $a_contacts_unique = array_unique($a_contacts); $a_services[$i]['contacts'] = implode(',', $a_contacts_unique); $i++; } } } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateServicesCfg business rules\n" ); PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Starting generateServicesCfg business rules templates ...\n" ); // Services catalogs templates // TODO : correctly test and improve it ! $a_listBA = $pmServicescatalog->find("`is_generic`='1'"); foreach ($a_listBA as $dataBA) { PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - SC : ".$dataBA['id']."\n" ); if (isset($a_entities_allowed['-1']) OR isset($a_entities_allowed[$dataBA['entities_id']])) { $pmServicescatalog->getFromDB($dataBA['id']); $a_entitiesServices = $pmServicescatalog->getGenericServicesEntities(); foreach ($a_entitiesServices as $idEntity=>$a_entityServices) { // New entity ... so new business rule ! PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - SC templated services for an entity : ".$idEntity."\n" ); $pmDerivatedSC = new PluginMonitoringServicescatalog(); $a_derivatedSC = $pmDerivatedSC->find("`entities_id`='$idEntity' AND `name` LIKE '".$dataBA['name']."%'"); foreach ($a_derivatedSC as $a_derivated) { PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - a_derivated : ".$a_derivated['name']."\n" ); $a_derivatedSC = $a_derivated; } $a_group = array(); foreach ($a_entityServices as $services) { if ($pmService->getFromDB($services['serviceId'])) { // Toolbox::logInFile("pm-shinken", " - SC templated service entity : ".$services['entityId'].", service : ".$pmService->getName(true)." on ".$pmService->getHostName()."\n"); if ($pmService->getHostName() != '') { $hostname = preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getHostName()); $serviceFakeId = $services['entityId']; $pmBusinessrulegroup->getFromDB($services['BRgroupId']); $BRoperator = $pmBusinessrulegroup->getField('operator'); if ($BRoperator == 'and' OR $BRoperator == 'or' OR strstr($BRoperator, ' of:')) { $operator = '|'; if ($BRoperator == 'and') { $operator = '&'; } if (!isset($a_group[$serviceFakeId])) { $a_group[$serviceFakeId] = ''; if (strstr($BRoperator, ' of:')) { $a_group[$serviceFakeId] = $BRoperator; } $a_group[$serviceFakeId] .= $hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getName(array('shinken'=>true))); } else { $a_group[$serviceFakeId] .= $operator.$hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getName(array('shinken'=>true))); } } else { $a_group[$serviceFakeId] = $BRoperator." ".$hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getHostName()); } // Toolbox::logInFile("pm-shinken", " - SCT group : ".$a_group[$serviceFakeId]."\n"); } } } if (count($a_group) > 0) { $pMonitoringCheck->getFromDB($a_derivatedSC['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; if ($calendar->getFromDB($a_derivatedSC['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } $a_services[$i]['host_name'] = preg_replace("/[^A-Za-z0-9\-_]/","",$a_derivatedSC['name']); $a_services[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['bp_host']; $a_services[$i]['business_impact'] = $a_derivatedSC['business_priority']; $a_services[$i]['service_description'] = preg_replace("/[^A-Za-z0-9\-_]/","",$a_derivatedSC['name']); $a_services[$i]['_ENTITIESID'] = $a_derivatedSC['entities_id']; $a_services[$i]['_ITEMSID'] = $a_derivatedSC['id']; $a_services[$i]['_ITEMTYPE'] = 'ServiceCatalog'; $command = "bp_rule!"; foreach ($a_group as $key=>$value) { if (!strstr($value, "&") AND !strstr($value, "|")) { $a_group[$key] = trim($value); } else { $a_group[$key] = "(".trim($value).")"; } } $a_services[$i]['check_command'] = $command.implode("&", $a_group); if ($a_derivatedSC['notification_interval'] != '30') { $a_services[$i]['notification_interval'] = $a_derivatedSC['notification_interval']; } else { $a_services[$i]['notification_interval'] = '30'; } $a_services[$i]['notification_period'] = "24x7"; $a_services[$i]['notification_options'] = 'w,u,c,r,f,s'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '3600'; $a_services[$i]['notifications_enabled'] = '1'; $a_services[$i]['event_handler_enabled'] = '0'; //$a_services[$i]['event_handler'] = 'super_event_kill_everyone!DIE'; $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; // $a_services[$i]['_httpstink'] = 'NO'; // * Contacts $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog' AND `items_id`='".$dataBA['id']."'"); foreach ($a_list_contact as $data_contact) { if ($data_contact['users_id'] > 0) { if (isset($a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } else if ($data_contact['groups_id'] > 0) { $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data_contact['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$datag['users_id']])) { $user->getFromDB($datag['users_id']); $a_contacts[] = $user->fields['name']; } } } } $a_contacts_unique = array_unique($a_contacts); $a_services[$i]['contacts'] = implode(',', $a_contacts_unique); $i++; } } } } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateServicesCfg business rules templates\n" ); if ($file == "1") { $config = "# Generated by plugin monitoring for GLPI\n# on ".date("Y-m-d H:i:s")."\n\n"; foreach ($a_services as $data) { $config .= $this->writeFile("service", $data); } return array('services.cfg', $config); } else { return $a_services; } }
/** * Show ports for an item * * @param $itemtype integer : item type * @param $ID integer : item ID * @param $withtemplate integer : withtemplate param **/ static function showForItem($itemtype, $ID, $withtemplate = '') { global $DB, $CFG_GLPI, $LANG; $rand = mt_rand(); if (!class_exists($itemtype)) { return false; } $item = new $itemtype(); if (!haveRight('networking', 'r') || !$item->can($ID, 'r')) { return false; } $canedit = $item->can($ID, 'w'); // Show Add Form if ($canedit && (empty($withtemplate) || $withtemplate != 2)) { echo "\n<div class='firstbloc'><table class='tab_cadre_fixe'>"; echo "<tr><td class='tab_bg_2 center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?items_id={$ID}&itemtype={$itemtype}'><strong>" . $LANG['networking'][19] . "</strong></a></td>\n"; echo "<td class='tab_bg_2 center' width='50%'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?items_id={$ID}&itemtype={$itemtype}&several=1'>\n <strong>" . $LANG['networking'][46] . "</strong></a></td>\n"; echo "</tr></table></div>\n"; } initNavigateListItems('NetworkPort', $item->getTypeName() . " = " . $item->getName()); $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '{$ID}'\n AND `itemtype` = '{$itemtype}'\n ORDER BY `name`,\n `logical_number`"; if ($result = $DB->query($query)) { echo "<div class='spaced'>"; if ($DB->numrows($result) != 0) { $colspan = 9; if ($withtemplate != 2) { if ($canedit) { $colspan++; echo "\n<form id='networking_ports{$rand}' name='networking_ports{$rand}' method='post'\n action='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php'>\n"; } } echo "<table class='tab_cadre_fixe'>\n"; echo "<tr><th colspan='{$colspan}'>\n"; if ($DB->numrows($result) == 1) { echo $LANG['networking'][12]; } else { echo $LANG['networking'][11]; } echo " : " . $DB->numrows($result) . "</th></tr>\n"; echo "<tr>"; if ($withtemplate != 2 && $canedit) { echo "<th> </th>\n"; } echo "<th>#</th>\n"; echo "<th>" . $LANG['common'][16] . "</th>\n"; echo "<th>" . $LANG['networking'][51] . "</th>\n"; echo "<th>" . $LANG['networking'][14] . "<br>" . $LANG['networking'][15] . "</th>\n"; echo "<th>" . $LANG['networking'][60] . " / " . $LANG['networking'][61] . "<br>" . $LANG['networking'][59] . "</th>\n"; echo "<th>" . $LANG['networking'][56] . "</th>\n"; echo "<th>" . $LANG['common'][65] . "</th>\n"; echo "<th>" . $LANG['networking'][17] . " :</th>\n"; echo "<th>" . $LANG['networking'][14] . "<br>" . $LANG['networking'][15] . "</th></tr>\n"; $i = 0; $netport = new NetworkPort(); while ($devid = $DB->fetch_row($result)) { $netport->getFromDB(current($devid)); addToNavigateListItems('NetworkPort', $netport->fields["id"]); echo "<tr class='tab_bg_1'>\n"; if ($withtemplate != 2 && $canedit) { echo "<td class='center' width='20'>"; echo "<input type='checkbox' name='del_port[" . $netport->fields["id"] . "]' value='1'>"; echo "</td>\n"; } echo "<td class='center'><strong>"; if ($canedit && $withtemplate != 2) { echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $netport->fields["id"] . "\">"; } echo $netport->fields["logical_number"]; if ($canedit && $withtemplate != 2) { echo "</a>"; } echo "</strong>"; showToolTip($netport->fields['comment']); echo "</td>\n"; echo "<td>" . $netport->fields["name"] . "</td>\n"; echo "<td>" . Dropdown::getDropdownName("glpi_netpoints", $netport->fields["netpoints_id"]) . "</td>\n"; echo "<td>" . $netport->fields["ip"] . "<br>" . $netport->fields["mac"] . "</td>\n"; echo "<td>" . $netport->fields["netmask"] . " / " . $netport->fields["subnet"] . "<br>" . $netport->fields["gateway"] . "</td>\n"; // VLANs echo "<td>"; NetworkPort_Vlan::showForNetworkPort($netport->fields["id"], $canedit, $withtemplate); echo "</td>\n"; echo "<td>" . Dropdown::getDropdownName("glpi_networkinterfaces", $netport->fields["networkinterfaces_id"]) . "</td>\n"; echo "<td width='300' class='tab_bg_2'>"; self::showConnection($item, $netport, $withtemplate); echo "</td>\n"; echo "<td class='tab_bg_2'>"; if ($netport->getContact($netport->fields["id"])) { echo $netport->fields["ip"] . "<br>"; echo $netport->fields["mac"]; } echo "</td></tr>\n"; } echo "</table>\n"; if ($canedit && $withtemplate != 2) { openArrowMassive("networking_ports{$rand}", true); Dropdown::showForMassiveAction('NetworkPort'); closeArrowMassive(); } if ($canedit && $withtemplate != 2) { echo "</form>"; } } else { echo "<table class='tab_cadre_fixe'><tr><th>" . $LANG['networking'][10] . "</th></tr>"; echo "</table>"; } echo "</div>"; } }