You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkRight("networking", READ); if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $netdevice = new NetworkEquipment(); if (isset($_POST["add"])) { $netdevice->check(-1, CREATE, $_POST); if ($newID = $netdevice->add($_POST)) { Event::log($newID, "networkequipment", 4, "inventory", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])); if ($_SESSION['glpibackcreated']) { Html::redirect($netdevice->getFormURL() . "?id=" . $newID); } } Html::back(); } else { if (isset($_POST["delete"])) { $netdevice->check($_POST["id"], DELETE); $netdevice->delete($_POST); Event::log($_POST["id"], "networkequipment", 4, "inventory", sprintf(__('%s deletes an item'), $_SESSION["glpiname"])); $netdevice->redirectToList();
/** * @test */ public function NetworkEquipmentGeneral() { global $DB; $DB->connect(); $networkEquipment = new NetworkEquipment(); $networkEquipment->getFromDB(1); unset($networkEquipment->fields['date_mod']); $a_reference = array('name' => 'switchr2d2', 'serial' => 'FOC147UJEU4', 'id' => '1', 'entities_id' => '0', 'is_recursive' => '0', 'ram' => '64', 'otherserial' => NULL, 'contact' => NULL, 'contact_num' => NULL, 'users_id_tech' => '0', 'groups_id_tech' => '0', 'comment' => NULL, 'locations_id' => '3', 'domains_id' => '0', 'networks_id' => '0', 'networkequipmenttypes_id' => '0', 'networkequipmentmodels_id' => '3', 'networkequipmentfirmwares_id' => '3', 'manufacturers_id' => '29', 'is_deleted' => '0', 'is_template' => '0', 'template_name' => NULL, 'users_id' => '0', 'groups_id' => '0', 'states_id' => '0', 'ticket_tco' => '0.0000', 'is_dynamic' => '1'); $this->assertEquals($a_reference, $networkEquipment->fields); }
/** * Function to update NetworkEquipment * * @param array $a_inventory data fron agent inventory * @param id $items_id id of the networkequipment * * @return nothing */ function updateNetworkEquipment($a_inventory, $items_id) { global $DB; $networkEquipment = new NetworkEquipment(); $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment(); $networkEquipment->getFromDB($items_id); if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = $networkEquipment->fields['entities_id']; } if (!isset($_SESSION['glpiactiveentities'])) { $_SESSION['glpiactiveentities'] = array($networkEquipment->fields['entities_id']); } if (!isset($_SESSION['glpiactive_entity'])) { $_SESSION['glpiactive_entity'] = $networkEquipment->fields['entities_id']; } // * NetworkEquipment $db_networkequipment = $networkEquipment->fields; $a_lockable = PluginFusioninventoryLock::getLockFields('glpi_networkequipments', $items_id); $a_ret = PluginFusioninventoryToolbox::checkLock($a_inventory['NetworkEquipment'], $db_networkequipment, $a_lockable); $a_inventory['NetworkEquipment'] = $a_ret[0]; $mac = $a_inventory['NetworkEquipment']['mac']; unset($a_inventory['NetworkEquipment']['mac']); $input = $a_inventory['NetworkEquipment']; $input['id'] = $items_id; $networkEquipment->update($input); $this->internalPorts($a_inventory['internalport'], $items_id, $mac, 'Internal'); // * NetworkEquipment fusion (ext) $db_networkequipment = array(); $query = "SELECT *\n FROM `" . getTableForItemType("PluginFusioninventoryNetworkEquipment") . "`\n WHERE `networkequipments_id` = '{$items_id}'"; $result = $DB->query($query); while ($data = $DB->fetch_assoc($result)) { foreach ($data as $key => $value) { $db_networkequipment[$key] = Toolbox::addslashes_deep($value); } } if (count($db_networkequipment) == '0') { // Add $a_inventory['PluginFusioninventoryNetworkEquipment']['networkequipments_id'] = $items_id; $pfNetworkEquipment->add($a_inventory['PluginFusioninventoryNetworkEquipment']); } else { // Update $idtmp = $db_networkequipment['id']; unset($db_networkequipment['id']); unset($db_networkequipment['networkequipments_id']); unset($db_networkequipment['plugin_fusioninventory_configsecurities_id']); $a_ret = PluginFusioninventoryToolbox::checkLock($a_inventory['PluginFusioninventoryNetworkEquipment'], $db_networkequipment); $a_inventory['PluginFusioninventoryNetworkEquipment'] = $a_ret[0]; $input = $a_inventory['PluginFusioninventoryNetworkEquipment']; $input['id'] = $idtmp; $pfNetworkEquipment->update($input); } // * Ports $this->importPorts($a_inventory, $items_id); }
/** * @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"); }
/** * @test */ public function AddNetworkEquipment() { global $DB; self::restore_database(); $this->update_time = date('Y-m-d H:i:s'); $a_inventory = array('PluginFusioninventoryNetworkEquipment' => array('sysdescr' => 'Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 12.2(50)SE4, RELEASE SOFTWARE (fc1)\\nTechnical Support: http://www.cisco.com/techsupport\\nCopyright (c) 1986-2010 by Cisco Systems, Inc.\\nCompiled Fri 26-Mar-10 09:14 by prod_rel_team', 'last_fusioninventory_update' => $this->update_time, 'cpu' => 5, 'memory' => 18, 'uptime' => '157 days, 02:14:44.00'), 'networkport' => array(), 'connection-mac' => array(), 'vlans' => array(), 'connection-lldp' => array(), 'internalport' => array('192.168.30.2'), 'itemtype' => 'NetworkEquipment'); $a_inventory['NetworkEquipment'] = array('name' => 'switchr2d2', 'id' => 96, 'serial' => 'FOC147UJXXX', 'otherserial' => '', 'manufacturers_id' => 29, 'locations_id' => 3, 'networkequipmentmodels_id' => 3, 'networkequipmentfirmwares_id' => 3, 'memory' => 18, 'ram' => 64, 'is_dynamic' => 1, 'mac' => '6c:50:4d:39:59:90'); $a_inventory['networkport'] = array('10001' => array('ifdescr' => 'FastEthernet0/1', 'ifinerrors' => 869, 'ifinoctets' => 1953319640, 'ifinternalstatus' => 1, 'iflastchange' => '156 days, 08:37:22.84', 'ifmtu' => 1500, 'name' => 'Fa0/1', 'logical_number' => 10001, 'ifouterrors' => 0, 'ifoutoctets' => 554008368, 'speed' => 100000000, 'ifstatus' => 1, 'iftype' => 6, 'mac' => '6c:50:4d:39:59:81', 'trunk' => 0, 'ifspeed' => 100000000)); $a_inventory['connection-mac'] = array('10001' => array('cc:f9:54:a1:03:45')); $a_inventory['vlans'] = array(); $a_inventory['connection-lldp'] = array(); $pfiNetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib(); $networkEquipment = new NetworkEquipment(); $this->items_id = $networkEquipment->add(array('serial' => 'FOC147UJXXX', 'entities_id' => 0)); $this->assertGreaterThan(0, $this->items_id); $pfiNetworkEquipmentLib->updateNetworkEquipment($a_inventory, $this->items_id); // To be sure not have 2 same informations $pfiNetworkEquipmentLib->updateNetworkEquipment($a_inventory, $this->items_id); }
static function task_definitiontype_networkinventory($a_itemtype) { $a_itemtype['PluginFusioninventoryIPRange'] = __('IP Ranges', 'fusioninventory'); $a_itemtype['NetworkEquipment'] = NetworkEquipment::getTypeName(); $a_itemtype['Printer'] = Printer::getTypeName(); return $a_itemtype; }
if (!isset($_POST['id'])) { exit; } if (!isset($_REQUEST['glpi_tab'])) { exit; } if (!isset($_POST["sort"])) { $_POST["sort"] = ""; } if (!isset($_POST["order"])) { $_POST["order"] = ""; } if (!isset($_POST["withtemplate"])) { $_POST["withtemplate"] = ""; } $netdevice = new NetworkEquipment(); $netdevice->check($_POST["id"], 'r'); if (!empty($_POST["withtemplate"])) { if ($_POST["id"] > 0) { switch ($_REQUEST['glpi_tab']) { case 4: Infocom::showForItem($netdevice, $_POST["withtemplate"]); Contract::showAssociated($netdevice, $_POST["withtemplate"]); break; case 5: Document::showAssociated($netdevice, $_POST["withtemplate"]); break; default: if (!Plugin::displayAction($netdevice, $_REQUEST['glpi_tab'], $_POST["withtemplate"])) { NetworkPort::showForItem('NetworkEquipment', $_POST["id"], $_POST["withtemplate"]); }
function prepareRun($taskjobs_id) { global $DB; $pfTask = new PluginFusioninventoryTask(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $pfIPRange = new PluginFusioninventoryIPRange(); $pfAgent = new PluginFusioninventoryAgent(); $a_specificity = array(); $a_specificity['DEVICE'] = array(); $uniqid = uniqid(); $pfTaskjob->getFromDB($taskjobs_id); $pfTask->getFromDB($pfTaskjob->fields['plugin_fusioninventory_tasks_id']); $NetworkEquipment = new NetworkEquipment(); $NetworkPort = new NetworkPort(); /* * * Different possibilities : * IP RANGE * NetworkEquipment * Printer * * We will count total number of devices to query */ // get all snmpauth $a_snmpauth = getAllDatasFromTable("glpi_plugin_fusioninventory_configsecurities"); // get items_id by type $a_iprange = array(); $a_NetworkEquipment = array(); $a_Printer = array(); $communication = $pfTask->fields['communication']; $a_definition = importArrayFromDB($pfTaskjob->fields['definition']); foreach ($a_definition as $datas) { $itemtype = key($datas); $items_id = current($datas); switch ($itemtype) { case 'PluginFusioninventoryIPRange': $a_iprange[] = $items_id; break; case 'NetworkEquipment': $query = "SELECT `glpi_networkequipments`.`id` AS `gID`,\n `glpi_ipaddresses`.`name` AS `gnifaddr`,\n `plugin_fusioninventory_configsecurities_id`,\n FROM `glpi_networkequipments`\n LEFT JOIN `glpi_plugin_fusioninventory_networkequipments`\n ON `networkequipments_id`=`glpi_networkequipments`.`id`\n LEFT JOIN `glpi_networkports`\n ON `glpi_networkports`.`items_id`=`glpi_networkequipments`.`id`\n AND `glpi_networkports`.`itemtype`='NetworkEquipment'\n LEFT JOIN `glpi_networknames`\n ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n AND `glpi_networknames`.`itemtype`='NetworkPort'\n LEFT JOIN `glpi_ipaddresses`\n ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n WHERE `glpi_networkequipments`.`is_deleted`='0'\n AND `plugin_fusioninventory_configsecurities_id`!='0'\n AND `glpi_networkequipments`.`id` = '" . $items_id . "'\n AND `glpi_ipaddresses`.`name`!=''\n LIMIT 1"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { if (isset($a_snmpauth[$data['plugin_fusioninventory_configsecurities_id']])) { $input = array(); $input['TYPE'] = 'NETWORKING'; $input['ID'] = $data['gID']; $input['IP'] = $data['gnifaddr']; $input['AUTHSNMP_ID'] = $data['plugin_fusioninventory_configsecurities_id']; $a_specificity['DEVICE']['NetworkEquipment' . $data['gID']] = $input; $a_NetworkEquipment[] = $items_id; } } break; case 'Printer': $query = "SELECT `glpi_printers`.`id` AS `gID`,\n `glpi_ipaddresses`.`name` AS `gnifaddr`,\n `plugin_fusioninventory_configsecurities_id`,\n FROM `glpi_printers`\n LEFT JOIN `glpi_plugin_fusioninventory_printers`\n ON `printers_id`=`glpi_printers`.`id`\n LEFT JOIN `glpi_networkports`\n ON `glpi_networkports`.`items_id`=`glpi_printers`.`id`\n AND `glpi_networkports`.`itemtype`='Printer'\n LEFT JOIN `glpi_networknames`\n ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n AND `glpi_networknames`.`itemtype`='NetworkPort'\n LEFT JOIN `glpi_ipaddresses`\n ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n WHERE `glpi_printers`.`is_deleted`=0\n AND `plugin_fusioninventory_configsecurities_id`!='0'\n AND `glpi_printers`.`id` = '" . $items_id . "'\n AND `glpi_ipaddresses`.`name`!=''\n LIMIT 1"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { if (isset($a_snmpauth[$data['plugin_fusioninventory_configsecurities_id']])) { $input = array(); $input['TYPE'] = 'PRINTER'; $input['ID'] = $data['gID']; $input['IP'] = $data['gnifaddr']; $input['AUTHSNMP_ID'] = $data['plugin_fusioninventory_configsecurities_id']; $a_specificity['DEVICE']['Printer' . $data['gID']] = $input; $a_Printer[] = $items_id; } } break; } } // Get all devices on each iprange foreach ($a_iprange as $items_id) { $pfIPRange->getFromDB($items_id); // Search NetworkEquipment $query = "SELECT `glpi_networkequipments`.`id` AS `gID`,\n `glpi_ipaddresses`.`name` AS `gnifaddr`,\n `plugin_fusioninventory_configsecurities_id`,\n FROM `glpi_networkequipments`\n LEFT JOIN `glpi_plugin_fusioninventory_networkequipments`\n ON `networkequipments_id`=`glpi_networkequipments`.`id`\n LEFT JOIN `glpi_networkports`\n ON `glpi_networkports`.`items_id`=`glpi_networkequipments`.`id`\n AND `glpi_networkports`.`itemtype`='NetworkEquipment'\n LEFT JOIN `glpi_networknames`\n ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n AND `glpi_networknames`.`itemtype`='NetworkPort'\n LEFT JOIN `glpi_ipaddresses`\n ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n WHERE `glpi_networkequipments`.`is_deleted`='0'\n AND `plugin_fusioninventory_configsecurities_id`!='0'"; if ($pfIPRange->fields['entities_id'] != '-1') { $entities = "(" . $this->fields['entities_id']; foreach (getAncestorsOf("glpi_entities", $pfIPRange->fields['entities_id']) as $parent) { $entities .= ",{$parent}"; } $entities .= ")"; $query .= " AND `glpi_networkequipments`.`entities_id` IN " . $entities . " "; } $query .= " AND inet_aton(`glpi_ipaddresses`.`name`)\n BETWEEN inet_aton('" . $pfIPRange->fields['ip_start'] . "')\n AND inet_aton('" . $pfIPRange->fields['ip_end'] . "') "; $query .= " GROUP BY `glpi_networkequipments`.`id`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { if (isset($a_snmpauth[$data['plugin_fusioninventory_configsecurities_id']])) { $input = array(); $input['TYPE'] = 'NETWORKING'; $input['ID'] = $data['gID']; $input['IP'] = $data['gnifaddr']; $input['AUTHSNMP_ID'] = $data['plugin_fusioninventory_configsecurities_id']; $a_specificity['DEVICE']['NetworkEquipment' . $data['gID']] = $input; $a_NetworkEquipment[] = $data['gID']; } } // Search Printer $query = "SELECT `glpi_printers`.`id` AS `gID`,\n `glpi_ipaddresses`.`name` AS `gnifaddr`,\n `plugin_fusioninventory_configsecurities_id`,\n FROM `glpi_printers`\n LEFT JOIN `glpi_plugin_fusioninventory_printers`\n ON `printers_id`=`glpi_printers`.`id`\n LEFT JOIN `glpi_networkports`\n ON `glpi_networkports`.`items_id`=`glpi_printers`.`id`\n AND `glpi_networkports`.`itemtype`='Printer'\n LEFT JOIN `glpi_networknames`\n ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n AND `glpi_networknames`.`itemtype`='NetworkPort'\n LEFT JOIN `glpi_ipaddresses`\n ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n WHERE `glpi_printers`.`is_deleted`=0\n AND `plugin_fusioninventory_configsecurities_id`!='0'"; if ($pfIPRange->fields['entities_id'] != '-1') { $entities = "(" . $this->fields['entities_id']; foreach (getAncestorsOf("glpi_entities", $pfIPRange->fields['entities_id']) as $parent) { $entities .= ",{$parent}"; } $entities .= ")"; $query .= "AND `glpi_printers`.`entities_id` IN " . $entities . " "; } $query .= " AND inet_aton(`glpi_ipaddresses`.`name`)\n BETWEEN inet_aton('" . $pfIPRange->fields['ip_start'] . "')\n AND inet_aton('" . $pfIPRange->fields['ip_end'] . "') "; $query .= " GROUP BY `glpi_printers`.`id`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { if (isset($a_snmpauth[$data['plugin_fusioninventory_configsecurities_id']])) { $input = array(); $input['TYPE'] = 'PRINTER'; $input['ID'] = $data['gID']; $input['IP'] = $data['gnifaddr']; $input['AUTHSNMP_ID'] = $data['plugin_fusioninventory_configsecurities_id']; $a_specificity['DEVICE']['Printer' . $data['gID']] = $input; $a_Printer[] = $data['gID']; } } } $count_device = count($a_NetworkEquipment) + count($a_Printer); $a_actions = importArrayFromDB($pfTaskjob->fields['action']); // *** For dynamic agent same subnet, it's an another management *** if (strstr($pfTaskjob->fields['action'], '".2"')) { $a_subnet = array(); $a_agentList = array(); $a_devicesubnet = array(); foreach ($a_NetworkEquipment as $items_id) { $NetworkEquipment->getFromDB($items_id); $a_ip = explode(".", $NetworkEquipment->fields['ip']); $ip_subnet = $a_ip[0] . "." . $a_ip[1] . "." . $a_ip[2] . "."; if (!isset($a_subnet[$ip_subnet])) { $a_subnet[$ip_subnet] = 0; } $a_subnet[$ip_subnet]++; $a_devicesubnet[$ip_subnet]['NetworkEquipment'][$items_id] = 1; } foreach ($a_Printer as $items_id) { $a_ports = $NetworkPort->find("`itemtype`='Printer'\n AND `items_id`='" . $items_id . "'\n AND `ip`!='127.0.0.1'"); foreach ($a_ports as $a_port) { $a_ip = explode(".", $a_port['ip']); $ip_subnet = $a_ip[0] . "." . $a_ip[1] . "." . $a_ip[2] . "."; if (!isset($a_subnet[$ip_subnet])) { $a_subnet[$ip_subnet] = 0; } $a_subnet[$ip_subnet]++; $a_devicesubnet[$ip_subnet]['Printer'][$items_id] = 1; } } $a_agentsubnet = array(); foreach ($a_subnet as $subnet => $num) { $a_agentList = $this->getAgentsSubnet($num, $communication, $subnet); if (!isset($a_agentList)) { $a_agentsubnet[$subnet] = ''; } else { $a_agentsubnet[$subnet] = $a_agentList; } } $a_input = array(); $a_input['plugin_fusioninventory_taskjobs_id'] = $taskjobs_id; $a_input['state'] = 1; $a_input['plugin_fusioninventory_agents_id'] = 0; $a_input['itemtype'] = ''; $a_input['items_id'] = 0; $a_input['uniqid'] = $uniqid; $a_input['execution_id'] = $task->fields['execution_id']; $taskvalid = 0; foreach ($a_agentsubnet as $subnet => $a_agentList) { if (!isset($a_agentList) or isset($a_agentList) && is_array($a_agentList) && count($a_agentList) == '0' or isset($a_agentList) && !is_array($a_agentList) && $a_agentList == '') { // No agent available for this subnet for ($i = 0; $i < 2; $i++) { $itemtype = 'Printer'; if ($i == '0') { $itemtype = 'NetworkEquipment'; } if (isset($a_devicesubnet[$subnet][$itemtype])) { foreach ($a_devicesubnet[$subnet][$itemtype] as $items_id => $num) { $a_input['itemtype'] = $itemtype; $a_input['items_id'] = $items_id; $a_input['specificity'] = exportArrayToDB($a_specificity['DEVICE'][$itemtype . $items_id]); $Taskjobstates_id = $pfTaskjobstate->add($a_input); //Add log of taskjob $a_input['plugin_fusioninventory_taskjobstates_id'] = $Taskjobstates_id; $a_input['state'] = 7; $a_input['date'] = date("Y-m-d H:i:s"); $pfTaskjoblog->add($a_input); $pfTaskjobstate->changeStatusFinish($Taskjobstates_id, 0, '', 1, "Unable to find agent to inventory " . "this " . $itemtype, 0, 0); $a_input['state'] = 1; } } } } else { // add taskjobstate $count_device_subnet = 0; if (isset($a_devicesubnet[$subnet]['NetworkEquipment'])) { $count_device_subnet += count($a_devicesubnet[$subnet]['NetworkEquipment']); } if (isset($a_devicesubnet[$subnet]['Printer'])) { $count_device_subnet += count($a_devicesubnet[$subnet]['Printer']); } $nb_devicebyagent = ceil($count_device_subnet / count($a_agentList)); $nbagent = 0; $agent_id = array_pop($a_agentList); $a_input['state'] = 0; for ($i = 0; $i < 2; $i++) { $itemtype = 'Printer'; if ($i == '0') { $itemtype = 'NetworkEquipment'; } if (isset($a_devicesubnet[$subnet][$itemtype])) { foreach ($a_devicesubnet[$subnet][$itemtype] as $items_id => $num) { $a_input['itemtype'] = $itemtype; $a_input['items_id'] = $items_id; $a_input['specificity'] = exportArrayToDB($a_specificity['DEVICE'][$itemtype . $items_id]); if ($nbagent == $nb_devicebyagent) { $agent_id = array_pop($a_agentList); $nbagent = 0; } $a_input['plugin_fusioninventory_agents_id'] = $agent_id; $nbagent++; $taskvalid++; $Taskjobstates_id = $pfTaskjobstate->add($a_input); //Add log of taskjob $a_input['plugin_fusioninventory_taskjobstates_id'] = $Taskjobstates_id; $a_input['state'] = 7; $a_input['date'] = date("Y-m-d H:i:s"); $pfTaskjoblog->add($a_input); unset($a_input['state']); $a_input['plugin_fusioninventory_agents_id'] = 0; $a_input['state'] = 0; if ($communication == "push") { $_SESSION['glpi_plugin_fusioninventory']['agents'][$agent_id] = 1; } } } } } } if ($taskvalid == "0") { $pfTaskjob->reinitializeTaskjobs($pfTaskjob->fields['plugin_fusioninventory_tasks_id']); } } else { $a_agentList = array(); // *** Only agents not dynamic *** if (!strstr($pfTaskjob->fields['action'], '".1"') and !strstr($pfTaskjob->fields['action'], '".2"')) { $agent_require_model = 0; foreach ($a_actions as $a_action) { if (!in_array('.1', $a_action) and !in_array('.2', $a_action)) { $agent_id = current($a_action); if ($pfAgent->getFromDB($agent_id)) { $agent_version = $pfAgent->getAgentVersion($agent_id); if (strnatcmp($agent_version, '2.3.4') < 0) { $agent_require_model = 1; } if ($communication == 'pull') { $a_agentList[] = $agent_id; } else { if ($pfTaskjob->isAgentAlive('1', $agent_id)) { $a_agentList[] = $agent_id; } } } } } } else { if (strstr($pfTaskjob->fields['action'], '".1"')) { $a_agentList = $this->getAgentsSubnet($count_device, $communication); } } /* * Manage agents */ if (count($a_agentList) == 0) { $a_input = array(); $a_input['plugin_fusioninventory_taskjobs_id'] = $taskjobs_id; $a_input['state'] = 1; $a_input['plugin_fusioninventory_agents_id'] = 0; $a_input['itemtype'] = ''; $a_input['items_id'] = 0; $a_input['uniqid'] = $uniqid; $a_input['execution_id'] = $task->fields['execution_id']; $Taskjobstates_id = $pfTaskjobstate->add($a_input); //Add log of taskjob $a_input['plugin_fusioninventory_taskjobstates_id'] = $Taskjobstates_id; $a_input['state'] = 7; $a_input['date'] = date("Y-m-d H:i:s"); $pfTaskjoblog->add($a_input); $pfTaskjobstate->changeStatusFinish($Taskjobstates_id, 0, '', 1, "Unable to find agent to run this job"); $input_taskjob = array(); $input_taskjob['id'] = $pfTaskjob->fields['id']; //$input_taskjob['status'] = 0; $pfTaskjob->update($input_taskjob); } elseif ($count_device == 0) { $a_input = array(); $a_input['plugin_fusioninventory_taskjobs_id'] = $taskjobs_id; $a_input['state'] = 1; $a_input['plugin_fusioninventory_agents_id'] = 0; $a_input['itemtype'] = ''; $a_input['items_id'] = 0; $a_input['uniqid'] = $uniqid; $Taskjobstates_id = $pfTaskjobstate->add($a_input); //Add log of taskjob $a_input['plugin_fusioninventory_taskjobstates_id'] = $Taskjobstates_id; $a_input['state'] = 7; $a_input['date'] = date("Y-m-d H:i:s"); $pfTaskjoblog->add($a_input); $pfTaskjobstate->changeStatusFinish($Taskjobstates_id, 0, '', 0, "No suitable devices to inventory"); $input_taskjob = array(); $input_taskjob['id'] = $pfTaskjob->fields['id']; //$input_taskjob['status'] = 1; $pfTaskjob->update($input_taskjob); } else { foreach ($a_agentList as $agent_id) { //Add jobstate and put status (waiting on server = 0) $a_input = array(); $a_input['plugin_fusioninventory_taskjobs_id'] = $taskjobs_id; $a_input['state'] = 0; $a_input['plugin_fusioninventory_agents_id'] = $agent_id; $a_input['uniqid'] = $uniqid; $a_input['execution_id'] = $task->fields['execution_id']; $alternate = 0; for ($d = 0; $d < ceil($count_device / count($a_agentList)); $d++) { if (count($a_NetworkEquipment) + count($a_Printer) > 0) { $getdevice = "NetworkEquipment"; if ($alternate == "1") { $getdevice = "Printer"; $alternate = 0; } else { $getdevice = "NetworkEquipment"; $alternate++; } if (count($a_NetworkEquipment) == '0') { $getdevice = "Printer"; } else { if (count($a_Printer) == '0') { $getdevice = "NetworkEquipment"; } } $a_input['itemtype'] = $getdevice; switch ($getdevice) { case 'NetworkEquipment': $a_input['items_id'] = array_pop($a_NetworkEquipment); $a_input['specificity'] = exportArrayToDB($a_specificity['DEVICE']['NetworkEquipment' . $a_input['items_id']]); break; case 'Printer': $a_input['items_id'] = array_pop($a_Printer); $a_input['specificity'] = exportArrayToDB($a_specificity['DEVICE']['Printer' . $a_input['items_id']]); break; } $Taskjobstates_id = $pfTaskjobstate->add($a_input); //Add log of taskjob $a_input['plugin_fusioninventory_taskjobstates_id'] = $Taskjobstates_id; $a_input['state'] = 7; $a_input['date'] = date("Y-m-d H:i:s"); $pfTaskjoblog->add($a_input); unset($a_input['state']); if ($communication == "push") { $_SESSION['glpi_plugin_fusioninventory']['agents'][$agent_id] = 1; } } } } $input_taskjob = array(); $input_taskjob['id'] = $pfTaskjob->fields['id']; $input_taskjob['status'] = 1; $pfTaskjob->update($input_taskjob); } } return $uniqid; }
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { global $CFG_GLPI; // Can exists on template $nb = 0; if (NetworkEquipment::canView()) { if (in_array($item->getType(), $CFG_GLPI["networkport_types"])) { if ($_SESSION['glpishow_count_on_tabs']) { $nb = self::countForItem($item); } return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb); } } if ($item->getType() == 'NetworkPort') { $nbAlias = countElementsInTable('glpi_networkportaliases', "`networkports_id_alias` = '" . $item->getField('id') . "'"); if ($nbAlias > 0) { $aliases = self::createTabEntry(NetworkPortAlias::getTypeName(Session::getPluralNumber()), $nbAlias); } else { $aliases = ''; } $nbAggregates = countElementsInTable('glpi_networkportaggregates', "`networkports_id_list`\n LIKE '%\"" . $item->getField('id') . "\"%'"); if ($nbAggregates > 0) { $aggregates = self::createTabEntry(NetworkPortAggregate::getTypeName(Session::getPluralNumber()), $nbAggregates); } else { $aggregates = ''; } if (!empty($aggregates) && !empty($aliases)) { return $aliases . '/' . $aggregates; } return $aliases . $aggregates; } return ''; }
/** Generate bigdump : generate items for an entity * * @param $ID_entity entity ID **/ function generate_entity($ID_entity) { global $MAX, $DB, $percent, $FIRST, $LAST, $MAX_KBITEMS_BY_CAT, $MAX_DISK, $DOCUMENTS, $NET_PORT, $NET_LOC; regenerateTreeCompleteName("glpi_entities"); $current_year = date("Y"); // DOMAIN $items = array("SP2MI", "CAMPUS"," IUT86", "PRESIDENCE", "CEAT", "D'omaine"); $dp = new Domain(); $FIRST["domain"] = getMaxItem("glpi_domains")+1; for ($i=0 ; $i<$MAX['domain'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "domain $ID_entity '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'comment' => "comment $val"))); } $LAST["domain"] = getMaxItem("glpi_domains"); // STATUS $items = array("Reparation", "En stock", "En fonction", "Retour SAV", "En attente d'"); $dp = new State(); $FIRST["state"] = getMaxItem("glpi_states")+1; for ($i=0 ; $i<$MAX['state'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "State $ID_entity '$i"; } $state_id = $dp->add(toolbox::addslashes_deep(array('name' => $val, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'comment' => "comment $val"))); // generate sub status for ($j=0 ; $j<$MAX['state'] ; $j++) { $val2 = "Sub $val $j"; $dp->add(toolbox::addslashes_deep(array('name' => $val2, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'states_id' => $state_id, 'comment' => "comment $val"))); } } $LAST["state"] = getMaxItem("glpi_states"); // glpi_groups $FIRST["groups"] = getMaxItem("glpi_groups")+1; $group = new Group(); for ($i=0 ; $i<$MAX['groups'] ; $i++) { $gID = $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "group d'$i", 'comment' => "comment group d'$i", 'is_assign' => 0))); // Generate sub group for ($j=0 ; $j<$MAX['groups'] ; $j++) { $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "subgroup d'$j", 'comment' => "comment subgroup d'$j of group $i", 'groups_id' => $gID, 'is_assign' => 0))); } } $LAST["groups"] = getMaxItem("glpi_groups"); $FIRST["techgroups"] = $LAST["groups"]+1; for ($i=0 ; $i<$MAX['groups'] ; $i++) { $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "tech group d'$i", 'comment' => "comment tech group d'$i"))); } $LAST["techgroups"] = getMaxItem("glpi_groups"); regenerateTreeCompleteName("glpi_groups"); // glpi_users $FIRST["users_sadmin"] = getMaxItem("glpi_users")+1; $user = new User(); $gu = new Group_User(); for ($i=0 ; $i<$MAX['users_sadmin'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "sadmin$i-$ID_entity", 'password' => "sadmin'$i", 'password2' => "sadmin'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "sadmin '$i name", 'firstname' => "sadmin '$i firstname", 'comment' => "comment' $i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 4, '_entities_id' => $ID_entity, '_is_recursive' => 1 ))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']))); } $LAST["users_sadmin"] = getMaxItem("glpi_users"); $FIRST["users_admin"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_admin'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "admin$i-$ID_entity", 'password' => "admin'$i", 'password2' => "admin'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "admin$i 'name", 'firstname' => "admin$i 'firstname", 'comment' => "comment '$i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 3, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']), 'is_manager' => 1, 'is_delegate' => 1)); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']), 'is_manager' => 1, 'is_delegate' => 1)); } $LAST["users_admin"] = getMaxItem("glpi_users"); $FIRST["users_normal"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_normal'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "normal$i-$ID_entity", 'password' => "normal'$i", 'password2' => "normal'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "normal$i 'name", 'firstname' => "normal$i 'firstname", 'comment' => "comment '$i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 2, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']))); } $LAST["users_normal"] = getMaxItem("glpi_users"); $FIRST["users_postonly"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_postonly'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "postonly$i-$ID_entity", 'password' => "postonly'$i", 'password2' => "postonly'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "postonly$i 'name", 'firstname' => "postonly$i 'firstname", 'comment' => "comment' $i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 1, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); } $LAST["users_postonly"] = getMaxItem("glpi_users"); $FIRST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories")+1; $kbc = new KnowbaseItemCategory(); for ($i=0 ; $i<max(1,pow($MAX['kbcategories'],1/3)) ; $i++) { $newID = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity ' categorie $i", 'comment' => "comment ' categorie $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $j++) { $newID2 = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity s-categorie '$j", 'comment' => "comment s-categorie '$j", 'knowbaseitemcategories_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $k++) { $newID2 = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity ss-categorie' $k", 'comment' => "comment ss-categorie' $k", 'knowbaseitemcategories_id' => $newID2))); } } } $query = "OPTIMIZE TABLE `glpi_knowbaseitemcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_knowbaseitemcategories"); $LAST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories"); // LOCATIONS $added = 0; $FIRST["locations"] = getMaxItem("glpi_locations")+1; $loc = new Location(); for ($i=0 ; $i<pow($MAX['locations'],1/5)&&$added<$MAX['locations'] ; $i++) { $added++; $newID = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "location' $i", 'comment' => "comment 'location $i", 'building' => "building $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) { $added++; $newID2 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "s-location '$j", 'comment' => "comment s-location '$j", 'building' => "building $i", 'room' => "stage '$j", 'locations_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $k++) { $added++; $newID3 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ss-location '$k", 'comment' => "comment ss-location' $k", 'building' => "building $i", 'room' => "part' $k", 'locations_id' => $newID2))); for ($l=0 ; $l<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $l++) { $added++; $newID4 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "sss-location' $l", 'comment' => "comment sss-location' $l", 'building' => "building $i", 'room' => "room' $l", 'locations_id' => $newID3))); for ($m=0 ; $m<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $m++) { $added++; $newID5 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ssss-location' $m", 'comment' => "comment ssss-location' $m", 'building' => "building $i", 'room' => "room' $l-$m", 'locations_id' => $newID4))); } } } } } $query = "OPTIMIZE TABLE `glpi_locations`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_locations"); $LAST["locations"]=getMaxItem("glpi_locations"); // Task categories $added = 0; $FIRST["taskcategory"] = getMaxItem("glpi_taskcategories")+1; $tc = new TaskCategory(); for ($i=0 ; $i<pow($MAX['taskcategory'],1/5)&&$added<$MAX['taskcategory'] ; $i++) { $added++; $newID = $tc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ent$ID_entity taskcategory' $i", 'comment' => "comment ent$ID_entity taskcategory' $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) { $newID2 = $tc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ent$ID_entity taskcategory' $i", 'comment' => "comment ent$ID_entity taskcategory' $i", 'taskcategories_id' => $newID))); $added++; } } $query = "OPTIMIZE TABLE `glpi_taskcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_taskcategories"); $LAST["taskcategory"] = getMaxItem("glpi_taskcategories"); $ic = new ItilCategory(); // Specific ticket categories $newID = $ic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "category for entity' $ID_entity", 'comment' => "comment category for entity' $ID_entity", 'users_id' => mt_rand($FIRST['users_sadmin'],$LAST['users_admin']), 'groups_id' => mt_rand($FIRST['techgroups'],$LAST['techgroups']), 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1))); for ($i=0 ; $i<max(1,pow($MAX['tracking_category'],1/3)) ; $i++) { $ic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "scategory for entity' $ID_entity", 'comment' => "comment scategory for entity' $ID_entity", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']), 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1, 'itilcategories_id' => $newID))); } regenerateTreeCompleteName("glpi_itilcategories"); $FIRST["solutiontypes"] = getMaxItem("glpi_solutiontypes")+1; $items = array("d'après KB"); $st = new SolutionType(); for ($i=0 ; $i<$MAX['solutiontypes'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de solution ' $i"; } $st->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val", 'entities_id' => $ID_entity, 'is_recursive' => 1))); } $LAST["solutiontypes"] = getMaxItem("glpi_solutiontypes"); $FIRST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates")+1; $nb_items = mt_rand(0,$MAX['solutiontemplates']); $st = new SolutionTemplate(); for ($i=0 ; $i<$nb_items ; $i++) { $st-> add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "solution' $i-$ID_entity", 'content' => "content solution' $i-$ID_entity", 'solutiontypes_id' => mt_rand(0,$MAX['solutiontypes']), 'comment' => "comment solution' $i-$ID_entity"))); } $LAST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates"); // Add Specific questions $k = 0; $FIRST["kbitems"] = getMaxItem("glpi_knowbaseitems")+1; $ki = new KnowbaseItem(); $eki = new Entity_KnowbaseItem(); for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) { $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT); for ($j=0 ; $j<$nb ; $j++) { $k++; $newID = $ki->add(toolbox::addslashes_deep( array('knowbaseitemcategories_id' => $i, 'name' => "Entity' $ID_entity Question $k", 'answer' => "Answer' $k".Toolbox::getRandomString(50), 'is_faq' => mt_rand(0,1), 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin'])))); $eki->add(array('entities_id' => $ID_entity, 'knowbaseitems_id' => $newID, 'is_recursive' => 0)); } } // Add global questions for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) { $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT); for ($j=0 ; $j<$nb ; $j++) { $k++; $newID = $ki->add(toolbox::addslashes_deep( array('knowbaseitemcategories_id' => $i, 'name' => "Entity' $ID_entity Recursive Question $k", 'answer' => "Answer' $k".Toolbox::getRandomString(50), 'is_faq' => mt_rand(0,1), 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin'])))); $eki->add(array('entities_id' => $ID_entity, 'knowbaseitems_id' => $newID, 'is_recursive' => 1)); } } $LAST["kbitems"] = getMaxItem("glpi_knowbaseitems"); // Ajout documents specific $FIRST["document"] = getMaxItem("glpi_documents")+1; $doc = new Document(); for ($i=0 ; $i<$MAX['document'] ; $i++) { $link = ""; if (mt_rand(0,100)<50) { $link = "http://linktodoc/doc$i"; } $docID = $doc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "document' $i-$ID_entity", 'documentcategories_id' => mt_rand(1,$MAX['rubdocs']), 'comment' => "commen't $i", 'link' => $link, 'notepad' => "notes document' $i"))); $DOCUMENTS[$docID] = $ID_entity."-0"; } // Global ones for ($i=0 ; $i<$MAX['document']/2 ; $i++) { $link = ""; if (mt_rand(0,100)<50) { $link = "http://linktodoc/doc$i"; } $docID = $doc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive document' $i-$ID_entity", 'documentcategories_id' => mt_rand(1,$MAX['rubdocs']), 'comment' => "comment' $i", 'link' => $link, 'notepad' => "notes document' $i"))); $DOCUMENTS[$docID] = $ID_entity."-1"; } $LAST["document"] = getMaxItem("glpi_documents"); // Ajout budgets specific $FIRST["budget"] = getMaxItem("glpi_budgets")+1; $b = new Budget(); for ($i=0 ; $i<$MAX['budget'] ; $i++) { $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans $b->add(toolbox::addslashes_deep( array('name' => "budget' $i-$ID_entity", 'entities_id' => $ID_entity, 'is_recusive' => 0, 'comment' => "comment' $i-$ID_entity", 'begin_date' => date("Y-m-d",intval($date1)), 'end_date' => date("Y-m-d",intval($date2))))); } $LAST["budget"] = getMaxItem("glpi_budgets"); // GLobal ones for ($i=0 ; $i<$MAX['document']/2 ; $i++) { $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans $b->add(toolbox::addslashes_deep( array('name' => "Recursive budget' $i-$ID_entity", 'entities_id' => $ID_entity, 'is_recusive' => 1, 'comment' => "comment' $i-$ID_entity", 'begin_date' => date("Y-m-d",intval($date1)), 'end_date' => date("Y-m-d",intval($date2))))); } $LAST["document"] = getMaxItem("glpi_documents"); // glpi_suppliers $items = array("DELL", "IBM", "ACER", "Microsoft", "Epson", "Xerox", "Hewlett Packard", "Nikon", "Targus", "LG", "Samsung", "Lexmark"); $FIRST["enterprises"] = getMaxItem("glpi_suppliers")+1; $ent = new Supplier(); // Global ones for ($i=0 ; $i<$MAX['enterprises']/2 ; $i++) { if (isset($items[$i])) { $val = "Recursive ".$items[$i]; } else { $val = "Recursive enterprise_".$i."_ID_entity"; } $entID = $ent->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive' $val-$ID_entity", 'suppliertypes_id' => mt_rand(1,$MAX['enttype']), 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'website' => "http://www.$val.com/", 'fax' => "fax $i", 'email' => "info@ent$i.com", 'notepad' => "notes enterprises' $i"))); addDocuments('Supplier', $entID); } // Specific ones for ($i=0 ; $i<$MAX['enterprises'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "enterprise_".$i."_ID_entity"; } $entID = $ent->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "'$val-$ID_entity", 'suppliertypes_id' => mt_rand(1,$MAX['enttype']), 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'website' => "http://www.$val.com/", 'fax' => "fax $i", 'email' => "info@ent$i.com", 'notepad' => "notes supplier' $i", 'comment' => "comment supplier' $i"))); addDocuments('Supplier', $entID); } $LAST["enterprises"] = getMaxItem("glpi_suppliers"); // Ajout contracts $FIRST["contract"] = getMaxItem("glpi_contracts")+1; $c = new Contract(); $cs = new Contract_Supplier(); $cc = new ContractCost(); // Specific for ($i=0 ; $i<$MAX['contract'] ; $i++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $contractID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "contract' $i-$ID_entity", 'num' => "num' $i", 'contracttypes_id' => mt_rand(1,$MAX['contract_type']), 'begin_date' => $date, 'duration' => mt_rand(1,36), 'notice' => mt_rand(1,3), 'periodicity' => mt_rand(1,36), 'billing' => mt_rand(1,36), 'comment' => "comment' $i", 'accounting_number' => "compta num' $i", 'renewal' => 1))); addDocuments('Contract', $contractID); // Add an enterprise $cs->add(array('contracts_id' => $contractID, 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"]))); // Add a cost $cc->add(toolbox::addslashes_deep( array('contracts_id' => $contractID, 'cost' => mt_rand(100,10000), 'name' => "Initial 'cost", 'begin_date' => $date, 'budgets_id' => mt_rand($FIRST['budget'], $LAST['budget'])))); } for ($i=0 ; $i<$MAX['contract']/2 ; $i++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $contractID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive contract' $i-$ID_entity", 'num' => "num' $i", 'cost' => mt_rand(100,10000), 'contracttypes_id' => mt_rand(1,$MAX['contract_type']), 'begin_date' => $date, 'duration' => mt_rand(1,36), 'notice' => mt_rand(1,3), 'periodicity' => mt_rand(1,36), 'billing' => mt_rand(1,36), 'comment' => "comment' $i", 'accounting_number' => "compta num' $i", 'renewal' => 1))); addDocuments('Contract', $contractID); // Add an enterprise $cs->add(array('contracts_id' => $contractID, 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"]))); } $LAST["contract"] = getMaxItem("glpi_contracts"); // Ajout contacts $prenoms = array("Jean", "John", "Louis", "Pierre", "Auguste", "Albert", "Julien", "Guillaume", "Bruno", "Maurice", "Francois", "Laurent", "Richard", "Henri", "Clement", "d'avy"); $noms = array("Dupont", "Smith", "Durand", "Martin", "Dubois", "Dufour", "Dupin", "Duval", "Petit", "Grange", "Bernard", "Bonnet", "Richard", "Leroy", "Dumont", "Fontaine", "d'orleans"); $FIRST["contacts"] = getMaxItem("glpi_contacts")+1; $c = new Contact(); $cs = new Contact_Supplier(); for ($i=0 ; $i<$MAX['contacts'] ; $i++) { if (isset($noms[$i])) { $val = $noms[$i]; } else { $val = "name $i"; } if (isset($prenoms[$i])) { $val2 = $prenoms[$i]; } else { $val2 = "firstname $i"; } $contactID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "$val-$ID_entity", 'firstname' => $val2, 'contacttypes_id' => mt_rand(1,$MAX['contact_type']), 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'phone' => "phone $i", 'phone2' => "phone2 $i", 'mobile' => "mobile $i", 'fax' => "fax $i", 'email' => "email $i", 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'comment' => "Comment' $i"))); // Link with enterprise $cs->add(array('contacts_id' => $contactID, 'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises']))); } for ($i=0 ; $i<$MAX['contacts']/2 ; $i++) { if (isset($items[$i])) { $val = "Recursive ".$items[$i]; } else { $val = "Recursive contact $i"; } $contactID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "$val'-$ID_entity", 'contacttypes_id' => mt_rand(1,$MAX['contact_type']), 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'phone' => "phone $i", 'phone2' => "phone2 $i", 'mobile' => "mobile $i", 'fax' => "fax $i", 'email' => "email $i", 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'comment' => "Comment' $i"))); // Link with enterprise $cs->add(array('contacts_id' => $contactID, 'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises']))); } $LAST["contacts"] = getMaxItem("glpi_contacts"); // TYPE DE CONSOMMABLES $FIRST["type_of_consumables"] = getMaxItem("glpi_consumableitems")+1; $ci = new Consumableitem(); for ($i=0 ; $i<$MAX['type_of_consumables'] ; $i++) { $consID = $ci->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => mt_rand(0,1), 'name' => "consumable type' $i", 'ref' => "ref d' $i", 'locations_id' => mt_rand($FIRST["locations"], $LAST['locations']), 'consumableitemtypes_id' => mt_rand(0,$MAX['consumable_type']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'users_id_tech' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id_tech' => mt_rand($FIRST["groups"], $LAST["groups"]), 'comment' => "comment' $i", 'notepad' => "notes consumableitem' $i", 'alarm_threshold' => mt_rand(0,10)))); addDocuments('ConsumableItem', $consID); // AJOUT INFOCOMS addInfocoms('ConsumableItem', $consID, $ID_entity); // Ajout consommable en stock $c = new Consumable(); for ($j=0 ; $j<mt_rand(0,$MAX['consumables_stock']) ; $j++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'consumableitems_id' => $consID, 'date_in' => $date)); // AJOUT INFOCOMS addInfocoms('Consumable', $ID, $ID_entity); } // Ajout consommable donne for ($j=0 ; $j<mt_rand(0,$MAX['consumables_given']) ; $j++) { $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'consumableitems_id' => $consID, 'date_in' => $date, 'date_out' => date("Y-m-d"))); // AJOUT INFOCOMS addInfocoms('Consumable', $ID, $ID_entity); } } $LAST["type_of_consumables"] = getMaxItem("glpi_consumableitems"); // TYPE DE CARTOUCHES $FIRST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems")+1; $ct = new CartridgeItem(); for ($i=0 ; $i<$MAX['type_of_cartridges'] ; $i++) { $cartID = $ct->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => mt_rand(0,1), 'name' => "cartridge ' type $i", 'ref' => "ref '$i", 'locations_id' => mt_rand($FIRST["locations"], $LAST['locations']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'users_id_tech' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id_tech' => mt_rand($FIRST["groups"], $LAST["groups"]), 'comment' => "comment '$i", 'notepad' => "notes cartridgeitem '$i", 'alarm_threshold' => mt_rand(0,10)))); addDocuments('CartridgeItem', $cartID); // AJOUT INFOCOMS addInfocoms('CartridgeItem', $cartID, $ID_entity); $c = new Cartridge(); $cipm = new CartridgeItem_PrinterModel(); // Ajout cartouche en stock for ($j=0 ; $j<mt_rand(0,$MAX['cartridges_stock']) ; $j++) { $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $cartID, 'date_in' => $date)); // AJOUT INFOCOMS addInfocoms('Cartridge', $ID, $ID_entity); } // Assoc printer type to cartridge type $cipm->add(array('cartridgeitems_id' => $cartID, 'printermodels_id' => mt_rand(1,$MAX['type_printers']), )); } $LAST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems"); // Networking $NET_LOC = array(); $FIRST["networking"] = getMaxItem("glpi_networkequipments")+1; $FIRST["printers"] = getMaxItem("glpi_printers")+1; $ne = new NetworkEquipment(); $p = new Printer(); $np = new Netpoint(); $c = new Cartridge(); foreach ($DB->request('glpi_locations') as $data) { $i = $data["id"]; $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $infoIP = getNextIP(); $domainID = mt_rand($FIRST['domain'],$LAST['domain']); $networkID = mt_rand(1,$MAX['network']); // insert networking $netwID = $ne->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "networking '$i-$ID_entity", 'ram' => mt_rand(32,256), 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact '$i", 'contact_num' => "num '$i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment '$i", 'locations_id' => $i, 'domains_id' => $domainID, 'networks_id' => $networkID, 'networkequipmenttypes_id' => mt_rand(1,$MAX['type_networking']), 'networkequipmentmodels_id' => mt_rand(1,$MAX['model_networking']), 'networkequipmentfirmwares_id' => mt_rand(1,$MAX['firmware']), 'manufacturers_id' => mt_rand(1,$MAX['enterprises']), 'mac' => getNextMAC(), 'ip' => $infoIP["ip"], 'notepad' => "notes networking '$i", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); $NET_LOC[$data['id']] = $netwID; addDocuments('NetworkEquipment', $netwID); addContracts('NetworkEquipment', $netwID); // AJOUT INFOCOMS addInfocoms('NetworkEquipment', $netwID, $ID_entity); // Link with father addNetworkEthernetPort('NetworkEquipment', $netwID, $ID_entity, $i); // Ajout imprimantes reseaux : 1 par loc + connexion d un matos reseau + ajout de cartouches // Add trackings addTracking('NetworkEquipment', $netwID, $ID_entity); $typeID = mt_rand(1,$MAX['type_printers']); $modelID = mt_rand(1,$MAX['model_printers']); $recur = mt_rand(0,1); $printID = $p->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recur, 'name' => "printer of loc '$i", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact '$i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'have_serial' => mt_rand(0,1), 'have_parallel' => mt_rand(0,1), 'have_usb' => mt_rand(0,1), 'have_wifi' => mt_rand(0,1), 'have_ethernet' => mt_rand(0,1), 'comment' => "comment' $i", 'memory_size' => mt_rand(0,128), 'locations_id' => $i, 'domains_id' => $domainID, 'networks_id' => $networkID, 'printertypes_id' => $typeID, 'printermodels_id' => $modelID, 'manufacturers_id' => mt_rand(1,$MAX['enterprises']), 'is_global' => 1, 'notepad' => "notes printers '$i", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Printer', $printID); addContracts('Printer', $printID); // Add trackings addTracking('Printer', $printID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Printer', $printID, $ID_entity, $recur); // Add Cartouches // Get compatible cartridge $query = "SELECT `cartridgeitems_id` FROM `glpi_cartridgeitems_printermodels` WHERE `printermodels_id` = '$typeID'"; $result2 = $DB->query($query) or die("PB REQUETE ".$query); if ($DB->numrows($result2)>0) { $ctypeID = $DB->result($result2,0,0) or die (" PB RESULT ".$query); $printed = 0; $oldnb = mt_rand(1,$MAX['cartridges_by_printer']); $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = time(); $inter = abs(round(($date2-$date1)/$oldnb)); // Add old cartridges for ($j=0 ; $j<$oldnb ; $j++) { $printed += mt_rand(0,5000); $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date1+$j*$inter), 'date_out' => date("Y-m-d",$date1+($j+1)*$inter), 'pages' => $printed)); } // Add current cartridges $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => $date, 'date_use' => date("Y-m-d",$date2))); } $iface = mt_rand(1,$MAX['iface']); // Add networking ports addNetworkEthernetPort('Printer', $printID, $ID_entity, $i); } unset($NET_LOC); $LAST["networking"] = getMaxItem("glpi_networkequipments"); //////////// INVENTORY // glpi_computers $FIRST["computers"] = getMaxItem("glpi_computers")+1; $FIRST["monitors"] = getMaxItem("glpi_monitors")+1; $FIRST["phones"] = getMaxItem("glpi_phones")+1; $FIRST["peripherals"] = getMaxItem("glpi_peripherals")+1; $c = new Computer(); $mon = new Monitor(); $cdevmb = new Item_DeviceMotherBoard(); $cdevproc = new Item_DeviceProcessor(); $cdevmem = new Item_DeviceMemory(); $cdevhd = new Item_DeviceHardDrive(); $cdevnc = new Item_DeviceNetworkCard(); $cdevdr = new Item_DeviceDrive(); $cdevcon = new Item_DeviceControl(); $cdevgc = new Item_DeviceGraphicCard(); $cdevsc = new Item_DeviceSoundCard(); $cdevpci = new Item_DevicePci(); $cdevcase = new Item_DeviceCase(); $cdevps = new Item_DevicePowerSupply(); $cdisk = new ComputerDisk(); $np = new Netpoint(); $ci = new Computer_Item(); $phone = new Phone(); $print = new Printer(); $periph = new Peripheral(); $cart = new Cartridge(); for ($i=0 ; $i<$MAX['computers'] ; $i++) { $loc = mt_rand($FIRST["locations"],$LAST['locations']); $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $userID = mt_rand($FIRST['users_normal'],$LAST['users_postonly']); $groupID = mt_rand($FIRST["groups"],$LAST["groups"]); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $domainID = mt_rand($FIRST['domain'],$LAST['domain']); $networkID = mt_rand(1,$MAX['network']); $compID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "computer ' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'operatingsystems_id' => mt_rand(1,$MAX['os']), 'operatingsystemversions_id' => mt_rand(1,$MAX['os_version']), 'operatingsystemservicepacks_id' => mt_rand(1,$MAX['os_sp']), 'os_license_number' => "os sn $i", 'os_licenseid' => "os id $i", 'autoupdatesystems_id' => mt_rand(1,$MAX['os_sp']), 'locations_id' => $loc, 'domains_id' => $domainID, 'networks_id' => $networkID, 'computertypes_id' => mt_rand(1,$MAX['type_computers']), 'computermodels_id' => mt_rand(1,$MAX['model']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'is_global' => 1, 'notepad' => "notes computer '$i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0), 'uuid' => Toolbox::getRandomString(30) ))); addDocuments('Computer', $compID); addContracts('Computer', $compID); $NET_PORT['Computer'][$compID] = 0; // Add trackings addTracking('Computer', $compID, $ID_entity); // Add reservation addReservation('Computer', $compID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Computer', $compID, $ID_entity); // ADD DEVICE $cdevmb->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $max = mt_rand(1,4); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevproc->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $max = mt_rand(1,4); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevmem->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $max = mt_rand(1,2); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevhd->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $cdevnc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15), 'mac' => getNextMAC())); $cdevdr->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevcon->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevgc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevsc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $max = mt_rand(1,4); for($nb = 0; $nb<$max; $nb++) { $cdevpci->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); } $cdevcase->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial'=> Toolbox::getRandomString(15))); $max = mt_rand(1,2); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevps->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } // insert disk $nb_disk = mt_rand(1,$MAX_DISK); for ($j=1 ; $j<=$nb_disk ; $j++) { $totalsize = mt_rand(10000,1000000); $freesize = mt_rand(0,$totalsize); $cdisk->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'computers_id' => $compID, 'name' => "disk '$j", 'device' => "/dev/disk$j", 'mountpoint' => "/mnt/disk$j", 'filesystems_id' => mt_rand(1,10), 'totalsize' => $totalsize, 'freesize' => $freesize))); } // Add networking ports addNetworkEthernetPort('Computer', $compID, $ID_entity, $loc); // Ajout d'un ecran sur l'ordi $monID = $mon->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "monitor' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'size' => mt_rand(14,22), 'have_micro' => mt_rand(0,1), 'have_speaker' => mt_rand(0,1), 'have_subd' => mt_rand(0,1), 'have_bnc' => mt_rand(0,1), 'have_dvi' => mt_rand(0,1), 'have_pivot' => mt_rand(0,1), 'have_hdmi' => mt_rand(0,1), 'have_displayport' => mt_rand(0,1), 'locations_id' => $loc, 'monitortypes_id' => mt_rand(1,$MAX['type_monitors']), 'monitormodels_id' => mt_rand(1,$MAX['model_monitors']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes monitor' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Monitor', $monID); addContracts('Monitor', $monID); // Add trackings addTracking('Monitor', $monID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Monitor', $monID, $ID_entity); $ci->add(array('itemtype' => 'Monitor', 'items_id' => $monID, 'computers_id' => $compID, )); // Ajout d'un telephhone avec l'ordi $telID = $phone->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "phone' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'firmware' => Toolbox::getRandomString(10), 'brand' => "brand' $i", 'phonepowersupplies_id' => mt_rand(0,$MAX['phone_power']), 'number_line' => Toolbox::getRandomString(10), 'have_headset' => mt_rand(0,1), 'have_hp' => mt_rand(0,1), 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_phones']), 'phonemodels_id' => mt_rand(1,$MAX['model_phones']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes phone' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Phone', $telID); addContracts('Phone', $telID); // Add trackings addTracking('Phone', $telID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Phone', $telID, $ID_entity); $ci->add(array('itemtype' => 'Phone', 'items_id' => $telID, 'computers_id' => $compID)); // Ajout des periphs externes en connection directe while (mt_rand(0,100)<$percent['peripherals']) { $periphID = $periph->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "periph of comp' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'brand' => "brand' $i", 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_peripherals']), 'phonemodels_id' => mt_rand(1,$MAX['model_peripherals']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes peripheral' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Peripheral', $periphID); addContracts('Peripheral', $periphID); // Add trackings addTracking('Peripheral', $periphID, $ID_entity); // Add connection $ci->add(array('itemtype' => 'Peripheral', 'items_id' => $periphID, 'computers_id' => $compID)); } // Ajout d'une imprimante connection directe pour X% des computers + ajout de cartouches if (mt_rand(0,100)<=$percent['printer']) { // Add printer $typeID = mt_rand(1,$MAX['type_printers']); $modelID = mt_rand(1,$MAX['model_printers']); $printID = $p->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "printer of comp' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'have_serial' => mt_rand(0,1), 'have_parallel' => mt_rand(0,1), 'have_usb' => mt_rand(0,1), 'have_wifi' => mt_rand(0,1), 'have_ethernet' => mt_rand(0,1), 'comment' => "comment' $i", 'memory_size' => mt_rand(0,128), 'locations_id' => $loc, 'domains_id' => $domainID, 'networks_id' => $networkID, 'printertypes_id' => $typeID, 'printermodels_id' => $modelID, 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes printers '$i", 'users_id' => mt_rand($FIRST['users_postonly'], $LAST['users_postonly']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Printer', $printID); addContracts('Printer', $printID); // Add trackings addTracking('Printer', $printID, $ID_entity); // Add connection $ci->add(array('itemtype' => 'Printer', 'items_id' => $printID, 'computers_id' => $compID)); // AJOUT INFOCOMS addInfocoms('Printer', $printID, $ID_entity); // Add Cartouches // Get compatible cartridge $query = "SELECT `cartridgeitems_id` FROM `glpi_cartridgeitems_printermodels` WHERE `printermodels_id` = '$typeID'"; $result = $DB->query($query) or die("PB REQUETE ".$query); if ($DB->numrows($result)>0) { $ctypeID = $DB->result($result,0,0) or die (" PB RESULT ".$query); $printed = 0; $oldnb = mt_rand(1,$MAX['cartridges_by_printer']); $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = time(); $inter = round(($date2-$date1)/$oldnb); // Add old cartridges for ($j=0 ; $j<$oldnb ; $j++) { $printed += mt_rand(0,5000); $cart->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date1+$j*$inter), 'date_out' => date("Y-m-d",$date1+($j+1)*$inter), 'pages' => $printed)); } // Add current cartridges $cart->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date2))); } } } $LAST["computers"] = getMaxItem("glpi_computers"); $LAST["monitors"] = getMaxItem("glpi_monitors"); $LAST["phones"] = getMaxItem("glpi_phones"); // Add global peripherals $periph = new Peripheral(); $ci = new Computer_Item(); for ($i=0 ; $i<$MAX['global_peripherals'] ; $i++) { $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $periphID = $periph->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "periph '$i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'brand' => "brand' $i", 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_peripherals']), 'phonemodels_id' => mt_rand(1,$MAX['model_peripherals']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'is_global' => 1, 'notepad' => "notes peripheral' $i", 'users_id' => mt_rand($FIRST['users_normal'], $LAST['users_normal']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Peripheral', $periphID); addContracts('Peripheral', $periphID); // Add trackings addTracking('Peripheral', $periphID, $ID_entity); // Add reservation addReservation('Peripheral', $periphID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Peripheral', $periphID, $ID_entity); // Add connections $val = mt_rand(1,$MAX['connect_for_peripherals']); for ($j=1 ; $j<$val ; $j++) { $ci->add(array('itemtype' => 'Peripheral', 'items_id' => $periphID, 'computers_id' => mt_rand($FIRST["computers"],$LAST['computers']))); } } $LAST["peripherals"] = getMaxItem("glpi_peripherals"); $FIRST["software"] = getMaxItem("glpi_softwares")+1; // Ajout logiciels + licences associees a divers PCs $items = array(array("Open'Office", "1.1.4", "2.0", "2.0.1"), array("Microsoft Office", "95", "97", "XP", "2000", "2003", "2007"), array("Acrobat Reader", "6.0", "7.0", "7.04"), array("Gimp", "2.0", "2.2"), array("InkScape", "0.4")); $soft = new Software(); $softvers = new SoftwareVersion(); $softlic = new SoftwareLicense(); $csv = new Computer_SoftwareVersion(); $csl = new Computer_SoftwareLicense(); for ($i=0 ; $i<$MAX['software'] ; $i++) { if (isset($items[$i])) { $name = $items[$i][0]; } else { $name = "software '$i"; } $loc = mt_rand(1,$MAX['locations']); $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $recursive = mt_rand(0,1); $softID = $soft->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'name' => $name, 'comment' => "comment '$i", 'locations_id' => $loc, 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes software '$i", 'users_id' => mt_rand($FIRST['users_admin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'is_helpdesk_visible' => 1, 'softwarecategories_id' => mt_rand(1,$MAX['softwarecategory']) ))); addDocuments('Software', $softID); addContracts('Software', $softID); // Add trackings addTracking('Software', $softID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Software', $softID, $ID_entity); // Add versions $FIRST["version"] = getMaxItem("glpi_softwareversions")+1; if (isset($items[$i])) { $val2 = count($items[$i]); } else { $val2 = mt_rand(1,$MAX['softwareversions']+1); } for ($j=1 ; $j<=$val2 ; $j++) { if (isset($items[$i])) { $version = $items[$i][mt_rand(1,count($items[$i])-1)]; } else { $version = "$j.0"; } $os = mt_rand(1,$MAX['os']); $versID = $softvers->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'softwares_id' => $softID, 'name' => $version, 'comment' => "comment '$version", 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0), 'operatingsystems_id' => $os))); $val3 = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall'])); $comp_id = mt_rand($FIRST["computers"], $LAST['computers']); for ($k=0 ; $k<$val3 ; $k++) { $comp_id++; if ($comp_id>$LAST["computers"]) { $comp_id = $FIRST["computers"]; } $csv->add(array('computers_id' => $comp_id, 'softwareversions_id' => $versID)); } } $LAST["version"] = getMaxItem("glpi_softwareversions"); // Add licenses $val2 = mt_rand(1,$MAX['softwarelicenses']); for ($j=0 ; $j<$val2 ; $j++) { $softwareversions_id_buy = mt_rand($FIRST["version"],$LAST["version"]); $softwareversions_id_use = mt_rand($softwareversions_id_buy,$LAST["version"]); $nbused = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall'])); $licID = $softlic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'softwares_id' => $softID, 'number' => $nbused, 'softwarelicensetypes_id' => mt_rand(1,$MAX['licensetype']), 'name' => "license '$j", 'serial' => "serial $j", 'otherserial' => "otherserial $j", 'comment' => "comment license '$j", 'softwareversions_id_buy' => $softwareversions_id_buy, 'softwareversions_id_use' => $softwareversions_id_use))); $comp_id = mt_rand($FIRST["computers"], $LAST['computers']); for ($k=0 ; $k<$nbused ; $k++) { $comp_id++; if ($comp_id>$LAST["computers"]) { $comp_id = $FIRST["computers"]; } $csl->add(array('computers_id' => $comp_id, 'softwarelicenses_id' => $licID)); } } } $LAST["software"] = getMaxItem("glpi_softwares"); }
/** * @test */ public function UpdateNetworkEquipment() { // Load session rights $_SESSION['glpidefault_entity'] = 0; Session::initEntityProfiles(2); Session::changeProfile(4); // Update 2nd time $pfCND = new PluginFusioninventoryCommunicationNetworkDiscovery(); $networkEquipment = new NetworkEquipment(); $networkEquipment->getFromDB(1); $_SESSION['SOURCE_XMLDEVICE'] = $this->source_xmldevice; $pfCND->importDevice($networkEquipment); }
echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Last inventory') . "</th>"; echo "<th>" . __('Item type') . "</th>"; echo "<th>" . __('IP') . "</th>"; echo "<th>" . __('Serial Number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "<th>" . __('Model') . "</th>"; echo "<th>" . __('SNMP authentication') . "</th>"; echo "<th>" . __('Status') . "</th>"; echo "</tr>"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_array($result)) { echo "<tr class='tab_bg_1'>"; echo "<td>"; if ($data['network_id'] > 0) { $class = new NetworkEquipment(); $class->getFromDB($data['network_id']); } else { if ($data['printer_id'] > 0) { $class = new Printer(); $class->getFromDB($data['printer_id']); } } echo $class->getLink(1); echo "</td>"; echo "<td>" . Html::convDateTime($data['last_fusioninventory_update']) . "</td>"; echo "<td>"; if ($data['network_id'] > 0) { echo __('Networks'); } else { if ($data['printer_id'] > 0) {
function generateHostsCfg($file = 0, $tag = '') { global $DB; $pmCommand = new PluginMonitoringCommand(); $pmCheck = new PluginMonitoringCheck(); $pmComponent = new PluginMonitoringComponent(); $pmEntity = new PluginMonitoringEntity(); $pmHostconfig = new PluginMonitoringHostconfig(); $pmHost = new PluginMonitoringHost(); $calendar = new Calendar(); $pmRealm = new PluginMonitoringRealm(); $networkEquipment = new NetworkEquipment(); $pmContact_Item = new PluginMonitoringContact_Item(); $profile_User = new Profile_User(); $user = new User(); $a_hosts = array(); $i = 0; $a_parents_found = array(); $a_hosts_found = array(); $a_entities_allowed = $pmEntity->getEntitiesByTag($tag); // * Prepare contacts $a_contacts_entities = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog'\n AND `users_id`>0"); foreach ($a_list_contact as $data) { $contactentities = getSonsOf('glpi_entities', $data['entities_id']); if (isset($a_contacts_entities[$data['items_id']][$data['users_id']])) { $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$data['users_id']]); } $a_contacts_entities[$data['items_id']][$data['users_id']] = $contactentities; } $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n GROUP BY `itemtype`, `items_id`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $classname = $data['itemtype']; $class = new $classname(); if ($class->getFromDB($data['items_id'])) { if (isset($a_entities_allowed['-1']) or isset($a_entities_allowed[$class->fields['entities_id']])) { $a_hosts[$i]['host_name'] = $classname . "-" . $data['items_id'] . "-" . preg_replace("/[^A-Za-z0-9]/", "", $class->fields['name']); $a_hosts_found[$a_hosts[$i]['host_name']] = 1; $a_hosts[$i]['alias'] = preg_replace("/[^A-Za-z0-9]/", "", $class->fields['name']) . " / " . $classname . "-" . $data['items_id']; if (isset($class->fields['networkequipmenttypes_id'])) { if ($class->fields['networkequipmenttypes_id'] > 0) { $a_hosts[$i]['alias'] .= " (" . Dropdown::getDropdownName("glpi_networkequipmenttypes", $class->fields['networkequipmenttypes_id']) . ")"; } } else { if (isset($class->fields['computertypes_id'])) { if ($class->fields['computertypes_id'] > 0) { $a_hosts[$i]['alias'] .= " (" . Dropdown::getDropdownName("glpi_computertypes", $class->fields['computertypes_id']) . ")"; } } else { if (isset($class->fields['printertypes_id'])) { if ($class->fields['printertypes_id'] > 0) { $a_hosts[$i]['alias'] .= " (" . Dropdown::getDropdownName("glpi_printertypes", $class->fields['printertypes_id']) . ")"; } } } } $ip = PluginMonitoringHostaddress::getIp($data['items_id'], $data['itemtype'], $class->fields['name']); $a_hosts[$i]['address'] = $ip; // Manage dependencies $parent = ''; if ($data['itemtype'] != 'NetworkEquipment') { $networkPort = new NetworkPort(); $a_networkports = $networkPort->find("`itemtype`='" . $data['itemtype'] . "'\n AND `items_id`='" . $data['items_id'] . "'"); foreach ($a_networkports as $data_n) { $networkports_id = $networkPort->getContact($data_n['id']); if ($networkports_id) { $networkPort->getFromDB($networkports_id); if ($networkPort->fields['itemtype'] == 'NetworkEquipment') { $networkEquipment->getFromDB($networkPort->fields['items_id']); $parent = 'NetworkEquipment-' . $networkPort->fields['items_id'] . '-' . preg_replace("/[^A-Za-z0-9]/", "", $networkEquipment->fields['name']); $a_parents_found[$parent] = 1; $pmHost->updateDependencies($classname, $data['items_id'], 'NetworkEquipment-' . $networkPort->fields['items_id']); } } } } $a_hosts[$i]['parents'] = $parent; $a_fields = array(); $pmCommand->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_commands_id', $class->fields['entities_id'], $classname, $class->getID())); $a_component = current($pmComponent->find("`plugin_monitoring_commands_id`='" . $pmCommand->fields['id'] . "'", "", 1)); $a_fields = $a_component; $a_hosts[$i]['check_command'] = $pmCommand->fields['command_name']; $pmCheck->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_checks_id', $class->fields['entities_id'], $classname, $class->getID())); $a_hosts[$i]['check_interval'] = $pmCheck->fields['check_interval']; $a_hosts[$i]['retry_interval'] = $pmCheck->fields['retry_interval']; $a_hosts[$i]['max_check_attempts'] = $pmCheck->fields['max_check_attempts']; if ($calendar->getFromDB($pmHostconfig->getValueAncestor('calendars_id', $class->fields['entities_id'], $classname, $class->getID()))) { $a_hosts[$i]['check_period'] = $calendar->fields['name']; } else { $a_hosts[$i]['check_period'] = "24x7"; } $pmRealm->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_realms_id', $class->fields['entities_id'], $classname, $class->getID())); $a_hosts[$i]['realm'] = $pmRealm->fields['name']; $a_hosts[$i]['process_perf_data'] = '1'; $a_hosts[$i]['notification_interval'] = '30'; // For contact check if a service with this component $a_hosts[$i]['contacts'] = ''; $querycont = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n LEFT JOIN `glpi_plugin_monitoring_services`\n ON `plugin_monitoring_componentscatalogs_hosts_id`\n = `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`\n WHERE `plugin_monitoring_components_id`='" . $a_component['id'] . "'\n AND `items_id`='" . $data['items_id'] . "'\n AND `itemtype`='" . $data['itemtype'] . "'\n LIMIT 1"; $resultcont = $DB->query($querycont); if ($DB->numrows($resultcont) != 0) { $a_componentscatalogs_hosts = $DB->fetch_assoc($resultcont); // Notification interval $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponentscatalog->getFromDB($a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']); $a_hosts[$i]['notification_interval'] = $pmComponentscatalog->fields['notification_interval']; $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog'\n AND `items_id`='" . $a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id'] . "'"); foreach ($a_list_contact as $data_contact) { if (isset($a_contacts_entities[$a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']][$data_contact['users_id']])) { if (in_array($class->fields['entities_id'], $a_contacts_entities[$a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } if (count($a_contacts) > 0) { $a_contacts_unique = array_unique($a_contacts); $a_hosts[$i]['contacts'] = implode(',', $a_contacts_unique); } } if ($calendar->getFromDB($a_fields['calendars_id'])) { $a_hosts[$i]['notification_period'] = $calendar->fields['name']; } else { $a_hosts[$i]['notification_period'] = "24x7"; } $a_hosts[$i]['notification_options'] = 'd,u,r'; $i++; } } } // Check if parents all exist in hosts config foreach ($a_parents_found as $host => $num) { if (!isset($a_hosts_found[$host])) { // Delete parents not added in hosts config foreach ($a_hosts as $id => $data) { if ($data['parents'] == $host) { $a_hosts[$id]['parents'] = ''; } } } } if ($file == "1") { $config = "# Generated by plugin monitoring for GLPI\n# on " . date("Y-m-d H:i:s") . "\n\n"; foreach ($a_hosts as $data) { $config .= $this->constructFile("host", $data); } return array('hosts.cfg', $config); } else { return $a_hosts; } }
$ordi = ''; if (class_exists($np->fields["itemtype"])) { $item = new $np->fields["itemtype"](); if ($item->getFromDB($np->fields["items_id"])) { $ordi = $item->getName(); } } $ip2 = $np->fields['ip']; $mac2 = $np->fields['mac']; $portordi = $np->fields['name']; } $ip = $ligne['ip']; $mac = $ligne['mac']; $port = $ligne['port']; $np->getFromDB($ligne['IDport']); $nd = new NetworkEquipment(); $nd->getFromDB($np->fields["items_id"]); $switch = $nd->fields["name"]; //inserer ces valeures dans un tableau echo "<tr class='tab_bg_1'>"; if ($lieu) { echo "<td>{$lieu}</td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; } if ($switch) { echo "<td>{$switch}</td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; } if ($ip) {
include "../../../inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); Session::checkLoginUser(); switch ($_POST['itemtype']) { case 'PluginMonitoringServicescatalog': Dropdown::show('PluginMonitoringServicescatalog', array('name' => 'items_id')); break; case 'PluginMonitoringComponentscatalog': Dropdown::show('PluginMonitoringComponentscatalog', array('name' => 'items_id')); echo "<br/>" . __('Display minemap', 'monitoring') . " : "; Dropdown::showYesNo('is_minemap'); break; case 'PluginMonitoringService': $rand = mt_rand(); $elements = array('0' => Dropdown::EMPTY_VALUE, 'Computer' => Computer::getTypeName(), 'NetworkEquipment' => NetworkEquipment::getTypeName()); Dropdown::showFromArray('itemtype', $elements, array('rand' => $rand, 'emptylabel' => true, 'display_emptychoice' => true)); $params = array('itemtype' => '__VALUE__', 'entity_restrict' => $_POST['a_entities'], 'selectgraph' => '1', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_itemtype{$rand}", "show_itemtype{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownServiceHostType.php", $params); echo "<span id='show_itemtype{$rand}'><input type='hidden' name='services_id[]' value='0'/></span>\n"; break; case 'PluginMonitoringWeathermap': $toadd = array('-1' => "[" . __('Legend', 'monitoring') . "]"); Dropdown::show('PluginMonitoringWeathermap', array('name' => 'items_id', 'toadd' => $toadd)); echo "<br/>" . __('% of the width of the frame', 'monitoring') . " : "; Dropdown::showNumber("extra_infos", array('value' => 100, 'min' => 0, 'max' => 100, 'step' => 5)); break; case 'PluginMonitoringDisplayview': if (isset($_POST['sliders_id'])) { Dropdown::show('PluginMonitoringDisplayview', array('name' => 'items_id')); } else {
/** * @test */ public function prepareDB() { global $DB; $DB->connect(); $entity = new Entity(); $computer = new Computer(); $pfAgent = new PluginFusioninventoryAgent(); $pfTask = new PluginFusioninventoryTask(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfIPRange = new PluginFusioninventoryIPRange(); $networkEquipment = new NetworkEquipment(); $networkPort = new NetworkPort(); $printer = new Printer(); $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment(); // Create entities $_SESSION['glpiactive_entity'] = 0; $DB->query("INSERT INTO `glpi_entities`\n (`id`, `name`, `entities_id`, `completename`, `level`)\n VALUES (1, 'ent1', 0, 'Entité racine > ent1', 2)"); $DB->query("INSERT INTO `glpi_entities`\n (`id`, `name`, `entities_id`, `completename`, `level`)\n VALUES (2, 'ent2', 0, 'Entité racine > ent2', 2)"); $DB->query("INSERT INTO `glpi_entities`\n (`id`, `name`, `entities_id`, `completename`, `level`)\n VALUES (3, 'ent1.1', 1, 'Entité racine > ent1 > ent1.1', 3)"); // Create computers + agents $input = array('entities_id' => 0, 'name' => 'computer1'); $computers_id = $computer->add($input); $input = array('entities_id' => 0, 'name' => 'computer1', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer1', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id); $pfAgent->add($input); // Create Network Equipments $input = array('name' => 'sw0', 'entities_id' => 0); $networkEquipment->add($input); $input = array('entities_id' => 0, 'name' => 'management', 'items_id' => 1, 'itemtype' => 'NetworkEquipment', 'instantiation_type' => 'NetworkPortAggregate', 'NetworkName__ipaddresses' => array('-1' => '10.0.0.10')); $networkPort->splitInputForElements($input); $networkPort->add($input); $networkPort->updateDependencies(1); $input = array('networkequipments_id' => 1, 'plugin_fusioninventory_configsecurities_id' => 2); $pfNetworkEquipment->add($input); $input = array('name' => 'sw1', 'entities_id' => 1); $networkEquipment->add($input); $input = array('entities_id' => 1, 'name' => 'management', 'items_id' => 2, 'itemtype' => 'NetworkEquipment', 'instantiation_type' => 'NetworkPortAggregate', 'NetworkName__ipaddresses' => array('-1' => '10.0.0.11')); $networkPort->splitInputForElements($input); $networkPort->add($input); $networkPort->updateDependencies(1); $input = array('networkequipments_id' => 2, 'plugin_fusioninventory_configsecurities_id' => 2); $pfNetworkEquipment->add($input); $input = array('name' => 'sw2', 'entities_id' => 2); $networkEquipment->add($input); $input = array('entities_id' => 2, 'name' => 'management', 'items_id' => 3, 'itemtype' => 'NetworkEquipment', 'instantiation_type' => 'NetworkPortAggregate', 'NetworkName__ipaddresses' => array('-1' => '10.0.0.12')); $networkPort->splitInputForElements($input); $networkPort->add($input); $networkPort->updateDependencies(1); $input = array('networkequipments_id' => 3, 'plugin_fusioninventory_configsecurities_id' => 2); $pfNetworkEquipment->add($input); $input = array('name' => 'sw3/1.1', 'entities_id' => 3); $networkEquipment->add($input); $input = array('entities_id' => 3, 'name' => 'management', 'items_id' => 4, 'itemtype' => 'NetworkEquipment', 'instantiation_type' => 'NetworkPortAggregate', 'NetworkName__ipaddresses' => array('-1' => '10.0.0.21')); $networkPort->splitInputForElements($input); $networkPort->add($input); $networkPort->updateDependencies(1); $input = array('networkequipments_id' => 4, 'plugin_fusioninventory_configsecurities_id' => 2); $pfNetworkEquipment->add($input); // Create Printers // Add IPRange $input = array('entities_id' => 1, 'name' => 'Office', 'ip_start' => '10.0.0.1', 'ip_end' => '10.0.0.254'); $ipranges_id = $pfIPRange->add($input); // Allow all agents to do network discovery $query = "UPDATE `glpi_plugin_fusioninventory_agentmodules` " . " SET `is_active`='1' " . " WHERE `modulename`='NETWORKINVENTORY'"; $DB->query($query); // create task $input = array('entities_id' => 0, 'name' => 'network inventory', 'is_active' => 1); $tasks_id = $pfTask->add($input); // create taskjob $input = array('plugin_fusioninventory_tasks_id' => $tasks_id, 'entities_id' => 0, 'name' => 'inventory', 'method' => 'networkinventory', 'targets' => '[{"PluginFusioninventoryIPRange":"' . $ipranges_id . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"1"}]'); $pfTaskjob->add($input); }
public function deleteItem($input) { $this->check($input['id'], UPDATE); $connections_id = $this->getField('plugin_connections_connections_id'); $items_id = $this->getField('items_id'); if ($this->delete($input)) { // History Log into PluginConnectionsConnection $item = new NetworkEquipment(); $item->getFromDB($items_id); $changes[0] = 0; $changes[1] = $item->getNameID(array('forceid' => true)); $changes[2] = ''; Log::history($connections_id, 'PluginConnectionsConnection', $changes, 'NetworkEquipment', 16); // History Log into NetworkEquipment $item = new PluginConnectionsConnection(); $item->getFromDB($connections_id); $changes[0] = 0; $changes[1] = $item->getNameID(array('forceid' => true)); $changes[2] = ''; Log::history($items_id, 'NetworkEquipment', $changes, 'PluginConnectionsConnection', 16); } }
/** * if NetworkEquipment purged * * @param NetworkEquipment $net * @internal param NetworkEquipment $comp object */ static function purgeNetworkEquipment(NetworkEquipment $net) { $snmp = new self(); $snmp->deleteByCriteria(array('items_id' => $net->getField("id"), 'itemtype' => $net->getType())); $ipdiscover = new PluginOcsinventoryngIpdiscoverOcslink(); $ipdiscover->deleteByCriteria(array('items_id' => $net->getField("id"), 'itemtype' => $net->getType())); }
break; case 'PluginMonitoringComponentscatalog': Dropdown::show('PluginMonitoringComponentscatalog', array('name'=>'items_id')); echo "<br/>".__('Display minemap', 'monitoring')." : "; Dropdown::showYesNo('is_minemap'); break; case 'PluginMonitoringService': $rand = mt_rand(); echo "<select name='itemtype' id='itemtype$rand'>"; echo "<option value='0'>".Dropdown::EMPTY_VALUE."</option>"; // $a_types =array(); echo "<option value='Computer'>".Computer::getTypeName()."</option>"; echo "<option value='NetworkEquipment'>".NetworkEquipment::getTypeName()."</option>"; echo "</select>"; $params = array('itemtype' => '__VALUE__', 'entity_restrict' => $_POST['a_entities'], 'selectgraph' => '1', 'rand' => $rand); Ajax::updateItemOnSelectEvent("itemtype$rand", "show_itemtype$rand", $CFG_GLPI["root_doc"]."/plugins/monitoring/ajax/dropdownServiceHostType.php", $params); echo "<span id='show_itemtype$rand'><input type='hidden' name='services_id[]' value='0'/></span>\n"; break; case 'PluginMonitoringWeathermap':
based on GLPI - Gestionnaire Libre de Parc Informatique Copyright (C) 2003-2014 by the INDEPNET Development Team. ------------------------------------------------------------------------- LICENSE This file is part of GLPI. GLPI is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkRight("networking", READ); Html::header(NetworkEquipment::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "assets", "networkequipment"); Search::show('NetworkEquipment'); Html::footer();
// 3. Selection d'affichage pour generer la liste echo "<form name='form' method='post' action='report.location.list.php'>"; echo "<table class='tab_cadre' width='500'>"; echo "<tr class='tab_bg_1'><td width='120'>" . __('By location') . "</td>"; echo "<td>"; Location::dropdown(array('entity' => $_SESSION["glpiactive_entity"])); echo "</td><td class='center' width='120'>"; echo "<input type='submit' value=\"" . __s('Display report') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "<form name='form2' method='post' action='report.switch.list.php'>"; echo "<table class='tab_cadre' width='500'>"; echo "<tr class='tab_bg_1'><td width='120'>" . __('By hardware') . "</td>"; echo "<td>"; NetworkEquipment::dropdown(array('name' => 'switch')); echo "</td><td class='center' width='120'>"; echo "<input type='submit' value=\"" . __s('Display report') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); if (countElementsInTableForMyEntities("glpi_netpoints") > 0) { echo "<form name='form3' method='post' action='report.netpoint.list.php'>"; echo "<table class='tab_cadre' width='500'>"; echo "<tr class='tab_bg_1'><td width='120'>" . __('By network outlet') . "</td>"; echo "<td>"; Netpoint::dropdownNetpoint("prise", 0, -1, 1, $_SESSION["glpiactive_entity"]); echo "</td><td class='center' width='120'>"; echo "<input type='submit' value=\"" . __s('Display report') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>";
/** * Function to import discovered device * * @param $items_id id of the device to import * * @return nothing * **/ function import($items_id, $Import = 0, $NoImport = 0) { global $DB; $NetworkPort = new NetworkPort(); $a_NetworkPorts = $NetworkPort->find("`items_id` = '" . $items_id . "'\n AND `itemtype` = 'PluginFusioninventoryUnmanaged'"); $this->getFromDB($items_id); $this->fields = Toolbox::addslashes_deep($this->fields); $data = array(); switch ($this->fields['item_type']) { case 'Printer': $Printer = new Printer(); $data["entities_id"] = $this->fields["entities_id"]; if (!empty($this->fields["name"])) { $data["name"] = $this->fields["name"]; } $data["locations_id"] = $this->fields["locations_id"]; $data["serial"] = $this->fields["serial"]; $data["otherserial"] = $this->fields["otherserial"]; $data["contact"] = $this->fields["contact"]; $data["domain"] = $this->fields["domain"]; $data["comment"] = $this->fields["comment"]; $data["is_dynamic"] = 1; $printer_id = $Printer->add($data); foreach ($a_NetworkPorts as $data_Port) { $data_Port['items_id'] = $printer_id; $data_Port['itemtype'] = $Printer->getType(); $NetworkPort->update($data_Port); } // Import SNMP $pfPrinter = new PluginFusioninventoryPrinter(); $_SESSION['glpi_plugins_fusinvsnmp_table'] = "glpi_plugin_fusioninventory_printers"; $query = "SELECT *\n FROM `glpi_plugin_fusioninventory_printers`\n WHERE `printers_id`='" . $printer_id . "' "; $result = $DB->query($query); $data = array(); if ($DB->numrows($result) > 0) { $data = $DB->fetch_assoc($result); } $data['sysdescr'] = $this->fields['sysdescr']; $data['plugin_fusioninventory_configsecurities_id'] = $this->fields['plugin_fusioninventory_configsecurities_id']; if ($DB->numrows($result) == 0) { $data['printers_id'] = $printer_id; $pfPrinter->add($data); } else { $pfPrinter->update($data); } $this->deleteFromDB($items_id, 1); $Import++; break; case 'NetworkEquipment': $NetworkEquipment = new NetworkEquipment(); $data["entities_id"] = $this->fields["entities_id"]; if (!empty($this->fields["name"])) { $data["name"] = $this->fields["name"]; } $data["locations_id"] = $this->fields["locations_id"]; $data["serial"] = $this->fields["serial"]; $data["otherserial"] = $this->fields["otherserial"]; $data["contact"] = $this->fields["contact"]; $data["domain"] = $this->fields["domain"]; $data["comment"] = $this->fields["comment"]; $data["is_dynamic"] = 1; // $data_Port = current($a_NetworkPorts); // $data["ip"] = $data_Port["ip"]; // $data["mac"] = $data_Port["mac"]; $NetworkEquipment_id = $NetworkEquipment->add($data); foreach ($a_NetworkPorts as $data_Port) { $data_Port['items_id'] = $NetworkEquipment_id; $data_Port['itemtype'] = $NetworkEquipment->getType(); $NetworkPort->update($data_Port); } $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment(); $_SESSION['glpi_plugins_fusinvsnmp_table'] = "glpi_plugin_fusioninventory_networkequipments"; $query = "SELECT *\n FROM `glpi_plugin_fusioninventory_networkequipments`\n WHERE `networkequipments_id`='" . $NetworkEquipment_id . "' "; $result = $DB->query($query); $data = array(); if ($DB->numrows($result) > 0) { $data = $DB->fetch_assoc($result); } $data['sysdescr'] = $this->fields['sysdescr']; $data['plugin_fusioninventory_configsecurities_id'] = $this->fields['plugin_fusioninventory_configsecurities_id']; if ($DB->numrows($result) == 0) { $data['networkequipments_id'] = $NetworkEquipment_id; $pfNetworkEquipment->add($data); } else { $pfNetworkEquipment->update($data); } $this->deleteFromDB($items_id, 1); $Import++; break; case 'Peripheral': $Peripheral = new Peripheral(); $data["entities_id"] = $this->fields["entities_id"]; if (!empty($this->fields["name"])) { $data["name"] = $this->fields["name"]; } $data["locations_id"] = $this->fields["locations_id"]; $data["serial"] = $this->fields["serial"]; $data["otherserial"] = $this->fields["otherserial"]; $data["contact"] = $this->fields["contact"]; $data["comment"] = $this->fields["comment"]; $data["is_dynamic"] = 1; $Peripheral_id = $Peripheral->add($data); foreach ($a_NetworkPorts as $data_Port) { $data_Port['items_id'] = $Peripheral_id; $data_Port['itemtype'] = $Peripheral->getType(); $NetworkPort->update($data_Port); } $this->deleteFromDB($items_id, 1); $Import++; break; case 'Computer': $Computer = new Computer(); $data["entities_id"] = $this->fields["entities_id"]; if (!empty($this->fields["name"])) { $data["name"] = $this->fields["name"]; } $data["locations_id"] = $this->fields["locations_id"]; $data["serial"] = $this->fields["serial"]; $data["otherserial"] = $this->fields["otherserial"]; $data["contact"] = $this->fields["contact"]; $data["domain"] = $this->fields["domain"]; $data["comment"] = $this->fields["comment"]; $data["is_dynamic"] = 1; $Computer_id = $Computer->add($data); foreach ($a_NetworkPorts as $data_Port) { $data_Port['items_id'] = $Computer_id; $data_Port['itemtype'] = $Computer->getType(); $NetworkPort->update($data_Port); } $this->deleteFromDB($items_id, 1); $Import++; break; case 'Phone': $Phone = new Phone(); $data["entities_id"] = $this->fields["entities_id"]; $data["name"] = $this->fields["name"]; $data["locations_id"] = $this->fields["locations_id"]; $data["serial"] = $this->fields["serial"]; $data["otherserial"] = $this->fields["otherserial"]; $data["contact"] = $this->fields["contact"]; $data["comment"] = $this->fields["comment"]; $data["is_dynamic"] = 1; $phone_id = $Phone->add($data); foreach ($a_NetworkPorts as $data_Port) { $data_Port['items_id'] = $phone_id; $data_Port['itemtype'] = $Phone->getType(); $NetworkPort->update($data_Port); } $this->deleteFromDB($items_id, 1); $Import++; break; default: $NoImport++; break; } return array($Import, $NoImport); }
Copyright (C) 2003-2013 by the INDEPNET Development Team. http://indepnet.net/ http://glpi-project.org ------------------------------------------------------------------------- LICENSE This file is part of GLPI. GLPI is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkRight("networking", "r"); Html::header(NetworkEquipment::getTypeName(2), $_SERVER['PHP_SELF'], "inventory", "networking"); Search::show('NetworkEquipment'); Html::footer();
/** * Get search function for the class * * @since version 0.85 * * @return array of search option **/ function getSearchOptions() { $tab = parent::getSearchOptions(); $tab[21]['table'] = $this->getTable(); $tab[21]['field'] = 'is_visible_computer'; $tab[21]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Computer::getTypeName(Session::getPluralNumber())); $tab[21]['datatype'] = 'bool'; $tab[22]['table'] = $this->getTable(); $tab[22]['field'] = 'is_visible_softwareversion'; $tab[22]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), SoftwareVersion::getTypeName(Session::getPluralNumber())); $tab[22]['datatype'] = 'bool'; $tab[23]['table'] = $this->getTable(); $tab[23]['field'] = 'is_visible_monitor'; $tab[23]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Monitor::getTypeName(Session::getPluralNumber())); $tab[23]['datatype'] = 'bool'; $tab[24]['table'] = $this->getTable(); $tab[24]['field'] = 'is_visible_printer'; $tab[24]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Printer::getTypeName(Session::getPluralNumber())); $tab[24]['datatype'] = 'bool'; $tab[25]['table'] = $this->getTable(); $tab[25]['field'] = 'is_visible_peripheral'; $tab[25]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Peripheral::getTypeName(Session::getPluralNumber())); $tab[25]['datatype'] = 'bool'; $tab[26]['table'] = $this->getTable(); $tab[26]['field'] = 'is_visible_phone'; $tab[26]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Phone::getTypeName(Session::getPluralNumber())); $tab[26]['datatype'] = 'bool'; $tab[27]['table'] = $this->getTable(); $tab[27]['field'] = 'is_visible_networkequipment'; $tab[27]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), NetworkEquipment::getTypeName(Session::getPluralNumber())); $tab[27]['datatype'] = 'bool'; return $tab; }
static function dropdownService($ID, $options = array()) { global $CFG_GLPI; $p = array(); $p['name'] = 'networkports_id'; $p['comments'] = 1; $p['entity'] = -1; $p['entity_sons'] = false; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } // Manage entity_sons if (!($p['entity'] < 0) && $p['entity_sons']) { if (is_array($p['entity'])) { echo "entity_sons options is not available with array of entity"; } else { $p['entity'] = getSonsOf('glpi_entities', $p['entity']); } } $rand = mt_rand(); echo "<select name='itemtype[{$ID}]' id='itemtype{$rand}'>"; echo "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option>"; // $a_types =array(); echo "<option value='Computer'>" . Computer::getTypeName() . "</option>"; echo "<option value='NetworkEquipment'>" . NetworkEquipment::getTypeName() . "</option>"; echo "</select>"; $params = array('itemtype' => '__VALUE__', 'entity_restrict' => $p['entity'], 'current' => $ID, 'comments' => $p['comments'], 'myname' => $p['name'], 'rand' => $rand); ajaxUpdateItemOnSelectEvent("itemtype{$rand}", "show_" . $p['name'] . "{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownServiceHostType.php", $params); echo "<span id='show_" . $p['name'] . "{$rand}'><input type='hidden' name='services_id[]' value='0'/></span>\n"; return $rand; }
/** * Return the instance fields of itemtype identified by id * * @param $itemtype string itemtype (class) of object * @param $id integer identifier of object * @param $params array with theses options : * - 'expand_dropdowns': Show dropdown's names instead of id. default: false. Optionnal * - 'get_hateoas': Show relation of current item in a links attribute. default: true. Optionnal * - 'get_sha1': Get a sha1 signature instead of the full answer. default: false. Optionnal * - 'with_components': Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], Optionnal. * - 'with_disks': Only for Computer, retrieve the associated filesystems. Optionnal. * - 'with_softwares': Only for Computer, retrieve the associated softwares installations. Optionnal. * - 'with_connections': Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optionnal. * - 'with_networkports':Retrieve all network connections and advanced network informations. Optionnal. * - 'with_infocoms': Retrieve financial and administrative informations. Optionnal. * - 'with_contracts': Retrieve associated contracts. Optionnal. * - 'with_documents': Retrieve associated external documents. Optionnal. * - 'with_tickets': Retrieve associated itil tickets. Optionnal. * - 'with_problems': Retrieve associated itil problems. Optionnal. * - 'with_changes': Retrieve associated itil changes. Optionnal. * - 'with_notes': Retrieve Notes (if exists, not all itemtypes have notes). Optionnal. * - 'with_logs': Retrieve historical. Optionnal. * * @return array fields of found object **/ protected function getItem($itemtype, $id, $params = array()) { global $CFG_GLPI, $DB; $this->initEndpoint(); // default params $default = array('expand_dropdowns' => false, 'get_hateoas' => true, 'get_sha1' => false, 'with_components' => false, 'with_disks' => false, 'with_softwares' => false, 'with_connections' => false, 'with_networkports' => false, 'with_infocoms' => false, 'with_contracts' => false, 'with_documents' => false, 'with_tickets' => false, 'with_problems' => false, 'with_changes' => false, 'with_notes' => false, 'with_logs' => false); $params = array_merge($default, $params); $item = new $itemtype(); if (!$item->getFromDB($id)) { return $this->messageNotfoundError(); } if (!$item->can($id, READ)) { return $this->messageRightError(); } $fields = $item->fields; // avoid disclosure of critical fields $item::unsetUndisclosedFields($fields); // retrieve devices if (isset($params['with_devices']) && $params['with_devices'] && in_array($itemtype, Item_Devices::getConcernedItems())) { $all_devices = array(); foreach (Item_Devices::getItemAffinities($item->getType()) as $device_type) { $found_devices = getAllDatasFromTable($device_type::getTable(), "`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'\n AND `is_deleted` = '0'", true); foreach ($found_devices as $devices_id => &$device) { unset($device['items_id']); unset($device['itemtype']); unset($device['is_deleted']); } if (!empty($found_devices)) { $all_devices[$device_type] = $found_devices; } } $fields['_devices'] = $all_devices; } // retrieve computer disks if (isset($params['with_disks']) && $params['with_disks'] && $itemtype == "Computer") { // build query to retrive filesystems $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n `glpi_computerdisks`.*\n FROM `glpi_computerdisks`\n LEFT JOIN `glpi_filesystems`\n ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n WHERE `computers_id` = '{$id}'\n AND `is_deleted` = '0'"; $fields['_disks'] = array(); if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { unset($data['computers_id']); unset($data['is_deleted']); $fields['_disks'][] = array('name' => $data); } } } // retrieve computer softwares if (isset($params['with_softwares']) && $params['with_softwares'] && $itemtype == "Computer") { $fields['_softwares'] = array(); if (!Software::canView()) { $fields['_softwares'] = self::arrayRightError(); } else { $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n `glpi_softwares`.`id` AS softwares_id,\n `glpi_softwareversions`.`id` AS softwareversions_id,\n `glpi_computers_softwareversions`.`is_dynamic`,\n `glpi_softwareversions`.`states_id`,\n `glpi_softwares`.`is_valid`\n FROM `glpi_computers_softwareversions`\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n LEFT JOIN `glpi_softwares`\n ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n WHERE `glpi_computers_softwareversions`.`computers_id` = '{$id}'\n AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n ORDER BY `glpi_softwares`.`name`, `glpi_softwareversions`.`name`"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_softwares'][] = $data; } } } } // retrieve item connections if (isset($params['with_connections']) && $params['with_connections'] && $itemtype == "Computer") { $fields['_connections'] = array(); foreach ($CFG_GLPI["directconnect_types"] as $connect_type) { $connect_item = new $connect_type(); if ($connect_item->canView()) { $query = "SELECT `glpi_computers_items`.`id` AS assoc_id,\n `glpi_computers_items`.`computers_id` AS assoc_computers_id,\n `glpi_computers_items`.`itemtype` AS assoc_itemtype,\n `glpi_computers_items`.`items_id` AS assoc_items_id,\n `glpi_computers_items`.`is_dynamic` AS assoc_is_dynamic,\n " . getTableForItemType($connect_type) . ".*\n FROM `glpi_computers_items`\n LEFT JOIN `" . getTableForItemType($connect_type) . "`\n ON (`" . getTableForItemType($connect_type) . "`.`id`\n = `glpi_computers_items`.`items_id`)\n WHERE `computers_id` = '{$id}'\n AND `itemtype` = '" . $connect_type . "'\n AND `glpi_computers_items`.`is_deleted` = '0'"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_connections'][$connect_type][] = $data; } } } } } // retrieve item networkports if (isset($params['with_networkports']) && $params['with_networkports']) { $fields['_networkports'] = array(); if (!NetworkEquipment::canView()) { $fields['_networkports'] = self::arrayRightError(); } else { foreach (NetworkPort::getNetworkPortInstantiations() as $networkport_type) { $netport_table = $networkport_type::getTable(); $query = "SELECT\n netp.`id` as netport_id,\n netp.`entities_id`,\n netp.`is_recursive`,\n netp.`logical_number`,\n netp.`name`,\n netp.`mac`,\n netp.`comment`,\n netp.`is_dynamic`,\n netp_subtable.*\n FROM glpi_networkports AS netp\n LEFT JOIN `{$netport_table}` AS netp_subtable\n ON netp_subtable.`networkports_id` = netp.`id`\n WHERE netp.`instantiation_type` = '{$networkport_type}'\n AND netp.`items_id` = '{$id}'\n AND netp.`itemtype` = '{$itemtype}'\n AND netp.`is_deleted` = '0'"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { if (isset($data['netport_id'])) { // append network name $query_netn = "SELECT\n GROUP_CONCAT(CONCAT(ipadr.`id`, '" . Search::SHORTSEP . "' , ipadr.`name`)\n SEPARATOR '" . Search::LONGSEP . "') as ipadresses,\n netn.`id` as networknames_id,\n netn.`name` as networkname,\n netn.`fqdns_id`,\n fqdn.`name` as fqdn_name,\n fqdn.`fqdn`\n FROM `glpi_networknames` AS netn\n LEFT JOIN `glpi_ipaddresses` AS ipadr\n ON ipadr.`itemtype` = 'NetworkName' AND ipadr.`items_id` = netn.`id`\n LEFT JOIN `glpi_fqdns` AS fqdn\n ON fqdn.`id` = netn.`fqdns_id`\n LEFT JOIN `glpi_ipaddresses_ipnetworks` ipadnet\n ON ipadnet.`ipaddresses_id` = ipadr.`id`\n LEFT JOIN `glpi_ipnetworks` `ipnet`\n ON ipnet.`id` = ipadnet.`ipnetworks_id`\n WHERE netn.`itemtype` = 'NetworkPort'\n AND netn.`items_id` = " . $data['netport_id'] . "\n GROUP BY netn.`id`, netn.`name`, netn.fqdns_id, fqdn.name, fqdn.fqdn"; if ($result_netn = $DB->query($query_netn)) { $data_netn = $DB->fetch_assoc($result_netn); $raw_ipadresses = explode(Search::LONGSEP, $data_netn['ipadresses']); $ipadresses = array(); foreach ($raw_ipadresses as $ipadress) { $ipadress = explode(Search::SHORTSEP, $ipadress); //find ip network attached to these ip $ipnetworks = array(); $query_ipnet = "SELECT\n ipnet.`id`,\n ipnet.`completename`,\n ipnet.`name`,\n ipnet.`address`,\n ipnet.`netmask`,\n ipnet.`gateway`,\n ipnet.`ipnetworks_id`,\n ipnet.`comment`\n FROM `glpi_ipnetworks` ipnet\n INNER JOIN `glpi_ipaddresses_ipnetworks` ipadnet\n ON ipnet.`id` = ipadnet.`ipnetworks_id`\n AND ipadnet.`ipaddresses_id` = " . $ipadress[0]; if ($result_ipnet = $DB->query($query_ipnet)) { while ($data_ipnet = $DB->fetch_assoc($result_ipnet)) { $ipnetworks[] = $data_ipnet; } } $ipadresses[] = array('id' => $ipadress[0], 'name' => $ipadress[1], 'IPNetwork' => $ipnetworks); } $data['NetworkName'] = array('id' => $data_netn['networknames_id'], 'name' => $data_netn['networkname'], 'fqdns_id' => $data_netn['fqdns_id'], 'FQDN' => array('id' => $data_netn['fqdns_id'], 'name' => $data_netn['fqdn_name'], 'fqdn' => $data_netn['fqdn']), 'IPAddress' => $ipadresses); } } $fields['_networkports'][$networkport_type][] = $data; } } } } } // retrieve item infocoms if (isset($params['with_infocoms']) && $params['with_infocoms']) { $fields['_infocoms'] = array(); if (!Infocom::canView()) { $fields['_infocoms'] = self::arrayRightError(); } else { $ic = new Infocom(); if ($ic->getFromDBforDevice($itemtype, $id)) { $fields['_infocoms'] = $ic->fields; } } } // retrieve item contracts if (isset($params['with_contracts']) && $params['with_contracts']) { $fields['_contracts'] = array(); if (!Contract::canView()) { $fields['_contracts'] = self::arrayRightError(); } else { $query = "SELECT `glpi_contracts_items`.*\n FROM `glpi_contracts_items`,\n `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n AND `glpi_contracts_items`.`items_id` = '{$id}'\n AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_contracts`.`name`"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_contracts'][] = $data; } } } } // retrieve item contracts if (isset($params['with_documents']) && $params['with_documents']) { $fields['_documents'] = array(); if (!$itemtype != 'Ticket' && $itemtype != 'KnowbaseItem' && $itemtype != 'Reminder' && !Document::canView()) { $fields['_documents'] = self::arrayRightError(); } else { $query = "SELECT `glpi_documents_items`.`id` AS assocID,\n `glpi_documents_items`.`date_mod` AS assocdate,\n `glpi_entities`.`id` AS entityID,\n `glpi_entities`.`completename` AS entity,\n `glpi_documentcategories`.`completename` AS headings,\n `glpi_documents`.*\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_documents`\n ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n LEFT JOIN `glpi_documentcategories`\n ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n WHERE `glpi_documents_items`.`items_id` = '{$id}'\n AND `glpi_documents_items`.`itemtype` = '{$itemtype}' "; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_documents'][] = $data; } } } } // retrieve item tickets if (isset($params['with_tickets']) && $params['with_tickets']) { $fields['_tickets'] = array(); if (!Ticket::canView()) { $fields['_tickets'] = self::arrayRightError(); } else { $query = "SELECT " . Ticket::getCommonSelect() . "\n FROM `glpi_tickets` " . Ticket::getCommonLeftJoin() . "\n WHERE `glpi_items_tickets`.`items_id` = '{$id}'\n AND `glpi_items_tickets`.`itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n ORDER BY `glpi_tickets`.`date_mod` DESC"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_tickets'][] = $data; } } } } // retrieve item problems if (isset($params['with_problems']) && $params['with_problems']) { $fields['_problems'] = array(); if (!Problem::canView()) { $fields['_problems'] = self::arrayRightError(); } else { $query = "SELECT " . Problem::getCommonSelect() . "\n FROM `glpi_problems`\n LEFT JOIN `glpi_items_problems`\n ON (`glpi_problems`.`id` = `glpi_items_problems`.`problems_id`) " . Problem::getCommonLeftJoin() . "\n WHERE `items_id` = '{$id}'\n AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_problems") . "\n ORDER BY `glpi_problems`.`date_mod` DESC"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_problems'][] = $data; } } } } // retrieve item changes if (isset($params['with_changes']) && $params['with_changes']) { $fields['_changes'] = array(); if (!Change::canView()) { $fields['_changes'] = self::arrayRightError(); } else { $query = "SELECT " . Change::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`problems_id`) " . Change::getCommonLeftJoin() . "\n WHERE `items_id` = '{$id}'\n AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n ORDER BY `glpi_changes`.`date_mod` DESC"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_changes'][] = $data; } } } } // retrieve item notes if (isset($params['with_notes']) && $params['with_notes']) { $fields['_notes'] = array(); if (!Session::haveRight($itemtype::$rightname, READNOTE)) { $fields['_notes'] = self::arrayRightError(); } else { $fields['_notes'] = Notepad::getAllForItem($item); } } // retrieve item logs if (isset($params['with_logs']) && $params['with_logs']) { $fields['_logs'] = array(); if (!Session::haveRight($itemtype::$rightname, READNOTE)) { $fields['_logs'] = self::arrayRightError(); } else { $fields['_logs'] = getAllDatasFromTable("glpi_logs", "`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'"); } } // expand dropdown (retrieve name of dropdowns) and get hateoas from foreign keys $fields = self::parseDropdowns($fields, $params); // get hateoas from children if ($params['get_hateoas']) { $hclasses = self::getHatoasClasses($itemtype); foreach ($hclasses as $hclass) { $fields['links'][] = array('rel' => $hclass, 'href' => self::$api_url . "/{$itemtype}/" . $item->getID() . "/{$hclass}/"); } } // get sha1 footprint if needed if ($params['get_sha1']) { $fields = sha1(json_encode($fields, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK)); } return $fields; }
function generateHostsCfg($file=0, $tag='') { global $DB; // Log Shinken restart event with Tag information ... $pmLog = new PluginMonitoringLog(); if (isset($_SERVER['HTTP_USER_AGENT']) AND strstr($_SERVER['HTTP_USER_AGENT'], 'xmlrpclib.py')) { if (!isset($_SESSION['glpi_currenttime'])) { $_SESSION['glpi_currenttime'] = date("Y-m-d H:i:s"); } $input = array(); $input['user_name'] = "Shinken"; $input['action'] = "restart"; $input['date_mod'] = date("Y-m-d H:i:s"); $input['value'] = $tag; $pmLog->add($input); } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Starting generateHostsCfg ($tag) ...\n" ); $pmCommand = new PluginMonitoringCommand(); $pmCheck = new PluginMonitoringCheck(); $pmComponent = new PluginMonitoringComponent(); $pmEntity = new PluginMonitoringEntity(); $pmHostconfig = new PluginMonitoringHostconfig(); $pmHost = new PluginMonitoringHost(); $calendar = new Calendar(); $pmRealm = new PluginMonitoringRealm(); $networkEquipment = new NetworkEquipment(); $pmContact_Item = new PluginMonitoringContact_Item(); $profile_User = new Profile_User(); $pmEventhandler = new PluginMonitoringEventhandler(); $user = new User(); $a_hosts = array(); $i=0; $a_parents_found = array(); $a_hosts_found = array(); $a_entities_allowed = $pmEntity->getEntitiesByTag($tag); $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_entities", '', $a_entities_list); } // * Prepare 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; } // $query = "SELECT * // FROM `glpi_plugin_monitoring_componentscatalogs_hosts` // GROUP BY `itemtype`, `items_id`"; $query = "SELECT `glpi_plugin_monitoring_componentscatalogs_hosts`.*, `glpi_computers`.`id`, `glpi_entities`.`id` AS entityId, `glpi_entities`.`name` AS entityName, `glpi_entities`.`completename` AS entityFullName, `glpi_locations`.`id`, `glpi_locations`.`completename` AS locationName, `glpi_locations`.`comment` AS locationComment, `glpi_locations`.`building` AS locationGPS, `glpi_plugin_monitoring_services`.`networkports_id` FROM `glpi_plugin_monitoring_componentscatalogs_hosts` LEFT JOIN `glpi_computers` ON `glpi_computers`.`id` = `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id` LEFT JOIN `glpi_entities` ON `glpi_computers`.`entities_id` = `glpi_entities`.`id` LEFT JOIN `glpi_locations` ON `glpi_locations`.`id` = `glpi_computers`.`locations_id` LEFT JOIN `glpi_plugin_monitoring_services` ON `glpi_plugin_monitoring_services`.`plugin_monitoring_componentscatalogs_hosts_id` = `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` $where GROUP BY `itemtype`, `items_id`"; PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Hosts: $query\n" ); $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { // Toolbox::logInFile("pm-shinken", " - fetch host ".$data['itemtype']." / ".$data['items_id']."\n"); $classname = $data['itemtype']; $class = new $classname; if ($class->getFromDB($data['items_id'])) { // if (isset($a_entities_allowed['-1']) // OR isset($a_entities_allowed[$class->fields['entities_id']])) { $pmHost->getFromDBByQuery("WHERE `glpi_plugin_monitoring_hosts`.`itemtype` = '" . $data['itemtype'] . "' AND `glpi_plugin_monitoring_hosts`.`items_id` = '" . $data['items_id'] . "' LIMIT 1"); $a_hosts[$i]['host_name'] = preg_replace("/[^A-Za-z0-9\-_]/","",$class->fields['name']); // Fix if hostname is not defined ... if (empty($a_hosts[$i]['host_name'])) { continue; } $a_hosts_found[$a_hosts[$i]['host_name']] = 1; PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - add host ".$a_hosts[$i]['host_name']."\n" ); $a_hosts[$i]['_HOSTID'] = $pmHost->getField('id'); if (isset(self::$shinkenParameters['glpi']['entityId'])) { $a_hosts[$i][self::$shinkenParameters['glpi']['entityId']] = $data['entityId']; } if (isset(self::$shinkenParameters['glpi']['itemType'])) { $a_hosts[$i][self::$shinkenParameters['glpi']['itemType']] = $classname; } if (isset(self::$shinkenParameters['glpi']['itemId'])) { $a_hosts[$i][self::$shinkenParameters['glpi']['itemId']] = $data['items_id']; } if (isset(self::$shinkenParameters['glpi']['entityName'])) { $a_hosts[$i][self::$shinkenParameters['glpi']['entityName']] = strtolower(preg_replace("/[^A-Za-z0-9\-_]/","",$data['entityName'])); } $data['entityFullName'] = preg_replace("/ > /","#",$data['entityFullName']); $data['entityFullName'] = preg_replace("/". self::$shinkenParameters['glpi']['rootEntity'] ."#/","",$data['entityFullName']); $data['entityFullName'] = preg_replace("/#/","_",$data['entityFullName']); if (isset(self::$shinkenParameters['glpi']['entityComplete'])) { $a_hosts[$i][self::$shinkenParameters['glpi']['entityComplete']] = strtolower(preg_replace("/[^A-Za-z0-9\-_]/","",$data['entityFullName'])); } $data['entityFullName'] = preg_replace("/_/",".",$data['entityFullName']); if (isset(self::$shinkenParameters['glpi']['location'])) { if (! empty($data['locationName'])) { // Toolbox::logInFile("pm-shinken", " - location: ".$data['locationName']."\n"); $string = utf8_decode(strip_tags(trim($data['locationName']))); // $string = Toolbox::decodeFromUtf8($data['locationName']); $string = preg_replace("/[\r\n]/",".",$data['locationName']); $string = preg_replace("/[^A-Za-z0-9\-_ <>\',;.:!?%*()éèà ù]/",'',$string); // Toolbox::logInFile("pm-shinken", " - location: ".$string."\n"); $a_hosts[$i][self::$shinkenParameters['glpi']['location']] = $string; } } if (isset(self::$shinkenParameters['graphite']['prefix']['name'])) { $a_hosts[$i][self::$shinkenParameters['graphite']['prefix']['name']] = strtolower(self::$shinkenParameters['graphite']['prefix']['value'] . preg_replace("/[^A-Za-z0-9\-_.]/","",$data['entityFullName'])); } if (isset(self::$shinkenParameters['glpi']['lat'])) { if (! empty($data['locationGPS'])) { $split = explode(',', $data['locationGPS']); if (count($split) > 2) { // At least 3 elements, let us consider as GPS coordinates with altitude ... $a_hosts[$i][self::$shinkenParameters['glpi']['lat']] = $split[0]; $a_hosts[$i][self::$shinkenParameters['glpi']['lng']] = $split[1]; $a_hosts[$i][self::$shinkenParameters['glpi']['alt']] = $split[2]; } else if (count($split) > 1) { // At least 2 elements, let us consider as GPS coordinates ... $a_hosts[$i][self::$shinkenParameters['glpi']['lat']] = $split[0]; $a_hosts[$i][self::$shinkenParameters['glpi']['lng']] = $split[1]; // } else { // $a_hosts[$i]['_LOC_BUILDING'] = preg_replace("/[\r\n]/",".",$data['locationGPS']); // $a_hosts[$i]['_LOC_BUILDING'] = preg_replace("/[^A-Za-z0-9\-_]/"," / ",$a_hosts[$i]['_LOC_BUILDING']); } } } // Hostgroup name $a_hosts[$i]['hostgroups'] = strtolower(preg_replace("/[^A-Za-z0-9\-_ ]/","",$data['entityName'])); $a_hosts[$i]['hostgroups'] = preg_replace("/[ ]/","_",$a_hosts[$i]['hostgroups']); // Alias $a_hosts[$i]['alias'] = $data['entityName']." / ". $a_hosts[$i]['host_name']; if (isset($class->fields['networkequipmenttypes_id'])) { if ($class->fields['networkequipmenttypes_id'] > 0) { $a_hosts[$i]['alias'] .= " (".Dropdown::getDropdownName("glpi_networkequipmenttypes", $class->fields['networkequipmenttypes_id']).")"; } } else if (isset($class->fields['computertypes_id'])) { if ($class->fields['computertypes_id'] > 0) { $a_hosts[$i]['alias'] .= " (".Dropdown::getDropdownName("glpi_computertypes", $class->fields['computertypes_id']).")"; } } else if (isset($class->fields['printertypes_id'])) { if ($class->fields['printertypes_id'] > 0) { $a_hosts[$i]['alias'] .= " (".Dropdown::getDropdownName("glpi_printertypes", $class->fields['printertypes_id']).")"; } } // WebUI user interface ... if (isset(self::$shinkenParameters['webui']['hostIcons']['name'])) { $a_hosts[$i][self::$shinkenParameters['webui']['hostIcons']['name']] = self::$shinkenParameters['webui']['hostIcons']['value']; } if (isset(self::$shinkenParameters['webui']['hostView']['name'])) { $a_hosts[$i][self::$shinkenParameters['webui']['hostView']['name']] = self::$shinkenParameters['webui']['hostView']['value']; } // IP address $ip = PluginMonitoringHostaddress::getIp($data['items_id'], $data['itemtype'], $class->fields['name']); $a_hosts[$i]['address'] = $ip; // Manage dependencies $parent = ''; if ($data['itemtype'] != 'NetworkEquipment') { $networkPort = new NetworkPort(); $a_networkports = $networkPort->find("`itemtype`='".$data['itemtype']."' AND `items_id`='".$data['items_id']."'"); foreach ($a_networkports as $data_n) { $networkports_id = $networkPort->getContact($data_n['id']); if ($networkports_id) { $networkPort->getFromDB($networkports_id); if ($networkPort->fields['itemtype'] == 'NetworkEquipment') { $networkEquipment->getFromDB($networkPort->fields['items_id']); $parent = preg_replace("/[^A-Za-z0-9\-_]/","",$networkEquipment->fields['name']); $a_parents_found[$parent] = 1; $pmHost->updateDependencies($classname, $data['items_id'], 'NetworkEquipment-'.$networkPort->fields['items_id']); } } } if (empty($parent)) { if (self::$shinkenParameters['shinken']['hosts']['parents'] == 'entity') { $parent = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . $a_hosts[$i]['hostgroups']; } else { $parent = self::$shinkenParameters['shinken']['hosts']['parents']; } } } $a_hosts[$i]['parents'] = $parent; $a_fields = array(); $pmComponent->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_components_id', $class->fields['entities_id'], $classname, $class->getID())); $pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']); $a_fields = $pmComponent->fields; // Manage host check_command arguments // Toolbox::logInFile("pm-shinken", "Command line : ".$pmCommand->fields['command_line']."\n"); // Toolbox::logInFile("pm-shinken", "Arguments : ".$a_fields['arguments']."\n"); // Toolbox::logInFile("pm-shinken", "Arguments : ".$pmCommand->fields['arguments']."\n"); $array = array(); preg_match_all("/\\$(ARG\d+)\\$/", $pmCommand->fields['command_line'], $array); sort($array[0]); $a_arguments = importArrayFromDB($pmCommand->fields['arguments']); $a_argumentscustom = importArrayFromDB($pmComponent->fields['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 ($classname == 'Computer') { // Get networkportname of networkcard defined $pmHostaddress = new PluginMonitoringHostaddress(); $a_hostaddresses = $pmHostaddress->find("`itemtype`='Computer'" . " AND `items_id`='".$class->fields['id']."'", '', 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]." Not have value"; } $args .= '!'.$a_arguments[$arg]; if ($a_arguments[$arg] == '' AND $a_component['alias_command'] != '') { $args .= $a_component['alias_command']; } } } } $a_hosts[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . $pmCommand->fields['command_name'].$args; // Toolbox::logInFile("pm", "check_command : ".$a_hosts[$i]['check_command']."\n"); $pmCheck->getFromDB($pmComponent->fields['plugin_monitoring_checks_id']); $a_hosts[$i]['check_interval'] = $pmCheck->fields['check_interval']; $a_hosts[$i]['retry_interval'] = $pmCheck->fields['retry_interval']; $a_hosts[$i]['max_check_attempts'] = $pmCheck->fields['max_check_attempts']; if ($calendar->getFromDB($pmComponent->fields['calendars_id'])) { $a_hosts[$i]['check_period'] = $calendar->fields['name']; } else { $a_hosts[$i]['check_period'] = self::$shinkenParameters['shinken']['hosts']['check_period']; } $a_hosts[$i]['active_checks_enabled'] = $a_fields['active_checks_enabled']; $a_hosts[$i]['passive_checks_enabled'] = $a_fields['passive_checks_enabled']; // Manage freshness if ($a_fields['freshness_count'] == 0) { $a_hosts[$i]['check_freshness'] = '0'; $a_hosts[$i]['freshness_threshold'] = '0'; } else { $multiple = 1; if ($a_fields['freshness_type'] == 'seconds') { $multiple = 1; } else if ($a_fields['freshness_type'] == 'minutes') { $multiple = 60; } else if ($a_fields['freshness_type'] == 'hours') { $multiple = 3600; } else if ($a_fields['freshness_type'] == 'days') { $multiple = 86400; } $a_hosts[$i]['check_freshness'] = '1'; $a_hosts[$i]['freshness_threshold'] = (string)($a_fields['freshness_count'] * $multiple); } // Manage event handler if ($a_fields['plugin_monitoring_eventhandlers_id'] > 0) { if ($a_fields->getFromDB($a_fields['plugin_monitoring_eventhandlers_id'])) { $a_hosts[$i]['event_handler'] = $pmEventhandler->fields['command_name']; } } // Realm $pmRealm->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_realms_id', $class->fields['entities_id'], $classname, $class->getID())); $a_hosts[$i]['realm'] = $pmRealm->fields['name']; if (! empty(self::$shinkenParameters['shinken']['hosts']['use'])) $a_hosts[$i]['use'] = self::$shinkenParameters['shinken']['hosts']['use']; if (! empty(self::$shinkenParameters['shinken']['hosts']['process_perf_data'])) $a_hosts[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['hosts']['process_perf_data']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_period'])) $a_hosts[$i]['notification_period'] = self::$shinkenParameters['shinken']['hosts']['notification_period']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_options'])) $a_hosts[$i]['notification_options'] = self::$shinkenParameters['shinken']['hosts']['notification_options']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_interval'])) $a_hosts[$i]['notification_interval'] = self::$shinkenParameters['shinken']['hosts']['notification_interval']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes'])) $a_hosts[$i]['notes'] = self::$shinkenParameters['shinken']['hosts']['notes']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes_url'])) $a_hosts[$i]['notes_url'] = self::$shinkenParameters['shinken']['hosts']['notes_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['action_url'])) $a_hosts[$i]['action_url'] = self::$shinkenParameters['shinken']['hosts']['action_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image'])) $a_hosts[$i]['icon_image'] = self::$shinkenParameters['shinken']['hosts']['icon_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image_alt'])) $a_hosts[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['hosts']['icon_image_alt']; if (! empty(self::$shinkenParameters['shinken']['hosts']['vrml_image'])) $a_hosts[$i]['vrml_image'] = self::$shinkenParameters['shinken']['hosts']['vrml_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['statusmap_image'])) $a_hosts[$i]['statusmap_image'] = self::$shinkenParameters['shinken']['hosts']['statusmap_image']; // For contacts, check if a component catalog contains the host associated component ... $a_hosts[$i]['contacts'] = ''; if (($a_fields['passive_checks_enabled'] == '1') and ($a_fields['active_checks_enabled'] == '0')) { // Specific query if host is only passively checked ... // Find the first component catalog in which the host is used ... $querycont = "SELECT * 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 `items_id`='".$data['items_id']."' AND `itemtype`='".$data['itemtype']."' LIMIT 1"; } else { // Find component catalog which contains the host associated component ... $querycont = "SELECT * 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_components_id`='".$pmComponent->fields['id']."' AND `items_id`='".$data['items_id']."' AND `itemtype`='".$data['itemtype']."' LIMIT 1"; } $resultcont = $DB->query($querycont); if ($DB->numrows($resultcont) != 0) { $a_componentscatalogs_hosts = $DB->fetch_assoc($resultcont); // Notification interval $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponentscatalog->getFromDB($a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']); $a_hosts[$i]['notification_interval'] = $pmComponentscatalog->fields['notification_interval']; $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog' AND `items_id`='".$a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']."'"); foreach ($a_list_contact as $data_contact) { if (isset($a_contacts_entities[$a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']][$data_contact['users_id']])) { if (in_array($class->fields['entities_id'], $a_contacts_entities[$a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } if (count($a_contacts) > 0) { $a_contacts_unique = array_unique($a_contacts); $a_hosts[$i]['contacts'] = implode(',', $a_contacts_unique); } } $i++; // } } } // Fake host for business rules PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - add host_for_bp\n" ); $a_hosts[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['bp_host']; $a_hosts[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . 'check_dummy!0'; $a_hosts[$i]['alias'] = 'Fake host for business rules'; $a_hosts[$i]['_HOSTID'] = '0'; $a_hosts[$i]['_ITEMSID'] = '0'; $a_hosts[$i]['_ITEMTYPE'] = 'Computer'; $a_hosts[$i]['address'] = '127.0.0.1'; $a_hosts[$i]['parents'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['root_parent']; $a_hosts[$i]['hostgroups'] = self::$shinkenParameters['shinken']['fake_hosts']['hostgroup_name']; $a_hosts[$i]['check_interval'] = '60'; $a_hosts[$i]['retry_interval'] = '1'; $a_hosts[$i]['max_check_attempts'] = '1'; $a_hosts[$i]['check_period'] = '24x7'; if (self::$shinkenParameters['shinken']['fake_contacts']['build']) { $a_hosts[$i]['contacts'] = self::$shinkenParameters['shinken']['fake_contacts']['contact_name']; } else { $a_hosts[$i]['contacts'] = ''; } if (! empty(self::$shinkenParameters['shinken']['fake_hosts']['use'])) $a_hosts[$i]['use'] = self::$shinkenParameters['shinken']['fake_hosts']['use']; if (! empty(self::$shinkenParameters['shinken']['hosts']['process_perf_data'])) $a_hosts[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['hosts']['process_perf_data']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_period'])) $a_hosts[$i]['notification_period'] = self::$shinkenParameters['shinken']['hosts']['notification_period']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_options'])) $a_hosts[$i]['notification_options'] = self::$shinkenParameters['shinken']['hosts']['notification_options']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_interval'])) $a_hosts[$i]['notification_interval'] = self::$shinkenParameters['shinken']['hosts']['notification_interval']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes'])) $a_hosts[$i]['notes'] = self::$shinkenParameters['shinken']['hosts']['notes']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes_url'])) $a_hosts[$i]['notes_url'] = self::$shinkenParameters['shinken']['hosts']['notes_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['action_url'])) $a_hosts[$i]['action_url'] = self::$shinkenParameters['shinken']['hosts']['action_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image'])) $a_hosts[$i]['icon_image'] = self::$shinkenParameters['shinken']['hosts']['icon_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image_alt'])) $a_hosts[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['hosts']['icon_image_alt']; if (! empty(self::$shinkenParameters['shinken']['hosts']['vrml_image'])) $a_hosts[$i]['vrml_image'] = self::$shinkenParameters['shinken']['hosts']['vrml_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['statusmap_image'])) $a_hosts[$i]['statusmap_image'] = self::$shinkenParameters['shinken']['hosts']['statusmap_image']; $i++; // Add one fake host for each entity if (self::$shinkenParameters['shinken']['fake_hosts']['build']) { PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - add fake hosts for parents relationship\n" ); // Main root parent $a_hosts[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['root_parent']; $a_hosts[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . 'check_dummy!0'; $a_hosts[$i]['alias'] = 'Main root parent'; $a_hosts[$i]['_HOSTID'] = '0'; $a_hosts[$i]['_ITEMSID'] = '0'; $a_hosts[$i]['_ITEMTYPE'] = 'Computer'; $a_hosts[$i]['address'] = '127.0.0.1'; $a_hosts[$i]['parents'] = ''; $a_hosts[$i]['hostgroups'] = self::$shinkenParameters['shinken']['fake_hosts']['hostgroup_name']; $a_hosts[$i]['check_interval'] = '60'; $a_hosts[$i]['retry_interval'] = '1'; $a_hosts[$i]['max_check_attempts'] = '1'; $a_hosts[$i]['check_period'] = '24x7'; if (self::$shinkenParameters['shinken']['fake_contacts']['build']) { $a_hosts[$i]['contacts'] = self::$shinkenParameters['shinken']['fake_contacts']['contact_name']; } else { $a_hosts[$i]['contacts'] = ''; } if (! empty(self::$shinkenParameters['shinken']['fake_hosts']['use'])) $a_hosts[$i]['use'] = self::$shinkenParameters['shinken']['fake_hosts']['use']; if (! empty(self::$shinkenParameters['shinken']['hosts']['process_perf_data'])) $a_hosts[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['hosts']['process_perf_data']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_period'])) $a_hosts[$i]['notification_period'] = self::$shinkenParameters['shinken']['hosts']['notification_period']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_options'])) $a_hosts[$i]['notification_options'] = self::$shinkenParameters['shinken']['hosts']['notification_options']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_interval'])) $a_hosts[$i]['notification_interval'] = self::$shinkenParameters['shinken']['hosts']['notification_interval']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes'])) $a_hosts[$i]['notes'] = self::$shinkenParameters['shinken']['hosts']['notes']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes_url'])) $a_hosts[$i]['notes_url'] = self::$shinkenParameters['shinken']['hosts']['notes_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['action_url'])) $a_hosts[$i]['action_url'] = self::$shinkenParameters['shinken']['hosts']['action_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image'])) $a_hosts[$i]['icon_image'] = self::$shinkenParameters['shinken']['hosts']['icon_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image_alt'])) $a_hosts[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['hosts']['icon_image_alt']; if (! empty(self::$shinkenParameters['shinken']['hosts']['vrml_image'])) $a_hosts[$i]['vrml_image'] = self::$shinkenParameters['shinken']['hosts']['vrml_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['statusmap_image'])) $a_hosts[$i]['statusmap_image'] = self::$shinkenParameters['shinken']['hosts']['statusmap_image']; $i++; $a_entities_allowed = $pmEntity->getEntitiesByTag($tag); $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_entities", '', $a_entities_list); } $query = "SELECT `glpi_entities`.`id` AS entityId, `glpi_entities`.`name` AS entityName FROM `glpi_entities` $where"; $result = $DB->query($query); while ($dataEntity=$DB->fetch_array($result)) { // Hostgroup name : used as host name for parents ... $fake_host_name = strtolower(preg_replace("/[^A-Za-z0-9\-_ ]/","",$dataEntity['entityName'])); $fake_host_name = preg_replace("/[ ]/","_",$fake_host_name); $a_hosts[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . $fake_host_name; $a_hosts[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . 'check_dummy!0'; $a_hosts[$i]['alias'] = $dataEntity['entityName']; $a_hosts[$i]['_HOSTID'] = '0'; $a_hosts[$i]['_ITEMSID'] = '0'; $a_hosts[$i]['_ITEMTYPE'] = 'Computer'; $a_hosts[$i]['address'] = '127.0.0.1'; $a_hosts[$i]['parents'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['root_parent']; $a_hosts[$i]['hostgroups'] = self::$shinkenParameters['shinken']['fake_hosts']['hostgroup_name']; $a_hosts[$i]['check_interval'] = '60'; $a_hosts[$i]['retry_interval'] = '1'; $a_hosts[$i]['max_check_attempts'] = '1'; $a_hosts[$i]['check_period'] = '24x7'; if (self::$shinkenParameters['shinken']['fake_contacts']['build']) { $a_hosts[$i]['contacts'] = self::$shinkenParameters['shinken']['fake_contacts']['contact_name']; } else { $a_hosts[$i]['contacts'] = ''; } if (! empty(self::$shinkenParameters['shinken']['fake_hosts']['use'])) $a_hosts[$i]['use'] = self::$shinkenParameters['shinken']['fake_hosts']['use']; if (! empty(self::$shinkenParameters['shinken']['hosts']['process_perf_data'])) $a_hosts[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['hosts']['process_perf_data']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_period'])) $a_hosts[$i]['notification_period'] = self::$shinkenParameters['shinken']['hosts']['notification_period']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_options'])) $a_hosts[$i]['notification_options'] = self::$shinkenParameters['shinken']['hosts']['notification_options']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_interval'])) $a_hosts[$i]['notification_interval'] = self::$shinkenParameters['shinken']['hosts']['notification_interval']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes'])) $a_hosts[$i]['notes'] = self::$shinkenParameters['shinken']['hosts']['notes']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes_url'])) $a_hosts[$i]['notes_url'] = self::$shinkenParameters['shinken']['hosts']['notes_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['action_url'])) $a_hosts[$i]['action_url'] = self::$shinkenParameters['shinken']['hosts']['action_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image'])) $a_hosts[$i]['icon_image'] = self::$shinkenParameters['shinken']['hosts']['icon_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image_alt'])) $a_hosts[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['hosts']['icon_image_alt']; if (! empty(self::$shinkenParameters['shinken']['hosts']['vrml_image'])) $a_hosts[$i]['vrml_image'] = self::$shinkenParameters['shinken']['hosts']['vrml_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['statusmap_image'])) $a_hosts[$i]['statusmap_image'] = self::$shinkenParameters['shinken']['hosts']['statusmap_image']; $i++; } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateHostgroupsCfg\n" ); } // Check if parents all exist in hosts config foreach ($a_parents_found as $host => $num) { if (!isset($a_hosts_found[$host])) { // Delete parents not added in hosts config foreach ($a_hosts as $id=>$data) { if ($data['parents'] == $host) { $a_hosts[$id]['parents'] = ''; } } } } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateHostsCfg\n" ); if ($file == "1") { $config = "# Generated by plugin monitoring for GLPI\n# on ".date("Y-m-d H:i:s")."\n\n"; foreach ($a_hosts as $data) { $config .= $this->writeFile("host", $data); } return array('hosts.cfg', $config); } else { return $a_hosts; } }
/** * @test */ public function Cisco2Switch() { global $DB; $DB->connect(); self::restore_database(); $a_lldp = array('ifdescr' => 'ge-0/0/1.0', 'logical_number' => '504', 'sysdescr' => 'Juniper Networks, Inc. ex2200-24t-4g , version 10.1R1.8 Build date: 2010-02-12 16:59:31 UTC ', 'model' => '', 'ip' => '', 'mac' => '2c:6b:f5:98:f9:70', 'name' => 'juniperswitch3'); $pfINetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib(); $networkEquipment = new NetworkEquipment(); $networkport = new NetworkPort(); $pfNetworkPort = new PluginFusioninventoryNetworkPort(); // Cisco switch $networkequipments_id = $networkEquipment->add(array('name' => 'cisco2', 'entities_id' => 0)); $networkports_id = $networkport->add(array('itemtype' => 'NetworkEquipment', 'items_id' => $networkequipments_id, 'entities_id' => 0)); // Another switch $networkequipments_other_id = $networkEquipment->add(array('name' => 'juniperswitch3', 'entities_id' => 0)); // Port ge-0/0/1.0 $networkports_other_id = $networkport->add(array('itemtype' => 'NetworkEquipment', 'items_id' => $networkequipments_other_id, 'entities_id' => 0, 'mac' => '2c:6b:f5:98:f9:70', 'logical_number' => 504)); $pfNetworkPort->add(array('networkports_id' => $networkports_other_id, 'ifdescr' => 'ge-0/0/1.0')); $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(2, count($a_networkports), 'May have 2 network ports (' . print_r($a_networkports, TRUE) . ')'); $a_ref = array('id' => 1, 'networkports_id_1' => $networkports_id, 'networkports_id_2' => $networkports_other_id); $this->assertEquals($a_ref, current($a_portslinks), 'Link port'); }
function pluginFusioninventoryUpdate($current_version, $migrationname = 'Migration') { global $DB; ini_set("max_execution_time", "0"); ini_set("memory_limit", "-1"); foreach (glob(GLPI_ROOT . '/plugins/fusioninventory/inc/*.php') as $file) { require_once $file; } $migration = new $migrationname($current_version); $prepare_task = array(); $prepare_rangeip = array(); $prepare_Config = array(); $a_plugin = plugin_version_fusioninventory(); $plugins_id = PluginFusioninventoryModule::getModuleId($a_plugin['shortname']); $migration->displayMessage("Migration Classname : " . $migrationname); $migration->displayMessage("Update of plugin FusionInventory"); /* * Check if folders are correctly created */ if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmp')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmp'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/computer')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/computer'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/printer')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/printer'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/networkequipment')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/networkequipment'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/walks')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/walks'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmpmodels')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmpmodels'); } /* * Deploy folders */ if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/files')) { rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/files', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files'); } if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/repository')) { rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/repository', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/repository'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/repository')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/repository'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/manifests')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/manifests'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/import')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/import'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/export')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/export'); } if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/upload')) { rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/upload', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload'); } if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload')) { mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload'); } /* * Rename fileparts without .gz extension (cf #1999) */ if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files')) { $gzfiles = pluginFusioninventoryFindFiles(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files', '/\\.gz$/'); foreach ($gzfiles as $file) { $fileWithoutExt = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME); rename($file, $fileWithoutExt); } } unset($gzfiles); /* * Rename tables from old version of FuionInventory (2.2.1 for example) */ $migration->renameTable("glpi_plugin_fusioninventory_rangeip", "glpi_plugin_fusioninventory_ipranges"); $migration->renameTable("glpi_plugin_fusioninventory_lock", "glpi_plugin_fusioninventory_locks"); $migration->renameTable("glpi_plugin_fusioninventory_unknown_device", "glpi_plugin_fusioninventory_unknowndevices"); $migration->renameTable("glpi_plugin_fusioninventory_config", "glpi_plugin_fusioninventory_configs"); $migration->renameTable("glpi_plugin_fusioninventory_networking_ports", "glpi_plugin_fusinvsnmp_networkports"); $migration->renameTable("glpi_plugin_fusioninventory_construct_device", "glpi_plugin_fusinvsnmp_constructdevices"); $migration->renameTable("glpi_plugin_fusioninventory_construct_mibs", "glpi_plugin_fusioninventory_snmpmodelconstructdevice_miboids"); $migration->renameTable("glpi_plugin_fusioninventory_networking", "glpi_plugin_fusioninventory_networkequipments"); $migration->renameTable("glpi_plugin_fusioninventory_networking_ifaddr", "glpi_plugin_fusinvsnmp_networkequipmentips"); $migration->renameTable("glpi_plugin_fusioninventory_printers", "glpi_plugin_fusinvsnmp_printers"); $migration->renameTable("glpi_plugin_fusioninventory_printers_cartridges", "glpi_plugin_fusinvsnmp_printercartridges"); $migration->renameTable("glpi_plugin_fusioninventory_printers_history", "glpi_plugin_fusinvsnmp_printerlogs"); $migration->renameTable("glpi_plugin_fusioninventory_model_infos", "glpi_plugin_fusioninventory_snmpmodels"); $migration->renameTable("glpi_plugin_fusioninventory_mib_networking", "glpi_plugin_fusinvsnmp_modelmibs"); $migration->renameTable("glpi_plugin_fusioninventory_snmp_connection", "glpi_plugin_fusinvsnmp_configsecurities"); $migration->renameTable("glpi_plugin_fusioninventory_snmp_history", "glpi_plugin_fusinvsnmp_networkportlogs"); $migration->renameTable("glpi_plugin_fusioninventory_snmp_history_connections", "glpi_plugin_fusinvsnmp_networkportconnectionlogs"); $a_droptable = array('glpi_plugin_fusioninventory_agents_inventory_state', 'glpi_plugin_fusioninventory_config_modules', 'glpi_plugin_fusioninventory_connection_stats', 'glpi_plugin_fusioninventory_discovery', 'glpi_plugin_fusioninventory_errors', 'glpi_plugin_fusioninventory_lockable', 'glpi_plugin_fusioninventory_connection_history', 'glpi_plugin_fusioninventory_walks', 'glpi_plugin_fusioninventory_config_snmp_history', 'glpi_plugin_fusioninventory_config_snmp_networking', 'glpi_plugin_fusioninventory_task', 'glpi_plugin_fusinvinventory_pcidevices', 'glpi_plugin_fusinvinventory_pcivendors', 'glpi_plugin_fusinvinventory_usbdevices', 'glpi_plugin_fusinvinventory_usbvendors', 'glpi_plugin_fusinvsnmp_constructdevicewalks', 'glpi_plugin_fusioninventory_snmpmodelmiblabels', 'glpi_plugin_fusioninventory_snmpmodelmibobjects', 'glpi_plugin_fusioninventory_snmpmodelmiboids', 'glpi_plugin_fusioninventory_snmpmodelconstructdevices', 'glpi_plugin_fusioninventory_snmpmodelconstructdevicewalks' . 'glpi_plugin_fusioninventory_snmpmodelconstructdevices_users', 'glpi_plugin_fusioninventory_snmpmodelconstructdevice_miboids', 'glpi_plugin_fusioninventory_snmpmodelmibs', 'glpi_plugin_fusioninventory_snmpmodels', 'glpi_plugin_fusioninventory_snmpmodeldevices', 'glpi_plugin_fusinvsnmp_constructdevice_miboids', 'glpi_plugin_fusinvsnmp_constructdevices', 'glpi_plugin_fusinvsnmp_constructdevices_users', 'glpi_plugin_fusinvsnmp_miblabels', 'glpi_plugin_fusinvsnmp_mibobjects', 'glpi_plugin_fusinvsnmp_miboids', 'glpi_plugin_fusinvsnmp_modeldevices', 'glpi_plugin_fusinvsnmp_modelmibs', 'glpi_plugin_fusinvsnmp_models', 'glpi_plugin_fusioninventory_construct_walks'); foreach ($a_droptable as $newTable) { $migration->dropTable($newTable); } /* $a_table = array(); //table name $a_table['name'] = ''; $a_table['oldname'] = array( ); // fields : fields that are new, have changed type or just stay the same // array( // <fieldname> = array( // 'type' => <type>, 'value' => <value>) // ); $a_table['fields'] = array( ); // oldfields = fields that need to be removed // array( 'field0', 'field1', ...); $a_table['oldfields'] = array( ); // renamefields = fields that need to be renamed // array('oldname' = 'newname', ...) $a_table['renamefields'] = array( ); // keys : new, changed or not // array( 'field' => <fields>, 'name' => <keyname> , 'type' => <keytype>) // <fields> : fieldnames needed by the key // ex : array('field0' , 'field1' ...) // ex : 'fieldname' // <keyname> : the name of the key (if blank, the fieldname is used) // <type> : the type of key (ex: INDEX, ...) $a_table['keys'] = array( ); // oldkeys : keys that need to be removed // array( 'key0', 'key1', ... ) $a_table['oldkeys'] = array( ); */ //Push task functionnality $migration->addField('glpi_plugin_fusioninventory_tasks', 'last_agent_wakeup', 'datetime'); $migration->addField('glpi_plugin_fusioninventory_tasks', 'wakeup_agent_counter', "int(11) NOT NULL DEFAULT '0'"); $migration->addField('glpi_plugin_fusioninventory_tasks', 'wakeup_agent_time', "int(11) NOT NULL DEFAULT '0'"); $migration->addKey('glpi_plugin_fusioninventory_tasks', 'wakeup_agent_counter'); $migration->migrationOneTable('glpi_plugin_fusioninventory_tasks'); /* * Table glpi_plugin_fusioninventory_agents */ $newTable = "glpi_plugin_fusioninventory_agents"; $prepare_agentConfig = array(); if (TableExists("glpi_plugin_tracker_agents") and FieldExists("glpi_plugin_tracker_agents", "ifaddr_start")) { $query = "SELECT * FROM `glpi_plugin_tracker_agents`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $prepare_rangeip[] = array("ip_start" => $data['ifaddr_start'], "ip_end" => $data['ifaddr_end'], "name" => $data['name']); $prepare_agentConfig[] = array("name" => $data["name"], "lock" => $data['lock'], "threads_networkinventory" => $data['nb_process_query'], "threads_networkdiscovery" => $data['nb_process_discovery']); } } else { if (TableExists("glpi_plugin_tracker_agents") and FieldExists("glpi_plugin_tracker_agents", "core_discovery")) { $query = "SELECT * FROM `glpi_plugin_tracker_agents`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $prepare_agentConfig[] = array("name" => $data["name"], "lock" => $data['lock'], "threads_networkinventory" => $data['threads_query'], "threads_networkdiscovery" => $data['threads_discovery']); } } else { if (TableExists("glpi_plugin_fusioninventory_agents")) { if (FieldExists($newTable, "module_snmpquery")) { $query = "SELECT * FROM `glpi_plugin_fusioninventory_agents`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $prepare_agentConfig[] = array("id" => $data["ID"], "threads_networkinventory" => $data['threads_query'], "threads_networkdiscovery" => $data['threads_discovery'], "NETORKINVENTORY" => $data['module_snmpquery'], "NETWORKDISCOVERY" => $data['module_netdiscovery'], "INVENTORY" => $data['module_inventory'], "WAKEONLAN" => $data['module_wakeonlan']); } } } } } $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_agents'; $a_table['oldname'] = array('glpi_plugin_tracker_agents'); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => '1'); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['last_contact'] = array('type' => 'datetime', 'value' => NULL); $a_table['fields']['version'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['lock'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['device_id'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['token'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['useragent'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['tag'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['threads_networkdiscovery'] = array('type' => "int(4) NOT NULL DEFAULT '1' COMMENT 'array(xmltag=>value)'", 'value' => NULL); $a_table['fields']['threads_networkinventory'] = array('type' => "int(4) NOT NULL DEFAULT '1' COMMENT 'array(xmltag=>value)'", 'value' => NULL); $a_table['fields']['senddico'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['timeout_networkdiscovery'] = array('type' => "int(4) NOT NULL DEFAULT '0' COMMENT 'Network Discovery task timeout'", 'value' => NULL); $a_table['fields']['timeout_networkinventory'] = array('type' => "int(4) NOT NULL DEFAULT '0' COMMENT 'Network Inventory task timeout'", 'value' => NULL); $a_table['fields']['agent_port'] = array('type' => 'varchar(6)', 'value' => NULL); $a_table['oldfields'] = array('module_snmpquery', 'module_netdiscovery', 'module_inventory', 'module_wakeonlan', 'core_discovery', 'threads_discovery', 'core_query', 'threads_query', 'tracker_agent_version', 'logs', 'fragment', 'itemtype', 'device_type'); $a_table['renamefields'] = array(); $a_table['renamefields']['ID'] = 'id'; $a_table['renamefields']['last_agent_update'] = 'last_contact'; $a_table['renamefields']['fusioninventory_agent_version'] = 'version'; $a_table['renamefields']['key'] = 'device_id'; $a_table['renamefields']['on_device'] = 'computers_id'; $a_table['renamefields']['items_id'] = 'computers_id'; $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX'); $a_table['keys'][] = array('field' => 'device_id', 'name' => '', 'type' => 'INDEX'); $a_table['keys'][] = array('field' => 'computers_id', 'name' => '', 'type' => 'INDEX'); $a_table['oldkeys'] = array('key'); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_agentmodules */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_agentmodules'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['modulename'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['is_active'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['exceptions'] = array('type' => 'text', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['oldfields'][] = 'plugins_id'; $a_table['oldfields'][] = 'entities_id'; $a_table['oldfields'][] = 'url'; $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'modulename', 'name' => '', 'type' => 'UNIQUE'); $a_table['oldkeys'] = array('unicity', 'entities_id'); migrateTablesFusionInventory($migration, $a_table); /* * Add Deploy module */ $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='DEPLOY'"; $result = $DB->query($query); if (!$DB->numrows($result)) { $query_ins = "INSERT INTO `glpi_plugin_fusioninventory_agentmodules`\n (`modulename`, `is_active`, `exceptions`)\n VALUES ('DEPLOY', '0', '" . exportArrayToDB(array()) . "')"; $DB->query($query_ins); } /* * Add WakeOnLan module appear in version 2.3.0 */ $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='WAKEONLAN'"; $result = $DB->query($query); if (!$DB->numrows($result)) { $query_ins = "INSERT INTO `glpi_plugin_fusioninventory_agentmodules`\n (`modulename`, `is_active`, `exceptions`)\n VALUES ('WAKEONLAN', '0', '" . exportArrayToDB(array()) . "')"; $DB->query($query_ins); } /* * Add SNMPQUERY module if not present */ $query = "UPDATE `glpi_plugin_fusioninventory_agentmodules`\n SET `modulename`='NETWORKINVENTORY'\n WHERE `modulename`='SNMPQUERY'"; $DB->query($query); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='NETWORKINVENTORY'"; $result = $DB->query($query); if (!$DB->numrows($result)) { $agentmodule = new PluginFusioninventoryAgentmodule(); $input = array(); $input['modulename'] = "NETWORKINVENTORY"; $input['is_active'] = 0; $input['exceptions'] = exportArrayToDB(array()); $agentmodule->add($input); } /* * Add NETDISCOVERY module if not present */ $query = "UPDATE `glpi_plugin_fusioninventory_agentmodules`\n SET `modulename`='NETWORKDISCOVERY'\n WHERE `modulename`='NETDISCOVERY'"; $DB->query($query); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='NETWORKDISCOVERY'"; $result = $DB->query($query); if (!$DB->numrows($result)) { $agentmodule = new PluginFusioninventoryAgentmodule(); $input = array(); $input['modulename'] = "NETWORKDISCOVERY"; $input['is_active'] = 0; $input['exceptions'] = exportArrayToDB(array()); $agentmodule->add($input); } /* * Add INVENTORY module if not present */ $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='INVENTORY'"; $result = $DB->query($query); if (!$DB->numrows($result)) { $agentmodule = new PluginFusioninventoryAgentmodule(); $input = array(); $input['modulename'] = "INVENTORY"; $input['is_active'] = 1; $input['exceptions'] = exportArrayToDB(array()); $agentmodule->add($input); } /* * Table glpi_plugin_fusioninventory_configs */ $newTable = "glpi_plugin_fusioninventory_configs"; if (TableExists('glpi_plugin_tracker_config')) { if (FieldExists('glpi_plugin_tracker_config', 'ssl_only')) { $query = "SELECT * FROM `glpi_plugin_tracker_config`\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $data = $DB->fetch_assoc($result); $prepare_Config['ssl_only'] = $data['ssl_only']; } } // $query = "SELECT * FROM `glpi_plugin_tracker_config` // WHERE `type`='version' // LIMIT 1, 10"; // $result=$DB->query($query); // while ($data=$DB->fetch_array($result)) { // $DB->query("DELETE FROM `glpi_plugin_tracker_config` // WHERE `ID`='".$data['ID']."'"); // } } if (TableExists('glpi_plugin_fusioninventory_configs')) { $id = 'id'; if (FieldExists('glpi_plugin_fusioninventory_configs', 'ID')) { $id = 'ID'; } $query = "SELECT * FROM `glpi_plugin_fusioninventory_configs`\n WHERE `type`='version'\n LIMIT 1, 10"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $DB->query("DELETE FROM `glpi_plugin_fusioninventory_configs`\n WHERE `" . $id . "`='" . $data[$id] . "'"); } } $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_configs'; $a_table['oldname'] = array('glpi_plugin_tracker_config'); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['type'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['oldfields'][] = 'version'; $a_table['oldfields'][] = 'URL_agent_conf'; $a_table['oldfields'][] = 'ssl_only'; $a_table['oldfields'][] = 'authsnmp'; $a_table['oldfields'][] = 'inventory_frequence'; $a_table['oldfields'][] = 'criteria1_ip'; $a_table['oldfields'][] = 'criteria1_name'; $a_table['oldfields'][] = 'criteria1_serial'; $a_table['oldfields'][] = 'criteria1_macaddr'; $a_table['oldfields'][] = 'criteria2_ip'; $a_table['oldfields'][] = 'criteria2_name'; $a_table['oldfields'][] = 'criteria2_serial'; $a_table['oldfields'][] = 'criteria2_macaddr'; $a_table['oldfields'][] = 'delete_agent_process'; $a_table['oldfields'][] = 'activation_history'; $a_table['oldfields'][] = 'activation_connection'; $a_table['oldfields'][] = 'activation_snmp_computer'; $a_table['oldfields'][] = 'activation_snmp_networking'; $a_table['oldfields'][] = 'activation_snmp_peripheral'; $a_table['oldfields'][] = 'activation_snmp_phone'; $a_table['oldfields'][] = 'activation_snmp_printer'; $a_table['oldfields'][] = 'plugins_id'; $a_table['oldfields'][] = 'module'; $a_table['renamefields'] = array(); $a_table['renamefields']['ID'] = 'id'; $a_table['keys'] = array(); $a_table['keys'][] = array('field' => array("type"), 'name' => 'unicity', 'type' => 'UNIQUE'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_entities */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_entities'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['transfers_id_auto'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['agent_base_url'] = array('type' => 'string', 'value' => ''); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => array('entities_id', 'transfers_id_auto'), 'name' => 'entities_id', 'type' => 'INDEX'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); if (countElementsInTable($a_table['name']) == 0) { $a_configs = getAllDatasFromTable('glpi_plugin_fusioninventory_configs', "`type`='transfers_id_auto'"); $transfers_id_auto = 0; if (count($a_configs) > 0) { $a_config = current($a_configs); $transfers_id_auto = $a_config['value']; } $a_configs = getAllDatasFromTable('glpi_plugin_fusioninventory_configs', "`type`='agent_base_url'"); $agent_base_url = ''; if (count($a_configs) > 0) { $a_config = current($a_configs); $agent_base_url = $a_config['value']; } $DB->query("INSERT INTO `glpi_plugin_fusioninventory_entities`\n (`entities_id`, `transfers_id_auto`, `agent_base_url`)\n VALUES ('0', '" . $transfers_id_auto . "', '" . $agent_base_url . "');"); } else { if (countElementsInTable($a_table['name']) > 0) { $a_configs = getAllDatasFromTable('glpi_plugin_fusioninventory_configs', "`type`='agent_base_url'"); $agent_base_url = ''; if (count($a_configs) > 0) { $a_config = current($a_configs); $agent_base_url = $a_config['value']; $DB->query("UPDATE `glpi_plugin_fusioninventory_entities`\n SET `agent_base_url` = '" . $agent_base_url . "'\n ;"); } } } /* * Table glpi_plugin_fusioninventory_credentials */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_credentials'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['name'] = array('type' => 'string', 'value' => ""); $a_table['fields']['username'] = array('type' => 'string', 'value' => ""); $a_table['fields']['password'] = array('type' => 'string', 'value' => ""); $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL); $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL); $a_table['fields']['itemtype'] = array('type' => 'string', 'value' => ""); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); // Fix itemtype changed in 0.84 $DB->query("UPDATE `glpi_plugin_fusioninventory_credentials`\n SET `itemtype`='PluginFusioninventoryInventoryComputerESX'\n WHERE `itemtype`='PluginFusinvinventoryVmwareESX'"); /* * Table glpi_plugin_fusioninventory_credentialips */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_credentialips'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_credentials_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['name'] = array('type' => 'string', 'value' => ""); $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL); $a_table['fields']['ip'] = array('type' => 'string', 'value' => ""); $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_ipranges */ $newTable = "glpi_plugin_fusioninventory_ipranges"; if (TableExists("glpi_plugin_tracker_rangeip")) { // Get all data to create task $query = "SELECT * FROM `glpi_plugin_tracker_rangeip`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { if ($data['discover'] == '1') { $prepare_task[] = array("agents_id" => $data['FK_tracker_agents'], "ipranges_id" => $data['ID'], "netdiscovery" => "1"); } if ($data['query'] == '1') { $prepare_task[] = array("agents_id" => $data['FK_tracker_agents'], "ipranges_id" => $data['ID'], "snmpquery" => "1"); } } } if (TableExists("glpi_plugin_fusioninventory_rangeip") and FieldExists("glpi_plugin_fusioninventory_rangeip", "FK_fusioninventory_agents_discover")) { // Get all data to create task $query = "SELECT * FROM `glpi_plugin_fusioninventory_rangeip`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { if ($data['discover'] == '1') { $prepare_task[] = array("agents_id" => $data['FK_fusioninventory_agents_discover'], "ipranges_id" => $data['ID'], "netdiscovery" => "1"); } if ($data['query'] == '1') { $prepare_task[] = array("agents_id" => $data['FK_fusioninventory_agents_query'], "ipranges_id" => $data['ID'], "snmpquery" => "1"); } } } $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_ipranges'; $a_table['oldname'] = array('glpi_plugin_tracker_rangeip', 'glpi_plugin_fusinvsnmp_ipranges'); $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'name' => array('type' => 'string', 'value' => NULL), 'entities_id' => array('type' => 'integer', 'value' => NULL), 'ip_start' => array('type' => 'string', 'value' => NULL), 'ip_end' => array('type' => 'string', 'value' => NULL)); $a_table['oldfields'] = array('FK_tracker_agents', 'discover', 'query', 'FK_fusioninventory_agents_discover', 'FK_fusioninventory_agents_query', 'construct_device_id', 'log', 'comment'); $a_table['renamefields'] = array('ID' => 'id', 'ifaddr_start' => 'ip_start', 'ifaddr_end' => 'ip_end', 'FK_entities' => 'entities_id'); $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'INDEX')); $a_table['oldkeys'] = array('FK_tracker_agents', 'FK_tracker_agents_2'); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_locks */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_locks'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['tablename'] = array('type' => "varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT ''", 'value' => NULL); $a_table['fields']['items_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['tablefields'] = array('type' => 'text', 'value' => NULL); $a_table['oldfields'] = array('itemtype'); $a_table['renamefields'] = array(); $a_table['renamefields']['fields'] = 'tablefields'; $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'tablename', 'name' => '', 'type' => 'INDEX'); $a_table['keys'][] = array('field' => 'items_id', 'name' => '', 'type' => 'INDEX'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_ipranges_configsecurities */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_ipranges_configsecurities'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['plugin_fusioninventory_ipranges_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_configsecurities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['rank'] = array('type' => 'integer', 'value' => '1'); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_mappings */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_mappings'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['itemtype'] = array('type' => "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL", 'value' => NULL); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['table'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['tablefield'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['locale'] = array('type' => "int(4) NOT NULL DEFAULT '0'", 'value' => NULL); $a_table['fields']['shortlocale'] = array('type' => 'int(4) DEFAULT NULL', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX'); $a_table['keys'][] = array('field' => 'itemtype', 'name' => '', 'type' => 'INDEX'); $a_table['keys'][] = array('field' => 'table', 'name' => '', 'type' => 'INDEX'); $a_table['keys'][] = array('field' => 'tablefield', 'name' => '', 'type' => 'INDEX'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); pluginFusioninventoryUpdatemapping(); if (TableExists('glpi_plugin_fusioninventory_profiles')) { /* * Table glpi_plugin_fusioninventory_profiles */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_profiles'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['type'] = array('type' => 'string', 'value' => ''); $a_table['fields']['right'] = array('type' => 'char', 'value' => NULL); $a_table['fields']['plugins_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['profiles_id'] = array('type' => 'integer', 'value' => NULL); $a_table['oldfields'] = array('name', 'interface', 'is_default', 'snmp_networking', 'snmp_printers', 'snmp_models', 'snmp_authentification', 'rangeip', 'agents', 'remotecontrol', 'agentsprocesses', 'unknowndevices', 'reports', 'deviceinventory', 'netdiscovery', 'snmp_query', 'wol', 'configuration'); $a_table['renamefields'] = array(); $a_table['renamefields']['ID'] = 'id'; $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); // Remove multiple lines can have problem with unicity $query = "SELECT * , count(`id`) AS cnt\n FROM `glpi_plugin_fusioninventory_profiles`\n GROUP BY `type`,`plugins_id`,`profiles_id`\n HAVING cnt >1\n ORDER BY cnt"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $queryd = "DELETE FROM `glpi_plugin_fusioninventory_profiles`\n WHERE `type`='" . $data['type'] . "'\n AND `plugins_id`='" . $data['plugins_id'] . "'\n AND `profiles_id`='" . $data['profiles_id'] . "'\n ORDER BY `id` DESC\n LIMIT " . ($data['cnt'] - 1) . " "; $DB->query($queryd); } $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_profiles'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => array("type", "plugins_id", "profiles_id"), 'name' => 'unicity', 'type' => 'UNIQUE'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); } /* * Update tasks related database tables */ pluginFusioninventoryUpdateTasks($migration, $plugins_id); /* * Table glpi_plugin_fusioninventory_timeslots */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_timeslots'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => '0'); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL); $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_timeslotentries */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_timeslotentries'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['plugin_fusioninventory_timeslots_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => '0'); $a_table['fields']['day'] = array('type' => 'bool', 'value' => 1); $a_table['fields']['begin'] = array('type' => 'int(11) DEFAULT NULL', 'value' => NULL); $a_table['fields']['end'] = array('type' => 'int(11) DEFAULT NULL', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_unmanageds */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_unmanageds'; $a_table['oldname'] = array('glpi_plugin_fusioninventory_unknowndevices', 'glpi_plugin_tracker_unknown_device'); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL); $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['locations_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['is_deleted'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['users_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['serial'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['otherserial'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['contact'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['domain'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL); $a_table['fields']['item_type'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['accepted'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_agents_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['ip'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['hub'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['states_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['sysdescr'] = array('type' => 'text', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_configsecurities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['is_dynamic'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['serialized_inventory'] = array('type' => 'longblob', 'value' => NULL); $a_table['oldfields'] = array('dnsname', 'snmp', 'FK_model_infos', 'FK_snmp_connection', 'FK_agent', 'mac', 'ifmac', 'plugin_fusinvsnmp_models_id', 'plugin_fusioninventory_snmpmodels_id', 'is_template'); $a_table['renamefields'] = array('ID' => 'id', 'comments' => 'comment', 'type' => 'item_type', 'ifaddr' => 'ip', 'FK_entities' => 'entities_id', 'location' => 'locations_id', 'deleted' => 'is_deleted', 'plugin_fusinvsnmp_configsecurities_id' => 'plugin_fusioninventory_configsecurities_id'); $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'INDEX'), array('field' => 'plugin_fusioninventory_agents_id', 'name' => '', 'type' => 'INDEX'), array('field' => 'is_deleted', 'name' => '', 'type' => 'INDEX'), array('field' => 'date_mod', 'name' => '', 'type' => 'INDEX')); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); if (TableExists('glpi_plugin_fusinvsnmp_unknowndevices')) { $query = "SELECT * FROM `glpi_plugin_fusinvsnmp_unknowndevices`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $DB->query("UPDATE `glpi_plugin_fusioninventory_unmanageds`\n SET `sysdescr`='" . $data['sysdescr'] . "',\n `plugin_fusioninventory_configsecurities_id`='" . $data['plugin_fusinvsnmp_configsecurities_id'] . "'\n WHERE `id`='" . $data['plugin_fusioninventory_unknowndevices_id'] . "'"); } $migration->dropTable('glpi_plugin_fusinvsnmp_unknowndevices'); } /* * Table glpi_plugin_fusioninventory_ignoredimportdevices */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_ignoredimportdevices'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['date'] = array('type' => 'datetime', 'value' => NULL); $a_table['fields']['itemtype'] = array('type' => "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL", 'value' => NULL); $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['ip'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['mac'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['rules_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['method'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['serial'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['uuid'] = array('type' => 'string', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_inventorycomputercriterias */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputercriterias'; $a_table['oldname'] = array('glpi_plugin_fusinvinventory_criterias'); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_rulematchedlogs */ $newTable = "glpi_plugin_fusioninventory_rulematchedlogs"; if (!TableExists($newTable)) { $query = "CREATE TABLE `" . $newTable . "` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"; $DB->query($query); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "date", "datetime DEFAULT NULL"); $migration->addField($newTable, "items_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "itemtype", "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "rules_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "plugin_fusioninventory_agents_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "method", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_inventorycomputerblacklists */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputerblacklists'; $a_table['oldname'] = array('glpi_plugin_fusinvinventory_blacklists'); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['plugin_fusioninventory_criterium_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'plugin_fusioninventory_criterium_id', 'name' => '', 'type' => 'KEY'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); $DB->list_fields($newTable, FALSE); pluginFusioninventorychangeDisplayPreference("5153", "PluginFusioninventoryUnknownDevice"); pluginFusioninventorychangeDisplayPreference("5158", "PluginFusioninventoryAgent"); /* * Udpate criteria for blacklist */ $a_criteria = array(); $a_criteria['Serial number'] = 'ssn'; $a_criteria['uuid'] = 'uuid'; $a_criteria['Mac address'] = 'macAddress'; $a_criteria['Windows product key'] = 'winProdKey'; $a_criteria['Model'] = 'smodel'; $a_criteria['storage serial'] = 'storagesSerial'; $a_criteria['drives serial'] = 'drivesSerial'; $a_criteria['Asset Tag'] = 'assetTag'; $a_criteria['Computer name'] = 'name'; $a_criteria['Manufacturer'] = 'manufacturer'; foreach ($a_criteria as $name => $comment) { $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`\n WHERE `name`='" . $name . "'"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $query_ins = "INSERT INTO `glpi_plugin_fusioninventory_inventorycomputercriterias`\n (`name`, `comment`)\n VALUES ('" . $name . "', '" . $comment . "')"; $DB->query($query_ins); } } $a_criteria = array(); $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $a_criteria[$data['comment']] = $data['id']; } /* * Update blacklist */ $newTable = "glpi_plugin_fusioninventory_inventorycomputerblacklists"; // * ssn $a_input = array('N/A', '(null string)', 'INVALID', 'SYS-1234567890', 'SYS-9876543210', 'SN-12345', 'SN-1234567890', '1111111111', '1111111', '1', '0123456789', '12345', '123456', '1234567', '12345678', '123456789', '1234567890', '123456789000', '12345678901234567', '0000000000', '000000000', '00000000', '0000000', '0000000', 'NNNNNNN', 'xxxxxxxxxxx', 'EVAL', 'IATPASS', 'none', 'To Be Filled By O.E.M.', 'Tulip Computers', 'Serial Number xxxxxx', 'SN-123456fvgv3i0b8o5n6n7k', 'Unknow', 'System Serial Number', 'MB-1234567890', '0', 'empty', 'Not Specified'); foreach ($a_input as $value) { $query = "SELECT * FROM `" . $newTable . "`\n WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['ssn'] . "'\n AND `value`='" . $value . "'"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $query = "INSERT INTO `" . $newTable . "`\n (`plugin_fusioninventory_criterium_id`, `value`)\n VALUES ( '" . $a_criteria['ssn'] . "', '" . $value . "')"; $DB->query($query); } } // * uuid $a_input = array('FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF', '03000200-0400-0500-0006-000700080009', '6AB5B300-538D-1014-9FB5-B0684D007B53', '01010101-0101-0101-0101-010101010101'); foreach ($a_input as $value) { $query = "SELECT * FROM `" . $newTable . "`\n WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['uuid'] . "'\n AND `value`='" . $value . "'"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $query = "INSERT INTO `" . $newTable . "`\n (`plugin_fusioninventory_criterium_id`, `value`)\n VALUES ( '" . $a_criteria['uuid'] . "', '" . $value . "')"; $DB->query($query); } } // * macAddress $a_input = array('20:41:53:59:4e:ff', '02:00:4e:43:50:49', 'e2:e6:16:20:0a:35', 'd2:0a:2d:a0:04:be', '00:a0:c6:00:00:00', 'd2:6b:25:2f:2c:e7', '33:50:6f:45:30:30', '0a:00:27:00:00:00', '00:50:56:C0:00:01', '00:50:56:C0:00:08', '02:80:37:EC:02:00', '50:50:54:50:30:30', '24:b6:20:52:41:53'); foreach ($a_input as $value) { $query = "SELECT * FROM `" . $newTable . "`\n WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['macAddress'] . "'\n AND `value`='" . $value . "'"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $query = "INSERT INTO `" . $newTable . "`\n (`plugin_fusioninventory_criterium_id`, `value`)\n VALUES ( '" . $a_criteria['macAddress'] . "', '" . $value . "')"; $DB->query($query); } } // * smodel $a_input = array('Unknow', 'To Be Filled By O.E.M.', '*', 'System Product Name', 'Product Name', 'System Name'); foreach ($a_input as $value) { $query = "SELECT * FROM `" . $newTable . "`\n WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['smodel'] . "'\n AND `value`='" . $value . "'"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $query = "INSERT INTO `" . $newTable . "`\n (`plugin_fusioninventory_criterium_id`, `value`)\n VALUES ( '" . $a_criteria['smodel'] . "', '" . $value . "')"; $DB->query($query); } } // * manufacturer $a_input = array('System manufacturer'); foreach ($a_input as $value) { $query = "SELECT * FROM `" . $newTable . "`\n WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['manufacturer'] . "'\n AND `value`='" . $value . "'"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $query = "INSERT INTO `" . $newTable . "`\n (`plugin_fusioninventory_criterium_id`, `value`)\n VALUES ( '" . $a_criteria['manufacturer'] . "', '" . $value . "')"; $DB->query($query); } } // * ip $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`\n WHERE `name`='IP'"; $result = $DB->query($query); if ($DB->numrows($result) == 0) { $DB->query("INSERT INTO `glpi_plugin_fusioninventory_inventorycomputercriterias`\n (`id`, `name`, `comment`) VALUES\n (11, 'IP', 'IP')"); } $a_criteria = array(); $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $a_criteria[$data['comment']] = $data['id']; } $a_input = array('0.0.0.0'); foreach ($a_input as $value) { $query = "SELECT * FROM `" . $newTable . "`\n WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['IP'] . "'\n AND `value`='" . $value . "'"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $query = "INSERT INTO `" . $newTable . "`\n (`plugin_fusioninventory_criterium_id`, `value`)\n VALUES ( '" . $a_criteria['IP'] . "', '" . $value . "')"; $DB->query($query); } } /* * Table glpi_plugin_fusioninventory_inventorycomputerantiviruses */ $newTable = "glpi_plugin_fusioninventory_inventorycomputerantiviruses"; $migration->renameTable("glpi_plugin_fusinvinventory_antivirus", $newTable); if (!TableExists($newTable)) { $DB->query("CREATE TABLE `" . $newTable . "` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"); } $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "computers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL"); $migration->addField($newTable, "manufacturers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "version", "varchar(255) DEFAULT NULL"); $migration->addField($newTable, "is_active", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "uptodate", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->addKey($newTable, "name"); $migration->addKey($newTable, "version"); $migration->addKey($newTable, "is_active"); $migration->addKey($newTable, "uptodate"); $migration->addKey($newTable, "computers_id"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_inventorycomputerbatteries */ $newTable = "glpi_plugin_fusioninventory_inventorycomputerbatteries"; if (!TableExists($newTable)) { $query = "CREATE TABLE `" . $newTable . "` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"; $DB->query($query); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "computers_id", "computers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL"); $migration->changeField($newTable, "manufacturers_id", "manufacturers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "serial", "serial", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "capacity", "capacity", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "date", "date", "datetime DEFAULT NULL"); $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerchemistries_id", "plugin_fusioninventory_inventorycomputerchemistries_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "voltage", "voltage", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "computers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL"); $migration->addField($newTable, "manufacturers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "serial", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "capacity", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "date", "datetime DEFAULT NULL"); $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerchemistries_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "voltage", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addKey($newTable, "computers_id"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_inventorycomputerchemistries */ $newTable = "glpi_plugin_fusioninventory_inventorycomputerchemistries"; if (!TableExists($newTable)) { $query = "CREATE TABLE `" . $newTable . "` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"; $DB->query($query); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL"); $migration->migrationOneTable($newTable); $migration->addKey($newTable, "name"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_inventorycomputercomputers */ if (TableExists("glpi_plugin_fusinvinventory_computers") and FieldExists("glpi_plugin_fusinvinventory_computers", "uuid")) { $Computer = new Computer(); $sql = "SELECT * FROM `glpi_plugin_fusinvinventory_computers`"; $result = $DB->query($sql); while ($data = $DB->fetch_array($result)) { if ($Computer->getFromDB($data['items_id'])) { $input = array(); $input['id'] = $data['items_id']; $input['uuid'] = $data['uuid']; $Computer->update($input); } } $sql = "DROP TABLE `glpi_plugin_fusinvinventory_computers`"; $DB->query($sql); } if (TableExists("glpi_plugin_fusinvinventory_tmp_agents")) { $sql = "DROP TABLE `glpi_plugin_fusinvinventory_tmp_agents`"; $DB->query($sql); } $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputercomputers'; $a_table['oldname'] = array('glpi_plugin_fusinvinventory_computers'); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['bios_date'] = array('type' => 'datetime', 'value' => NULL); $a_table['fields']['bios_version'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['bios_assettag'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['bios_manufacturers_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['operatingsystem_installationdate'] = array('type' => 'datetime', 'value' => NULL); $a_table['fields']['winowner'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['wincompany'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['last_fusioninventory_update'] = array('type' => 'datetime', 'value' => NULL); $a_table['fields']['remote_addr'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_computerarchs_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['serialized_inventory'] = array('type' => 'longblob', 'value' => ""); $a_table['fields']['is_entitylocked'] = array('type' => 'bool', 'value' => "0"); $a_table['fields']['oscomment'] = array('type' => 'text', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'computers_id', 'name' => '', 'type' => 'INDEX'); $a_table['keys'][] = array('field' => 'last_fusioninventory_update', 'name' => '', 'type' => 'INDEX'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); // Migrate libserialization require_once GLPI_ROOT . "/plugins/fusioninventory/inc/inventorycomputercomputer.class.php"; $pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer(); if (TableExists('glpi_plugin_fusinvinventory_libserialization')) { $query = "SELECT * FROM `glpi_plugin_fusinvinventory_libserialization`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $a_pfcomputer = array(); $a_pfcomputer = current($pfInventoryComputerComputer->find("`computers_id`='" . $data['computers_id'] . "'", "", 1)); if (empty($a_pfcomputer)) { // Add if (countElementsInTable("glpi_computers", "`id`='" . $data['computers_id'] . "'") > 0) { $input = array(); $input['computers_id'] = $data['computers_id']; $input['last_fusioninventory_update'] = $data['last_fusioninventory_update']; $pfInventoryComputerComputer->add($input); } } else { // Update $a_pfcomputer['last_fusioninventory_update'] = $data['last_fusioninventory_update']; $pfInventoryComputerComputer->update($a_pfcomputer); } } } $migration->dropTable('glpi_plugin_fusinvinventory_libserialization'); /* * Table glpi_plugin_fusioninventory_inventorycomputerstats */ if (!TableExists("glpi_plugin_fusioninventory_inventorycomputerstats")) { $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputerstats'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => "smallint(3) NOT NULL AUTO_INCREMENT", 'value' => ''); $a_table['fields']['day'] = array('type' => "smallint(3) NOT NULL DEFAULT '0'", 'value' => ''); $a_table['fields']['hour'] = array('type' => "tinyint(2) NOT NULL DEFAULT '0'", 'value' => ''); $a_table['fields']['counter'] = array('type' => 'integer', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); require_once GLPI_ROOT . "/plugins/fusioninventory/inc/inventorycomputerstat.class.php"; PluginFusioninventoryInventoryComputerStat::init(); } /* * Table glpi_plugin_fusioninventory_inventorycomputerstorages */ $newTable = "glpi_plugin_fusioninventory_inventorycomputerstorages"; if (!TableExists($newTable)) { $query = "CREATE TABLE `" . $newTable . "` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"; $DB->query($query); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL"); $migration->changeField($newTable, "uuid", "uuid", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "totalsize", "totalsize", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "freesize", "freesize", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerstoragetypes_id", "plugin_fusioninventory_inventorycomputerstoragetypes_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "computers_id", "computers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL"); $migration->addField($newTable, "uuid", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "totalsize", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "freesize", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerstoragetypes_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "computers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addKey($newTable, "uuid"); $migration->addKey($newTable, "computers_id"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_inventorycomputerstoragetypes */ $newTable = "glpi_plugin_fusioninventory_inventorycomputerstoragetypes"; if (!TableExists($newTable)) { $query = "CREATE TABLE `" . $newTable . "` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"; $DB->query($query); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL"); $migration->changeField($newTable, "level", "level", "tinyint(2) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL"); $migration->addField($newTable, "level", "tinyint(2) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addKey($newTable, "level"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_inventorycomputerstorages_storages */ $newTable = "glpi_plugin_fusioninventory_inventorycomputerstorages_storages"; if (!TableExists($newTable)) { $query = "CREATE TABLE `" . $newTable . "` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"; $DB->query($query); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_1", "plugin_fusioninventory_inventorycomputerstorages_id_1", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_2", "plugin_fusioninventory_inventorycomputerstorages_id_2", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_1", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_2", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addKey($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_1"); $migration->addKey($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_2"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * glpi_plugin_fusioninventory_configlogfields */ $newTable = "glpi_plugin_fusioninventory_configlogfields"; $migration->renameTable("glpi_plugin_fusioninventory_config_snmp_history", $newTable); $migration->renameTable("glpi_plugin_fusinvsnmp_configlogfields", $newTable); if (TableExists($newTable)) { if (FieldExists($newTable, "field")) { $query = "SELECT * FROM `" . $newTable . "`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $pfMapping = new PluginFusioninventoryMapping(); $mapping = 0; if ($mapping = $pfMapping->get("NetworkEquipment", $data['field'])) { $queryu = "UPDATE `" . $newTable . "`\n SET `field`='" . $mapping['id'] . "'\n WHERE `field`='" . $data['field'] . "'"; $DB->query($queryu); } } } } if (!TableExists($newTable)) { $query = "CREATE TABLE `" . $newTable . "` (\n `id` int(8) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"; $DB->query($query); } $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "id", "id", "int(8) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "plugin_fusioninventory_mappings_id", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "days", "days", "int(255) NOT NULL DEFAULT '-1'"); $migration->migrationOneTable($newTable); $migration->changeField($newTable, "ID", "id", "int(8) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "field", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(8) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "days", "int(255) NOT NULL DEFAULT '-1'"); $migration->addKey($newTable, "plugin_fusioninventory_mappings_id"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); $configLogField = new PluginFusioninventoryConfigLogField(); $configLogField->initConfig(); /* * Table glpi_plugin_fusioninventory_networkportconnectionlogs */ $newTable = "glpi_plugin_fusioninventory_networkportconnectionlogs"; $migration->renameTable("glpi_plugin_fusinvsnmp_networkportconnectionlogs", $newTable); if (!TableExists($newTable)) { $DB->query('CREATE TABLE `' . $newTable . '` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'); } $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "date", "date_mod", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->changeField($newTable, "date_mod", "date_mod", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->changeField($newTable, "creation", "creation", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "FK_port_source", "networkports_id_source", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "networkports_id_source", "networkports_id_source", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "FK_port_destination", "networkports_id_destination", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "networkports_id_destination", "networkports_id_destination", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "plugin_fusioninventory_agentprocesses_id", "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'"); $migration->dropField($newTable, "process_number"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "date_mod", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->addField($newTable, "creation", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "networkports_id_source", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "networkports_id_destination", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addKey($newTable, array("networkports_id_source", "networkports_id_destination", "plugin_fusioninventory_agentprocesses_id"), "networkports_id_source"); $migration->addKey($newTable, "date_mod"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_networkporttypes */ $newTable = "glpi_plugin_fusioninventory_networkporttypes"; $migration->renameTable("glpi_plugin_fusinvsnmp_networkporttypes", $newTable); if (!TableExists($newTable)) { $query = "CREATE TABLE `" . $newTable . "` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"; $DB->query($query); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL"); $migration->changeField($newTable, "number", "number", "int(4) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "othername", "othername", "varchar(255) DEFAULT NULL"); $migration->changeField($newTable, "import", "import", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL"); $migration->addField($newTable, "number", "int(4) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "othername", "varchar(255) DEFAULT NULL"); $migration->addField($newTable, "import", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_printers */ $newTable = "glpi_plugin_fusioninventory_printers"; $migration->renameTable("glpi_plugin_fusinvsnmp_printers", $newTable); $migration->renameTable("glpi_plugin_tracker_printers", $newTable); if (!TableExists($newTable)) { $DB->query('CREATE TABLE `' . $newTable . '` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "printers_id", "printers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "sysdescr", "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "plugin_fusinvsnmp_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "plugin_fusioninventory_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "frequence_days", "frequence_days", "int(5) NOT NULL DEFAULT '1'"); $migration->changeField($newTable, "last_fusioninventory_update", "last_fusioninventory_update", "datetime DEFAULT NULL"); $migration->migrationOneTable($newTable); $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "FK_printers", "printers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "FK_snmp_connection", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "last_tracker_update", "last_fusioninventory_update", "datetime DEFAULT NULL"); $migration->dropKey($newTable, "FK_printers"); $migration->dropKey($newTable, "FK_snmp_connection"); $migration->dropKey($newTable, "plugin_fusioninventory_snmpmodels_id"); $migration->migrationOneTable($newTable); $migration->dropField($newTable, "plugin_fusinvsnmp_models_id"); $migration->dropField($newTable, "plugin_fusioninventory_snmpmodels_id"); $migration->dropField($newTable, "FK_model_infos"); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "printers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "frequence_days", "int(5) NOT NULL DEFAULT '1'"); $migration->addField($newTable, "last_fusioninventory_update", "datetime DEFAULT NULL"); $migration->addField($newTable, "serialized_inventory", "longblob"); $migration->addKey($newTable, "plugin_fusioninventory_configsecurities_id"); $migration->addKey($newTable, "printers_id"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_printerlogs */ $newTable = "glpi_plugin_fusioninventory_printerlogs"; $migration->renameTable("glpi_plugin_fusinvsnmp_printerlogs", $newTable); $migration->renameTable("glpi_plugin_tracker_printers_history", $newTable); if (!TableExists($newTable)) { $DB->query('CREATE TABLE `' . $newTable . '` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "printers_id", "printers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "date", "date", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->changeField($newTable, "pages_total", "pages_total", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "pages_n_b", "pages_n_b", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "pages_color", "pages_color", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "pages_recto_verso", "pages_recto_verso", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "scanned", "scanned", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "pages_total_print", "pages_total_print", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "pages_n_b_print", "pages_n_b_print", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "pages_color_print", "pages_color_print", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "pages_total_copy", "pages_total_copy", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "pages_n_b_copy", "pages_n_b_copy", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "pages_color_copy", "pages_color_copy", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "pages_total_fax", "pages_total_fax", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "FK_printers", "printers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "printers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "date", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->addField($newTable, "pages_total", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "pages_n_b", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "pages_color", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "pages_recto_verso", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "scanned", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "pages_total_print", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "pages_n_b_print", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "pages_color_print", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "pages_total_copy", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "pages_n_b_copy", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "pages_color_copy", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "pages_total_fax", "int(11) NOT NULL DEFAULT '0'"); $migration->addKey($newTable, array("printers_id", "date"), "printers_id"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * glpi_plugin_fusioninventory_printercartridges */ $newTable = "glpi_plugin_fusioninventory_printercartridges"; $migration->renameTable("glpi_plugin_fusinvsnmp_printercartridges", $newTable); $migration->renameTable("glpi_plugin_tracker_printers_cartridges", $newTable); if (!TableExists($newTable)) { $DB->query('CREATE TABLE `' . $newTable . '` ( `id` bigint(100) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'); } $migration->changeField($newTable, "id", "id", "bigint(100) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "printers_id", "printers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "plugin_fusioninventory_mappings_id", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "cartridges_id", "cartridges_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "state", "state", "int(3) NOT NULL DEFAULT '100'"); $migration->migrationOneTable($newTable); $migration->changeField($newTable, "ID", "id", "bigint(100) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "FK_printers", "printers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "FK_cartridges", "cartridges_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); // Update with mapping if (FieldExists($newTable, "object_name")) { $query = "SELECT * FROM `" . $newTable . "`\n GROUP BY `object_name`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $pfMapping = new PluginFusioninventoryMapping(); $mapping = 0; if ($mapping = $pfMapping->get("Printer", $data['object_name'])) { $DB->query("UPDATE `" . $newTable . "`\n SET `plugin_fusioninventory_mappings_id`='" . $mapping['id'] . "'\n WHERE `object_name`='" . $data['object_name'] . "'"); } } } $migration->dropField($newTable, "object_name"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "bigint(100) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "printers_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "cartridges_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "state", "int(3) NOT NULL DEFAULT '100'"); $migration->addKey($newTable, "printers_id"); $migration->addKey($newTable, "plugin_fusioninventory_mappings_id"); $migration->addKey($newTable, "cartridges_id"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * glpi_plugin_fusioninventory_networkports */ $newTable = "glpi_plugin_fusioninventory_networkports"; $migration->renameTable("glpi_plugin_fusinvsnmp_networkports", $newTable); $migration->renameTable("glpi_plugin_tracker_networking_ports", $newTable); if (!TableExists($newTable)) { $DB->query('CREATE TABLE `' . $newTable . '` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "networkports_id", "networkports_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "ifmtu", "ifmtu", "int(8) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "ifspeed", "ifspeed", "bigint(50) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "ifinternalstatus", "ifinternalstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "ifconnectionstatus", "ifconnectionstatus", "int(8) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "iflastchange", "iflastchange", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "ifinoctets", "ifinoctets", "bigint(50) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "ifinerrors", "ifinerrors", "bigint(50) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "ifoutoctets", "ifoutoctets", "bigint(50) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "ifouterrors", "ifouterrors", "bigint(50) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "ifstatus", "ifstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "mac", "mac", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "ifdescr", "ifdescr", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "portduplex", "portduplex", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "trunk", "trunk", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "lastup", "lastup", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->migrationOneTable($newTable); $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "FK_networking_ports", "networkports_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "ifmac", "mac", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->dropKey($newTable, "FK_networking_ports"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "networkports_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "ifmtu", "int(8) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "ifspeed", "bigint(50) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "ifinternalstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "ifconnectionstatus", "int(8) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "iflastchange", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "ifinoctets", "bigint(50) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "ifinerrors", "bigint(50) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "ifoutoctets", "bigint(50) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "ifouterrors", "bigint(50) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "ifstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "mac", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "ifdescr", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "ifalias", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "portduplex", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "trunk", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "lastup", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->addKey($newTable, "networkports_id"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_networkequipments */ $newTable = "glpi_plugin_fusioninventory_networkequipments"; $migration->renameTable("glpi_plugin_fusinvsnmp_networkequipments", $newTable); $migration->renameTable("glpi_plugin_tracker_networking", $newTable); if (!TableExists($newTable)) { $DB->query('CREATE TABLE `' . $newTable . '` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "networkequipments_id", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "sysdescr", "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "plugin_fusioninventory_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "uptime", "uptime", "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "cpu", "cpu", "int(3) NOT NULL DEFAULT '0' COMMENT '%'"); $migration->changeField($newTable, "memory", "memory", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "last_fusioninventory_update", "last_fusioninventory_update", "datetime DEFAULT NULL"); $migration->changeField($newTable, "last_PID_update", "last_PID_update", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "FK_networking", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "FK_snmp_connection", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "last_tracker_update", "last_fusioninventory_update", "datetime DEFAULT NULL"); $migration->changeField($newTable, "plugin_fusinvsnmp_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'"); $migration->dropKey($newTable, "FK_networking"); $migration->dropKey($newTable, "FK_model_infos"); $migration->dropKey($newTable, "plugin_fusioninventory_snmpmodels_id"); $migration->migrationOneTable($newTable); $migration->dropField($newTable, "plugin_fusioninventory_snmpmodels_id"); $migration->dropField($newTable, "plugin_fusinvsnmp_models_id"); $migration->dropField($newTable, "FK_model_infos"); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "networkequipments_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "uptime", "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'"); $migration->addField($newTable, "cpu", "int(3) NOT NULL DEFAULT '0' COMMENT '%'"); $migration->addField($newTable, "memory", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "last_fusioninventory_update", "datetime DEFAULT NULL"); $migration->addField($newTable, "last_PID_update", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "serialized_inventory", "longblob"); $migration->addKey($newTable, "networkequipments_id"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * glpi_plugin_fusioninventory_networkequipmentips * Removed in 0.84, but required here for update, we drop in edn of this function */ if (TableExists("glpi_plugin_fusioninventory_networkequipmentips") || TableExists("glpi_plugin_fusinvsnmp_networkequipmentips") || TableExists("glpi_plugin_tracker_networking_ifaddr")) { $newTable = "glpi_plugin_fusioninventory_networkequipmentips"; $migration->renameTable("glpi_plugin_fusinvsnmp_networkequipmentips", $newTable); $migration->renameTable("glpi_plugin_tracker_networking_ifaddr", $newTable); if (!TableExists($newTable)) { $DB->query('CREATE TABLE `' . $newTable . '` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "networkequipments_id", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "ip", "ip", "varchar(255) DEFAULT NULL"); $migration->migrationOneTable($newTable); $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "FK_networking", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "ifaddr", "ip", "varchar(255) DEFAULT NULL"); $migration->dropKey($newTable, "ifaddr"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "networkequipments_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "ip", "varchar(255) DEFAULT NULL"); $migration->addKey($newTable, "ip"); $migration->addKey($newTable, "networkequipments_id"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); } /* * Table glpi_plugin_fusioninventory_networkportlogs */ $newTable = "glpi_plugin_fusioninventory_networkportlogs"; if (TableExists("glpi_plugin_tracker_snmp_history")) { // **** Update history update213to220_ConvertField($migration); // **** Migration network history connections $query = "SELECT count(ID) FROM `glpi_plugin_tracker_snmp_history`\n WHERE `Field`='0'"; $result = $DB->query($query); $datas = $DB->fetch_assoc($result); $nb = $datas['count(ID)']; //echo "Move Connections history to another table..."; for ($i = 0; $i < $nb; $i = $i + 500) { $migration->displayMessage("{$i} / {$nb}"); $sql_connection = "SELECT * FROM `glpi_plugin_tracker_snmp_history`\n WHERE `Field`='0'\n ORDER BY `FK_process` DESC, `date_mod` DESC\n LIMIT 500"; $result_connection = $DB->query($sql_connection); while ($thread_connection = $DB->fetch_array($result_connection)) { $input = array(); $input['process_number'] = $thread_connection['FK_process']; $input['date'] = $thread_connection['date_mod']; if ($thread_connection["old_device_ID"] != "0" or $thread_connection["new_device_ID"] != "0") { if ($thread_connection["old_device_ID"] != "0") { // disconnection $input['creation'] = '0'; } else { if ($thread_connection["new_device_ID"] != "0") { // connection $input['creation'] = '1'; } } $input['FK_port_source'] = $thread_connection["FK_ports"]; $dataPort = array(); if ($thread_connection["old_device_ID"] != "0") { $queryPort = "SELECT *\n FROM `glpi_networkports`\n WHERE `mac`='" . $thread_connection['old_value'] . "'\n LIMIT 1"; $resultPort = $DB->query($queryPort); $dataPort = $DB->fetch_assoc($resultPort); } else { if ($thread_connection["new_device_ID"] != "0") { $queryPort = "SELECT *\n FROM `glpi_networkports`\n WHERE `mac`='" . $thread_connection['new_value'] . "'\n LIMIT 1"; $resultPort = $DB->query($queryPort); $dataPort = $DB->fetch_assoc($resultPort); } } if (isset($dataPort['id'])) { $input['FK_port_destination'] = $dataPort['id']; } else { $input['FK_port_destination'] = 0; } $query_ins = "INSERT INTO `glpi_plugin_fusinvsnmp_networkportconnectionlogs`\n (`date_mod`, `creation`, `networkports_id_source`,\n `networkports_id_destination`)\n VALUES ('" . $input['date'] . "',\n '" . $input['creation'] . "',\n '" . $input['FK_port_source'] . "',\n '" . $input['FK_port_destination'] . "')"; $DB->query($query_ins); } } } $query_del = "DELETE FROM `glpi_plugin_tracker_snmp_history`\n WHERE `Field`='0'\n AND (`old_device_ID`!='0' OR `new_device_ID`!='0')"; $DB->query($query_del); $migration->displayMessage("{$nb} / {$nb}"); } $migration->renameTable("glpi_plugin_fusinvsnmp_networkportlogs", $newTable); $migration->renameTable("glpi_plugin_tracker_snmp_history", $newTable); if (!TableExists($newTable)) { $query = "CREATE TABLE `" . $newTable . "` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"; $DB->query($query); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "networkports_id", "networkports_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "plugin_fusioninventory_mappings_id", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "date_mod", "date_mod", "datetime DEFAULT NULL"); $migration->changeField($newTable, "value_old", "value_old", "varchar(255) DEFAULT NULL"); $migration->changeField($newTable, "value_new", "value_new", "varchar(255) DEFAULT NULL"); $migration->changeField($newTable, "plugin_fusioninventory_agentprocesses_id", "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "FK_ports", "networkports_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); // Update with mapping if (FieldExists($newTable, "Field")) { // $pfNetworkPortLog = new PluginFusioninventoryNetworkPortLog(); $pfMapping = new PluginFusioninventoryMapping(); $query = "SELECT * FROM `" . $newTable . "`\n GROUP BY `Field`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $mapping = 0; if ($mapping = $pfMapping->get("NetworkEquipment", $data['Field'])) { $DB->query("UPDATE `" . $newTable . "`\n SET `plugin_fusioninventory_mappings_id`='" . $mapping['id'] . "'\n WHERE `Field`='" . $data['Field'] . "'\n AND `plugin_fusioninventory_mappings_id`!='" . $mapping['id'] . "'"); } } } $migration->dropField($newTable, "Field"); $migration->changeField($newTable, "old_value", "value_old", "varchar(255) DEFAULT NULL"); $migration->dropField($newTable, "old_device_type"); $migration->dropField($newTable, "old_device_ID"); $migration->changeField($newTable, "new_value", "value_new", "varchar(255) DEFAULT NULL"); $migration->dropField($newTable, "new_device_type"); $migration->dropField($newTable, "new_device_ID"); $migration->dropField($newTable, "FK_process"); $migration->dropKey($newTable, "FK_process"); $migration->dropKey($newTable, "FK_ports"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "networkports_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "date_mod", "datetime DEFAULT NULL"); $migration->addField($newTable, "value_old", "varchar(255) DEFAULT NULL"); $migration->addField($newTable, "value_new", "varchar(255) DEFAULT NULL"); $migration->addField($newTable, "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addKey($newTable, array("networkports_id", "date_mod"), "networkports_id"); $migration->addKey($newTable, "plugin_fusioninventory_mappings_id"); $migration->addKey($newTable, "plugin_fusioninventory_agentprocesses_id"); $migration->addKey($newTable, "date_mod"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_configsecurities */ // TODO get info to create SNMP authentification with old values of Tracker plugin $newTable = "glpi_plugin_fusioninventory_configsecurities"; $migration->renameTable("glpi_plugin_fusinvsnmp_configsecurities", $newTable); $migration->renameTable("glpi_plugin_tracker_snmp_connection", $newTable); if (!TableExists($newTable)) { $DB->query('CREATE TABLE `' . $newTable . '` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "name", "name", "varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "snmpversion", "snmpversion", "varchar(8) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1'"); $migration->changeField($newTable, "community", "community", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "username", "username", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "authentication", "authentication", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "auth_passphrase", "auth_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "encryption", "encryption", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "priv_passphrase", "priv_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->changeField($newTable, "is_deleted", "is_deleted", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "FK_snmp_version", "snmpversion", "varchar(8) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1'"); $migration->changeField($newTable, "sec_name", "username", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->dropField($newTable, "sec_level"); $migration->dropField($newTable, "auth_protocol"); $migration->dropField($newTable, "priv_protocol"); $migration->dropField($newTable, "deleted"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "name", "varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "snmpversion", "varchar(8) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1'"); $migration->addField($newTable, "community", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "username", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "authentication", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "auth_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "encryption", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "priv_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL"); $migration->addField($newTable, "is_deleted", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->addKey($newTable, "snmpversion"); $migration->addKey($newTable, "is_deleted"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * glpi_plugin_fusioninventory_statediscoveries */ $newTable = "glpi_plugin_fusioninventory_statediscoveries"; $migration->renameTable("glpi_plugin_fusinvsnmp_statediscoveries", $newTable); if (!TableExists($newTable)) { $DB->query("CREATE TABLE `" . $newTable . "` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"); } $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($newTable, "plugin_fusioninventory_taskjob_id", "plugin_fusioninventory_taskjob_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "plugin_fusioninventory_agents_id", "plugin_fusioninventory_agents_id", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "start_time", "start_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->changeField($newTable, "end_time", "end_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->changeField($newTable, "date_mod", "date_mod", "datetime DEFAULT NULL"); $migration->changeField($newTable, "threads", "threads", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "nb_ip", "nb_ip", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "nb_found", "nb_found", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "nb_error", "nb_error", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "nb_exists", "nb_exists", "int(11) NOT NULL DEFAULT '0'"); $migration->changeField($newTable, "nb_import", "nb_import", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->addField($newTable, "plugin_fusioninventory_taskjob_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "plugin_fusioninventory_agents_id", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "start_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->addField($newTable, "end_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); $migration->addField($newTable, "date_mod", "datetime DEFAULT NULL"); $migration->addField($newTable, "threads", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "nb_ip", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "nb_found", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "nb_error", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "nb_exists", "int(11) NOT NULL DEFAULT '0'"); $migration->addField($newTable, "nb_import", "int(11) NOT NULL DEFAULT '0'"); $migration->migrationOneTable($newTable); $DB->list_fields($newTable, FALSE); /* * Table glpi_plugin_fusioninventory_computerlicenseinfos */ if (TableExists("glpi_plugin_fusinvinventory_licenseinfos")) { $DB->query("UPDATE `glpi_plugin_fusinvinventory_licenseinfos`" . " SET `softwarelicenses_id`='0'" . " WHERE `softwarelicenses_id` IS NULL"); } $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_computerlicenseinfos'; $a_table['oldname'] = array('glpi_plugin_fusinvinventory_licenseinfos'); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['softwarelicenses_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['fullname'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['serial'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['is_trial'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['is_update'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['is_oem'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['activation_date'] = array('type' => 'datetime', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX'); $a_table['keys'][] = array('field' => 'fullname', 'name' => '', 'type' => 'INDEX'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_computerarchs */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_computerarchs'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => ''); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Deploy Update Begin */ /* * glpi_plugin_fusioninventory_deployfiles */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_deployfiles'; $a_table['oldname'] = array(); $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'name' => array('type' => 'varchar(255) NOT NULL', 'value' => NULL), 'mimetype' => array('type' => 'varchar(255) NOT NULL', 'value' => NULL), 'filesize' => array('type' => 'bigint(20) NOT NULL', 'value' => NULL), 'comment' => array('type' => 'text DEFAULT NULL', 'value' => NULL), 'sha512' => array('type' => 'char(128) NOT NULL', 'value' => NULL), 'shortsha512' => array('type' => 'char(6) NOT NULL', 'value' => NULL), 'entities_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'is_recursive' => array('type' => 'tinyint(1) NOT NULL DEFAULT 0', 'value' => 0), 'date_mod' => array('type' => 'datetime DEFAULT NULL', 'value' => NULL)); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(array('field' => 'id', 'name' => '', 'type' => 'KEY'), array('field' => 'shortsha512', 'name' => '', 'type' => 'KEY'), array('field' => 'entities_id', 'name' => '', 'type' => 'KEY'), array('field' => 'date_mod', 'name' => '', 'type' => 'KEY')); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * glpi_plugin_fusioninventory_deployorders */ $a_table = array(); //table name $a_table['name'] = 'glpi_plugin_fusioninventory_deployorders'; $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_orders'); $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'type' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'create_date' => array('type' => ' datetime NOT NULL', 'value' => NULL), 'plugin_fusioninventory_deploypackages_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'json' => array('type' => 'longtext DEFAULT NULL', 'value' => NULL)); $a_table['oldfields'] = array(); $a_table['renamefields'] = array('plugin_fusinvdeploy_packages_id' => 'plugin_fusioninventory_deploypackages_id'); $a_table['keys'] = array(array('field' => 'type', 'name' => '', 'type' => 'KEY'), array('field' => 'create_date', 'name' => '', 'type' => 'KEY'), array('field' => 'plugin_fusioninventory_deploypackages_id', 'name' => '', 'type' => 'KEY')); $a_table['oldkeys'] = array('plugin_fusinvdeploy_packages_id'); migrateTablesFusionInventory($migration, $a_table); /* * glpi_plugin_fusioninventory_deploypackages */ $a_table = array(); //table name $a_table['name'] = 'glpi_plugin_fusioninventory_deploypackages'; $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_packages'); $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'name' => array('type' => 'varchar(255) COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL), 'comment' => array('type' => "text", 'value' => NULL), 'entities_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'is_recursive' => array('type' => 'tinyint(1) NOT NULL DEFAULT 0', 'value' => NULL), 'date_mod' => array('type' => 'datetime DEFAULT NULL', 'value' => NULL), 'uuid' => array('type' => 'string', 'value' => NULL)); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'KEY'), array('field' => 'date_mod', 'name' => '', 'type' => 'KEY')); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * glpi_plugin_fusioninventory_deploymirrors */ $a_table = array(); //table name $a_table['name'] = 'glpi_plugin_fusioninventory_deploymirrors'; $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_mirrors'); $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'entities_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'is_recursive' => array('type' => 'tinyint(1) NOT NULL DEFAULT 0', 'value' => NULL), 'name' => array('type' => 'varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL), 'url' => array('type' => "varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci" . " NOT NULL DEFAULT ''", 'value' => NULL), 'locations_id' => array('type' => 'int(11) NOT NULL', 'value' => 0), 'comment' => array('type' => "text", 'value' => NULL), 'date_mod' => array('type' => 'datetime DEFAULT NULL', 'value' => NULL)); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'KEY'), array('field' => 'date_mod', 'name' => '', 'type' => 'KEY')); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * glpi_plugin_fusioninventory_deploygroups */ $a_table = array(); //table name $a_table['name'] = 'glpi_plugin_fusioninventory_deploygroups'; $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_groups'); $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'name' => array('type' => 'varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL), 'comment' => array('type' => "text", 'value' => NULL), 'type' => array('type' => 'varchar(255) COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL)); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * glpi_plugin_fusioninventory_deploygroups_staticdatas */ $a_table = array(); //table name $a_table['name'] = 'glpi_plugin_fusioninventory_deploygroups_staticdatas'; $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_groups_staticdatas'); $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'groups_id' => array('type' => 'integer', 'value' => NULL), 'itemtype' => array('type' => 'varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL', 'value' => NULL), 'items_id' => array('type' => 'integer', 'value' => NULL)); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(array('field' => 'groups_id', 'name' => '', 'type' => 'KEY'), array('field' => 'items_id', 'name' => '', 'type' => 'KEY')); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * glpi_plugin_fusioninventory_deploygroups_dynamicdatas */ $a_table = array(); //table name $a_table['name'] = 'glpi_plugin_fusioninventory_deploygroups_dynamicdatas'; $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_groups_dynamicdatas'); $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'groups_id' => array('type' => 'integer', 'value' => NULL), 'fields_array' => array('type' => 'text', 'value' => NULL)); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(array('field' => 'groups_id', 'name' => '', 'type' => 'KEY')); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * import old datas as json in order table before migrate this table */ migrateTablesFromFusinvDeploy($migration); /* * Deploy Update End */ /* * Table glpi_plugin_fusioninventory_collects */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_collects'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => ''); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['type'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['is_active'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_collects_registries */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_collects_registries'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => ''); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_collects_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['hive'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['path'] = array('type' => 'text', 'value' => NULL); $a_table['fields']['key'] = array('type' => 'string', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_collects_registries_contents */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_collects_registries_contents'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => ''); $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_collects_registries_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['key'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'computers_id', 'name' => '', 'type' => 'INDEX'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_collects_wmis */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_collects_wmis'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => ''); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_collects_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['moniker'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['class'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['properties'] = array('type' => 'string', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_collects_wmis_contents */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_collects_wmis_contents'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => ''); $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_collects_wmis_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['property'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_collects_files */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_collects_files'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => ''); $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_collects_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['dir'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['limit'] = array('type' => "int(4) NOT NULL DEFAULT '50'", 'value' => NULL); $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['filter_regex'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['filter_sizeequals'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['filter_sizegreater'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['filter_sizelower'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['filter_checksumsha512'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['filter_checksumsha2'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['filter_name'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['filter_iname'] = array('type' => 'string', 'value' => NULL); $a_table['fields']['filter_is_file'] = array('type' => 'bool', 'value' => '1'); $a_table['fields']['filter_is_dir'] = array('type' => 'bool', 'value' => '0'); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_collects_files_contents */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_collects_files_contents'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => ''); $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['plugin_fusioninventory_collects_files_id'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['pathfile'] = array('type' => 'text', 'value' => NULL); $a_table['fields']['size'] = array('type' => 'integer', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_dblockinventorynames */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_dblockinventorynames'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['value'] = array('type' => "varchar(100) NOT NULL DEFAULT ''", 'value' => NULL); $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_dblockinventories */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_dblockinventories'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['value'] = array('type' => 'integer', 'value' => NULL); $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_dblocksoftwares */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_dblocksoftwares'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['value'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Table glpi_plugin_fusioninventory_dblocksoftwareversions */ $a_table = array(); $a_table['name'] = 'glpi_plugin_fusioninventory_dblocksoftwareversions'; $a_table['oldname'] = array(); $a_table['fields'] = array(); $a_table['fields']['value'] = array('type' => 'bool', 'value' => NULL); $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL); $a_table['oldfields'] = array(); $a_table['renamefields'] = array(); $a_table['keys'] = array(); $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE'); $a_table['oldkeys'] = array(); migrateTablesFusionInventory($migration, $a_table); /* * Add ESX module appear in version 2.4.0(0.80+1.0) */ $DB->query("UPDATE `glpi_plugin_fusioninventory_agentmodules`\n SET `modulename`='InventoryComputerESX'\n WHERE `modulename`='ESX'"); $agentmodule = new PluginFusioninventoryAgentmodule(); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='InventoryComputerESX'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $input = array(); $input['modulename'] = "InventoryComputerESX"; $input['is_active'] = 0; $input['exceptions'] = exportArrayToDB(array()); $url = ''; if (isset($_SERVER['HTTP_REFERER'])) { $url = $_SERVER['HTTP_REFERER']; } $agentmodule->add($input); } /* * Add Collect module appear in version 0.84+2.0 */ $agentmodule = new PluginFusioninventoryAgentmodule(); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='Collect'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $input = array(); $input['modulename'] = "Collect"; $input['is_active'] = 1; $input['exceptions'] = exportArrayToDB(array()); $agentmodule->add($input); } /* * Update pci and usb ids and oui */ foreach (array('usbid.sql', 'pciid.sql', 'oui.sql') as $sql) { $DB_file = GLPI_ROOT . "/plugins/fusioninventory/install/mysql/{$sql}"; $DBf_handle = fopen($DB_file, "rt"); $sql_query = fread($DBf_handle, filesize($DB_file)); fclose($DBf_handle); foreach (explode(";\n", "{$sql_query}") as $sql_line) { if (Toolbox::get_magic_quotes_runtime()) { $sql_line = Toolbox::stripslashes_deep($sql_line); } if (!empty($sql_line)) { $DB->query($sql_line); } } } /* * Migrate data of table glpi_plugin_fusinvsnmp_agentconfigs into * glpi_plugin_fusioninventory_agents */ if (TableExists("glpi_plugin_fusinvsnmp_agentconfigs")) { $query = "SELECT * FROM `glpi_plugin_fusinvsnmp_agentconfigs`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $queryu = "UPDATE `glpi_plugin_fusioninventory_agents`\n SET `threads_networkdiscovery`='" . $data['threads_netdiscovery'] . "',\n `threads_networkinventory`='" . $data['threads_snmpquery'] . "',\n `senddico`='" . $data['senddico'] . "'\n WHERE `id`='" . $data['plugin_fusioninventory_agents_id'] . "'"; $DB->query($queryu); } } // Update profiles if (TableExists("glpi_plugin_tracker_profiles")) { $profile = new Profile(); $pfProfile = new PluginFusioninventoryProfile(); $query = "SELECT * FROM `glpi_plugin_tracker_profiles`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $profiledata = current($profile->find("`name`='" . $data['name'] . "'", "", 1)); if (!empty($profiledata)) { $newprofile = array(); $newprofile['snmp_networking'] = "networkequipment"; $newprofile['snmp_printers'] = "printer"; $newprofile['snmp_models'] = "model"; $newprofile['snmp_authentification'] = "configsecurity"; $newprofile['general_config'] = "configuration"; $newprofile['snmp_report'] = "reportprinter"; foreach ($newprofile as $old => $new) { if (isset($profiledata[$old])) { // $pfProfile->addProfile($new, // $profiledata[$old], // $profiledata['id']); } } if (isset($profiledata["snmp_report"])) { // $pfProfile->addProfile("reportnetworkequipment", // $profiledata["snmp_report"], // $profiledata['id']); } } } $DB->query("DROP TABLE `glpi_plugin_tracker_profiles`"); } update213to220_ConvertField($migration); /* * Move networkequipment IPs to net system */ if (TableExists("glpi_plugin_fusioninventory_networkequipmentips")) { $networkPort = new NetworkPort(); $networkName = new NetworkName(); $ipAddress = new IPAddress(); $networkEquipment = new NetworkEquipment(); $query = "SELECT * FROM `glpi_plugin_fusioninventory_networkequipments`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { if ($networkEquipment->getFromDB($data['networkequipments_id'])) { $oldtableip = array(); $queryIP = "SELECT * FROM `glpi_plugin_fusioninventory_networkequipmentips`\n WHERE `networkequipments_id`='" . $data['networkequipments_id'] . "'"; $resultIP = $DB->query($queryIP); while ($dataIP = $DB->fetch_array($resultIP)) { $oldtableip[$dataIP['ip']] = $dataIP['ip']; } // Get actual IP defined $networknames_id = 0; $a_ports = $networkPort->find("`itemtype`='NetworkEquipment'\n AND `items_id`='" . $data['networkequipments_id'] . "'\n AND `instantiation_type`='NetworkPortAggregate'\n AND `name`='management'", "", 1); foreach ($a_ports as $a_port) { $a_networknames = $networkName->find("`itemtype`='NetworkPort'\n AND `items_id`='" . $a_port['id'] . "'"); foreach ($a_networknames as $a_networkname) { $networknames_id = $a_networkname['id']; $a_ipaddresses = $ipAddress->find("`itemtype`='NetworkName'\n AND `items_id`='" . $a_networkname['id'] . "'"); foreach ($a_ipaddresses as $a_ipaddress) { if (isset($oldtableip[$a_ipaddress['name']])) { unset($oldtableip[$a_ipaddress['name']]); } else { $ipAddress->delete($a_ipaddress, 1); } } } } // Update foreach ($oldtableip as $ip) { $input = array(); $input['itemtype'] = "NetworkName"; $input['items_id'] = $networknames_id; $input['name'] = $ip; $input['is_dynamic'] = 1; $ipAddress->add($input); } } } } /* * Table Delete old table not used */ $a_drop = array(); $a_drop[] = 'glpi_plugin_tracker_computers'; $a_drop[] = 'glpi_plugin_tracker_connection_history'; $a_drop[] = 'glpi_plugin_tracker_agents_processes'; $a_drop[] = 'glpi_plugin_tracker_config_snmp_history'; $a_drop[] = 'glpi_plugin_tracker_config_snmp_networking'; $a_drop[] = 'glpi_plugin_tracker_config_snmp_printer'; $a_drop[] = 'glpi_plugin_tracker_config_snmp_script'; $a_drop[] = 'glpi_plugin_tracker_connection_stats'; $a_drop[] = 'glpi_plugin_tracker_discovery'; $a_drop[] = 'glpi_plugin_tracker_errors'; $a_drop[] = 'glpi_plugin_tracker_model_infos'; $a_drop[] = 'glpi_plugin_tracker_processes'; $a_drop[] = 'glpi_plugin_tracker_processes_values'; $a_drop[] = 'glpi_plugin_fusioninventory_agents_errors'; $a_drop[] = 'glpi_plugin_fusioninventory_agents_processes'; $a_drop[] = 'glpi_plugin_fusioninventory_computers'; $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_auth_auth_protocol'; $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_auth_priv_protocol'; $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_auth_sec_level'; $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_version'; $a_drop[] = 'glpi_plugin_fusioninventory_config_snmp_networking'; $a_drop[] = 'glpi_plugin_fusioninventory_config_snmp_history'; $a_drop[] = 'glpi_plugin_fusinvsnmp_agentconfigs'; $a_drop[] = 'glpi_plugin_tracker_computers'; $a_drop[] = 'glpi_plugin_tracker_config'; $a_drop[] = 'glpi_plugin_tracker_config_discovery'; $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_mib_label'; $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_mib_object'; $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_mib_oid'; $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_snmp_auth_auth_protocol'; $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_snmp_auth_priv_protocol'; $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_snmp_version'; $a_drop[] = 'glpi_plugin_fusinvsnmp_temp_profiles'; $a_drop[] = 'glpi_plugin_fusinvsnmp_tmp_agents'; $a_drop[] = 'glpi_plugin_fusinvsnmp_tmp_configs'; $a_drop[] = 'glpi_plugin_fusinvsnmp_tmp_tasks'; $a_drop[] = 'glpi_plugin_tracker_tmp_connections'; $a_drop[] = 'glpi_plugin_tracker_tmp_netports'; $a_drop[] = 'glpi_plugin_tracker_walks'; $a_drop[] = 'glpi_plugin_fusioninventory_networkequipmentips'; foreach ($a_drop as $droptable) { if (TableExists($droptable)) { $DB->query("DROP TABLE `" . $droptable . "`"); } } $migration->executeMigration(); /* * Add WakeOnLan module appear in version 2.3.0 */ $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='WAKEONLAN'"; $result = $DB->query($query); if (!$DB->numrows($result)) { $agentmodule = new PluginFusioninventoryAgentmodule(); $input = array(); $input['plugins_id'] = $plugins_id; $input['modulename'] = "WAKEONLAN"; $input['is_active'] = 0; $input['exceptions'] = exportArrayToDB(array()); $agentmodule->add($input); } /* * Add storage type if not present */ $a_storage = array(); $a_storage['partition'] = 5; $a_storage['volume groups'] = 10; $a_storage['logical volumes'] = 20; $a_storage['hard disk'] = 1; $a_storage['mount'] = 25; foreach ($a_storage as $name => $level) { $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_inventorycomputerstoragetypes`\n WHERE `name`='" . $name . "'"; $result = $DB->query($query); if (!$DB->numrows($result)) { $DB->query("INSERT INTO `glpi_plugin_fusioninventory_inventorycomputerstoragetypes`\n (`name`, `level`) VALUES\n ('" . $name . "', '" . $level . "')"); } } /* * Clean for port orphelin */ //networkports with item_type = 0 $NetworkPort = new NetworkPort(); $NetworkPort_Vlan = new NetworkPort_Vlan(); $NetworkPort_NetworkPort = new NetworkPort_NetworkPort(); $a_networkports = $NetworkPort->find("`itemtype`=''"); foreach ($a_networkports as $data) { if ($NetworkPort_NetworkPort->getFromDBForNetworkPort($data['id'])) { $NetworkPort_NetworkPort->delete($NetworkPort_NetworkPort->fields); } $a_vlans = $NetworkPort_Vlan->find("`networkports_id`='" . $data['id'] . "'"); foreach ($a_vlans as $a_vlan) { $NetworkPort_Vlan->delete($a_vlan); } $NetworkPort->delete($data, 1); } /* * Clean old ports deleted but have some informations in SNMP tables */ //echo "Clean ports purged\n"; $query_select = "SELECT `glpi_plugin_fusioninventory_networkports`.`id`\n FROM `glpi_plugin_fusioninventory_networkports`\n LEFT JOIN `glpi_networkports`\n ON `glpi_networkports`.`id` = `networkports_id`\n LEFT JOIN `glpi_networkequipments`\n ON `glpi_networkequipments`.`id` = `glpi_networkports`.`items_id`\n WHERE `glpi_networkequipments`.`id` IS NULL"; $result = $DB->query($query_select); while ($data = $DB->fetch_array($result)) { $query_del = "DELETE FROM `glpi_plugin_fusioninventory_networkports`\n WHERE `id`='" . $data["id"] . "'"; $DB->query($query_del); } /* * Clean for switch more informations again in DB when switch is purged */ //echo "Clean for switch more informations again in DB when switch is purged\n"; $query_select = "SELECT `glpi_plugin_fusioninventory_networkequipments`.`id`\n FROM `glpi_plugin_fusioninventory_networkequipments`\n LEFT JOIN `glpi_networkequipments`\n ON `glpi_networkequipments`.`id` = `networkequipments_id`\n WHERE `glpi_networkequipments`.`id` IS NULL"; $result = $DB->query($query_select); while ($data = $DB->fetch_array($result)) { $query_del = "DELETE FROM `glpi_plugin_fusioninventory_networkequipments`\n WHERE `id`='" . $data["id"] . "'"; $DB->query($query_del); } /* * Clean for printer more informations again in DB when printer is purged */ //echo "Clean for printer more informations again in DB when printer is purged\n"; $query_select = "SELECT `glpi_plugin_fusioninventory_printers`.`id`\n FROM `glpi_plugin_fusioninventory_printers`\n LEFT JOIN `glpi_printers` ON `glpi_printers`.`id` = `printers_id`\n WHERE `glpi_printers`.`id` IS NULL"; $result = $DB->query($query_select); while ($data = $DB->fetch_array($result)) { $query_del = "DELETE FROM `glpi_plugin_fusioninventory_printers`\n WHERE `id`='" . $data["id"] . "'"; $DB->query($query_del); } /* * Clean printer cartridge not deleted with the printer associated */ //echo "Clean printer cartridge not deleted with the printer associated\n"; $query_select = "SELECT `glpi_plugin_fusioninventory_printercartridges`.`id`\n FROM `glpi_plugin_fusioninventory_printercartridges`\n LEFT JOIN `glpi_printers` ON `glpi_printers`.`id` = `printers_id`\n WHERE `glpi_printers`.`id` IS NULL"; $result = $DB->query($query_select); while ($data = $DB->fetch_array($result)) { $query_del = "DELETE FROM `glpi_plugin_fusioninventory_printercartridges`\n WHERE `id`='" . $data["id"] . "'"; $DB->query($query_del); } /* * Clean printer history not deleted with printer associated */ //echo "Clean printer history not deleted with printer associated\n"; $query_select = "SELECT `glpi_plugin_fusioninventory_printerlogs`.`id`\n FROM `glpi_plugin_fusioninventory_printerlogs`\n LEFT JOIN `glpi_printers` ON `glpi_printers`.`id` = `printers_id`\n WHERE `glpi_printers`.`id` IS NULL"; $result = $DB->query($query_select); while ($data = $DB->fetch_array($result)) { $query_del = "DELETE FROM `glpi_plugin_fusioninventory_printerlogs`\n WHERE `id`='" . $data["id"] . "'"; $DB->query($query_del); } /* * Fix problem with mapping with many entries with same mapping */ $a_mapping = array(); $a_mappingdouble = array(); $query = "SELECT * FROM `glpi_plugin_fusioninventory_mappings`\n ORDER BY `id`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { if (!isset($a_mapping[$data['itemtype'] . "." . $data['name']])) { $a_mapping[$data['itemtype'] . "." . $data['name']] = $data['id']; } else { $a_mappingdouble[$data['id']] = $data['itemtype'] . "." . $data['name']; } } foreach ($a_mappingdouble as $mapping_id => $mappingkey) { $query = "UPDATE `glpi_plugin_fusioninventory_printercartridges`\n SET plugin_fusioninventory_mappings_id='" . $a_mapping[$mappingkey] . "'\n WHERE plugin_fusioninventory_mappings_id='" . $mapping_id . "'"; $DB->query($query); $query = "UPDATE `glpi_plugin_fusioninventory_networkportlogs`\n SET plugin_fusioninventory_mappings_id='" . $a_mapping[$mappingkey] . "'\n WHERE plugin_fusioninventory_mappings_id='" . $mapping_id . "'"; $DB->query($query); $query = "UPDATE `glpi_plugin_fusioninventory_configlogfields`\n SET plugin_fusioninventory_mappings_id='" . $a_mapping[$mappingkey] . "'\n WHERE plugin_fusioninventory_mappings_id='" . $mapping_id . "'"; $DB->query($query); $query = "DELETE FROM `glpi_plugin_fusioninventory_mappings`\n WHERE `id` = '" . $mapping_id . "'"; $DB->query($query); } /* * Update networports to convert itemtype 5153 to PluginFusioninventoryUnknownDevice */ $sql = "UPDATE `glpi_networkports`\n SET `itemtype`='PluginFusioninventoryUnknownDevice'\n WHERE `itemtype`='5153'"; $DB->query($sql); $sql = "UPDATE `glpi_networkports`\n SET `itemtype`='PluginFusioninventoryTask'\n WHERE `itemtype`='5166'"; $DB->query($sql); /* * Clean display preferences not used */ $sql = "DELETE FROM `glpi_displaypreferences`\n WHERE `itemtype`='5150' "; $DB->query($sql); $sql = "DELETE FROM `glpi_displaypreferences`\n WHERE `itemtype`='5160' "; $DB->query($sql); $sql = "DELETE FROM `glpi_displaypreferences`\n WHERE `itemtype`='5161' "; $DB->query($sql); $sql = "DELETE FROM `glpi_displaypreferences`\n WHERE `itemtype`='5163' "; $DB->query($sql); $sql = "DELETE FROM `glpi_displaypreferences`\n WHERE `itemtype`='5165' "; $DB->query($sql); $sql = "DELETE FROM `glpi_displaypreferences`\n WHERE `itemtype`='5190' "; $DB->query($sql); /* * Update display preferences */ changeDisplayPreference("5153", "PluginFusioninventoryUnknownDevice"); changeDisplayPreference("5158", "PluginFusioninventoryAgent"); changeDisplayPreference("PluginFusinvinventoryBlacklist", "PluginFusioninventoryInventoryComputerBlacklist"); changeDisplayPreference("5151", "PluginFusinvsnmpModel"); changeDisplayPreference("PluginFusinvsnmpModel", "PluginFusioninventorySnmpmodel"); changeDisplayPreference("5152", "PluginFusinvsnmpConfigSecurity"); changeDisplayPreference("5156", "PluginFusinvsnmpPrinterCartridge"); changeDisplayPreference("5157", "PluginFusinvsnmpNetworkEquipment"); changeDisplayPreference("PluginFusinvsnmpNetworkEquipment", "PluginFusioninventoryNetworkEquipment"); changeDisplayPreference("5159", "PluginFusinvsnmpIPRange"); changeDisplayPreference("5162", "PluginFusinvsnmpNetworkPortLog"); changeDisplayPreference("5167", "PluginFusioninventorySnmpmodelConstructDevice"); changeDisplayPreference("PluginFusinvsnmpConstructDevice", "PluginFusioninventorySnmpmodelConstructDevice"); changeDisplayPreference("5168", "PluginFusinvsnmpPrinterLog"); changeDisplayPreference("PluginFusinvsnmpPrinterLogReport", "PluginFusioninventoryPrinterLogReport"); changeDisplayPreference("PluginFusioninventoryUnknownDevice", "PluginFusioninventoryUnmanaged"); /* * Delete IP and MAC of PluginFusioninventoryUnknownDevice in displaypreference */ $queryd = "DELETE FROM `glpi_displaypreferences`\n WHERE `itemtype`='PluginFusioninventoryUnknownDevice'\n AND (`num`='11' OR `num`='12' OR `num`='16')"; $DB->query($queryd); /* * Clean in displaypreference */ $queryd = "DELETE FROM `glpi_displaypreferences`\n WHERE `itemtype`='PluginFusioninventorysnmpModel'"; $DB->query($queryd); /* * Modify displaypreference for PluginFusioninventoryPrinterLog */ $pfPrinterLogReport = new PluginFusioninventoryPrinterLog(); $a_searchoptions = $pfPrinterLogReport->getSearchOptions(); $query = "SELECT * FROM `glpi_displaypreferences`\n WHERE `itemtype` = 'PluginFusioninventoryPrinterLogReport'\n AND `users_id`='0'"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $query = "INSERT INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`,\n `users_id`)\n VALUES (NULL, 'PluginFusioninventoryPrinterLogReport', '2', '1', '0'),\n (NULL, 'PluginFusioninventoryPrinterLogReport', '18', '2', '0'),\n (NULL, 'PluginFusioninventoryPrinterLogReport', '20', '3', '0'),\n (NULL, 'PluginFusioninventoryPrinterLogReport', '5', '4', '0'),\n (NULL, 'PluginFusioninventoryPrinterLogReport', '6', '5', '0')"; $DB->query($query); } else { while ($data = $DB->fetch_array($result)) { if (!isset($a_searchoptions[$data['num']])) { $queryd = "DELETE FROM `glpi_displaypreferences`\n WHERE `id`='" . $data['id'] . "'"; $DB->query($queryd); } } } /* * Modify displaypreference for PluginFusinvsnmpNetworkEquipment */ $a_check = array(); $a_check["2"] = 1; $a_check["3"] = 2; $a_check["4"] = 3; $a_check["5"] = 4; $a_check["6"] = 5; $a_check["7"] = 6; $a_check["8"] = 7; $a_check["9"] = 8; $a_check["10"] = 9; $a_check["11"] = 10; $a_check["14"] = 11; $a_check["12"] = 12; $a_check["13"] = 13; foreach ($a_check as $num => $rank) { $query = "SELECT * FROM `glpi_displaypreferences`\n WHERE `itemtype` = 'PluginFusioninventoryNetworkEquipment'\n AND `num`='" . $num . "'\n AND `users_id`='0'"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $query = "INSERT INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`,\n `users_id`)\n VALUES (NULL, 'PluginFusioninventoryNetworkEquipment', '" . $num . "',\n '" . $rank . "', '0')"; $DB->query($query); } } $query = "SELECT * FROM `glpi_displaypreferences`\n WHERE `itemtype` = 'PluginFusioninventoryNetworkEquipment'\n AND `users_id`='0'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { if (!isset($a_check[$data['num']])) { $queryd = "DELETE FROM `glpi_displaypreferences`\n WHERE `id`='" . $data['id'] . "'"; $DB->query($queryd); } } // If no PluginFusioninventoryTaskjoblog in preferences, add them $query = "SELECT * FROM `glpi_displaypreferences`\n WHERE `itemtype` = 'PluginFusioninventoryTaskjoblog'\n AND `users_id`='0'"; $result = $DB->query($query); if ($DB->numrows($result) == 0) { $DB->query("INSERT INTO `glpi_displaypreferences`\n (`id`, `itemtype`, `num`, `rank`, `users_id`)\n VALUES (NULL,'PluginFusioninventoryTaskjoblog', '2', '1', '0'),\n (NULL,'PluginFusioninventoryTaskjoblog', '3', '2', '0'),\n (NULL,'PluginFusioninventoryTaskjoblog', '4', '3', '0'),\n (NULL,'PluginFusioninventoryTaskjoblog', '5', '4', '0'),\n (NULL,'PluginFusioninventoryTaskjoblog', '6', '5', '0'),\n (NULL,'PluginFusioninventoryTaskjoblog', '7', '6', '0'),\n (NULL,'PluginFusioninventoryTaskjoblog', '8', '7', '0')"); } // If no PluginFusioninventoryNetworkPort in preferences, add them $query = "SELECT * FROM `glpi_displaypreferences`\n WHERE `itemtype` = 'PluginFusioninventoryNetworkPort'\n AND `users_id`='0'"; $result = $DB->query($query); if ($DB->numrows($result) == 0) { $DB->query("INSERT INTO `glpi_displaypreferences`\n (`id`, `itemtype`, `num`, `rank`, `users_id`)\n VALUES (NULL,'PluginFusioninventoryNetworkPort', '3', '1', '0'),\n (NULL,'PluginFusioninventoryNetworkPort', '5', '2', '0'),\n (NULL,'PluginFusioninventoryNetworkPort', '6', '3', '0'),\n (NULL,'PluginFusioninventoryNetworkPort', '7', '4', '0'),\n (NULL,'PluginFusioninventoryNetworkPort', '8', '5', '0'),\n (NULL,'PluginFusioninventoryNetworkPort', '9', '6', '0'),\n (NULL,'PluginFusioninventoryNetworkPort', '10', '7', '0'),\n (NULL,'PluginFusioninventoryNetworkPort', '11', '8', '0'),\n (NULL,'PluginFusioninventoryNetworkPort', '12', '9', '0'),\n (NULL,'PluginFusioninventoryNetworkPort', '13', '10', '0'),\n (NULL,'PluginFusioninventoryNetworkPort', '14', '11', '0')"); } /* * Convert taskjob definition from PluginFusinvsnmpIPRange to PluginFusioninventoryIPRange * onvert taskjob definition from PluginFusinvdeployPackage to PluginFusioninventoryDeployPackage */ $query = "SELECT * FROM `glpi_plugin_fusioninventory_taskjobs`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $a_defs = importArrayFromDB($data['targets']); foreach ($a_defs as $num => $a_def) { if (key($a_def) == 'PluginFusinvsnmpIPRange') { $a_defs[$num] = array('PluginFusioninventoryIPRange' => current($a_def)); } else { if (key($a_def) == 'PluginFusinvdeployPackage') { $a_defs[$num] = array('PluginFusioninventoryDeployPackage' => current($a_def)); } } } $queryu = "UPDATE `glpi_plugin_fusioninventory_taskjobs`\n SET `targets`='" . exportArrayToDB($a_defs) . "'\n WHERE `id`='" . $data['id'] . "'"; $DB->query($queryu); } /* * Convert taskjoblogs itemtype from PluginFusinvdeployPackage to * PluginFusioninventoryDeployPackage */ $query = "UPDATE `glpi_plugin_fusioninventory_taskjoblogs` " . "SET `itemtype`='PluginFusioninventoryDeployPackage'" . "WHERE `itemtype`='PluginFusinvdeployPackage'"; $result = $DB->query($query); /* * Convert taskjobstates itemtype from PluginFusinvdeployPackage to * PluginFusioninventoryDeployPackage */ $query = "UPDATE `glpi_plugin_fusioninventory_taskjobstates` " . "SET `itemtype`='PluginFusioninventoryDeployPackage'" . "WHERE `itemtype` = 'PluginFusinvdeployPackage'"; $result = $DB->query($query); /* * Convert taskjob action from PluginFusinvdeployGroup to PluginFusioninventoryDeployGroup */ $query = "SELECT * FROM `glpi_plugin_fusioninventory_taskjobs`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $a_defs = importArrayFromDB($data['actors']); foreach ($a_defs as $num => $a_def) { if (key($a_def) == 'PluginFusinvdeployGroup') { $a_defs[$num] = array('PluginFusioninventoryDeployGroup' => current($a_def)); } } $queryu = "UPDATE `glpi_plugin_fusioninventory_taskjobs`\n SET `actors`='" . exportArrayToDB($a_defs) . "'\n WHERE `id`='" . $data['id'] . "'"; $DB->query($queryu); } /* * Convert itemtype from glpi_plugin_fusioninventory_unknowndevices to * PluginFusioninventoryUnmanaged */ $tables = array('glpi_networkports', 'glpi_logs', 'glpi_plugin_fusioninventory_ignoredimportdevices'); foreach ($tables as $table) { $query = "UPDATE `" . $table . "` " . "SET `itemtype`='PluginFusioninventoryUnmanaged'" . "WHERE `itemtype` = 'PluginFusioninventoryUnknowndevice'"; $DB->query($query); } $query = "UPDATE `glpi_ipaddresses` " . "SET `mainitemtype`='PluginFusioninventoryUnmanaged'" . "WHERE `mainitemtype` = 'PluginFusioninventoryUnknowndevice'"; $DB->query($query); /* * Update rules */ $query = "UPDATE glpi_rules SET `sub_type`='PluginFusioninventoryInventoryRuleImport'\n WHERE `sub_type`='PluginFusioninventoryRuleImportEquipment'"; $DB->query($query); $query = "SELECT * FROM `glpi_rules`\n WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $querya = "UPDATE glpi_ruleactions SET `value`='1'\n WHERE `rules_id`='" . $data['id'] . "'\n AND `value`='0'\n AND `field`='_fusion'"; $DB->query($querya); } $query = "UPDATE glpi_rules SET `sub_type`='PluginFusioninventoryInventoryRuleEntity'\n WHERE `sub_type`='PluginFusinvinventoryRuleEntity'"; $DB->query($query); /* * Add default rules */ if (TableExists("glpi_plugin_tracker_config_discovery")) { $migration->displayMessage("Create rules"); $pfSetup = new PluginFusioninventorySetup(); $pfSetup->initRules(); } // If no rules, add them if (countElementsInTable('glpi_rules', "`sub_type`='PluginFusioninventoryInventoryRuleImport'") == 0) { $migration->displayMessage("Create rules"); $pfSetup = new PluginFusioninventorySetup(); $pfSetup->initRules(); } // Add peripheral rules (in first in rule list) when use it since 0.85 $query = "DELETE FROM `glpi_plugin_fusioninventory_configs`" . " WHERE `type`='import_peripheral' "; $DB->query($query); $query = "UPDATE `glpi_rules` " . " SET `ranking` = `ranking`+3" . " WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport' "; $ranking = 0; // Create rule for : Peripheral + serial $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection(); $input = array(); $input['is_active'] = 1; $input['name'] = 'Peripheral serial'; $input['match'] = 'AND'; $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport'; $input['ranking'] = $ranking; $rule_id = $rulecollection->add($input); // Add criteria $rule = $rulecollection->getRuleClass(); $rulecriteria = new RuleCriteria(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "serial"; $input['pattern'] = 1; $input['condition'] = 10; $rulecriteria->add($input); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "serial"; $input['pattern'] = 1; $input['condition'] = 8; $rulecriteria->add($input); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "itemtype"; $input['pattern'] = 'Peripheral'; $input['condition'] = 0; $rulecriteria->add($input); // Add action $ruleaction = new RuleAction(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['action_type'] = 'assign'; $input['field'] = '_fusion'; $input['value'] = '1'; $ruleaction->add($input); $ranking++; // Create rule for : Peripheral import $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection(); $input = array(); $input['is_active'] = 1; $input['name'] = 'Peripheral import'; $input['match'] = 'AND'; $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport'; $input['ranking'] = $ranking; $rule_id = $rulecollection->add($input); // Add criteria $rule = $rulecollection->getRuleClass(); $rulecriteria = new RuleCriteria(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "itemtype"; $input['pattern'] = 'Peripheral'; $input['condition'] = 0; $rulecriteria->add($input); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "serial"; $input['pattern'] = 1; $input['condition'] = 8; $rulecriteria->add($input); // Add action $ruleaction = new RuleAction(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['action_type'] = 'assign'; $input['field'] = '_fusion'; $input['value'] = '1'; $ruleaction->add($input); $ranking++; // Create rule for : Peripheral ignore import $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection(); $input = array(); $input['is_active'] = 1; $input['name'] = 'Peripheral ignore import'; $input['match'] = 'AND'; $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport'; $input['ranking'] = $ranking; $rule_id = $rulecollection->add($input); // Add criteria $rule = $rulecollection->getRuleClass(); $rulecriteria = new RuleCriteria(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "itemtype"; $input['pattern'] = 'Peripheral'; $input['condition'] = 0; $rulecriteria->add($input); // Add action $ruleaction = new RuleAction(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['action_type'] = 'assign'; $input['field'] = '_ignore_import'; $input['value'] = '1'; $ruleaction->add($input); // Add monitor rules (in first in rule list) when use it since 0.85 $query = "DELETE FROM `glpi_plugin_fusioninventory_configs`" . " WHERE `type`='import_monitor' "; $DB->query($query); $query = "UPDATE `glpi_rules` " . " SET `ranking` = `ranking`+3" . " WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport' "; $ranking = 0; // Create rule for : Monitor + serial $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection(); $input = array(); $input['is_active'] = 1; $input['name'] = 'Monitor serial'; $input['match'] = 'AND'; $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport'; $input['ranking'] = $ranking; $rule_id = $rulecollection->add($input); // Add criteria $rule = $rulecollection->getRuleClass(); $rulecriteria = new RuleCriteria(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "serial"; $input['pattern'] = 1; $input['condition'] = 10; $rulecriteria->add($input); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "serial"; $input['pattern'] = 1; $input['condition'] = 8; $rulecriteria->add($input); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "itemtype"; $input['pattern'] = 'Monitor'; $input['condition'] = 0; $rulecriteria->add($input); // Add action $ruleaction = new RuleAction(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['action_type'] = 'assign'; $input['field'] = '_fusion'; $input['value'] = '1'; $ruleaction->add($input); $ranking++; // Create rule for : Monitor import $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection(); $input = array(); $input['is_active'] = 1; $input['name'] = 'Monitor import'; $input['match'] = 'AND'; $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport'; $input['ranking'] = $ranking; $rule_id = $rulecollection->add($input); // Add criteria $rule = $rulecollection->getRuleClass(); $rulecriteria = new RuleCriteria(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "itemtype"; $input['pattern'] = 'Monitor'; $input['condition'] = 0; $rulecriteria->add($input); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "serial"; $input['pattern'] = 1; $input['condition'] = 8; $rulecriteria->add($input); // Add action $ruleaction = new RuleAction(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['action_type'] = 'assign'; $input['field'] = '_fusion'; $input['value'] = '1'; $ruleaction->add($input); $ranking++; // Create rule for : Monitor ignore import $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection(); $input = array(); $input['is_active'] = 1; $input['name'] = 'Monitor ignore import'; $input['match'] = 'AND'; $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport'; $input['ranking'] = $ranking; $rule_id = $rulecollection->add($input); // Add criteria $rule = $rulecollection->getRuleClass(); $rulecriteria = new RuleCriteria(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['criteria'] = "itemtype"; $input['pattern'] = 'Monitor'; $input['condition'] = 0; $rulecriteria->add($input); // Add action $ruleaction = new RuleAction(get_class($rule)); $input = array(); $input['rules_id'] = $rule_id; $input['action_type'] = 'assign'; $input['field'] = '_ignore_import'; $input['value'] = '1'; $ruleaction->add($input); // Add printer rules (in first in rule list) when use it since 0.85 $query = "DELETE FROM `glpi_plugin_fusioninventory_configs`" . " WHERE `type`='import_printer' "; /* * Manage configuration of plugin */ $config = new PluginFusioninventoryConfig(); $pfSetup = new PluginFusioninventorySetup(); $users_id = $pfSetup->createFusionInventoryUser(); $a_input = array(); $a_input['ssl_only'] = 0; $a_input['delete_task'] = 20; $a_input['inventory_frequence'] = 24; $a_input['agent_port'] = 62354; $a_input['extradebug'] = 0; $a_input['users_id'] = $users_id; $a_input['agents_old_days'] = 0; $config->addValues($a_input, FALSE); // $DB->query("DELETE FROM `glpi_plugin_fusioninventory_configs` // WHERE `plugins_id`='0'"); // $query = "SELECT * FROM `glpi_plugin_fusioninventory_configs` // WHERE `type`='version' // LIMIT 1, 10"; // $result = $DB->query($query); // while ($data=$DB->fetch_array($result)) { // $config->delete($data); // } $a_input = array(); $a_input['version'] = PLUGIN_FUSIONINVENTORY_VERSION; $config->addValues($a_input, TRUE); $a_input = array(); $a_input['ssl_only'] = 0; if (isset($prepare_Config['ssl_only'])) { $a_input['ssl_only'] = $prepare_Config['ssl_only']; } $a_input['delete_task'] = 20; $a_input['inventory_frequence'] = 24; $a_input['agent_port'] = 62354; $a_input['extradebug'] = 0; $a_input['users_id'] = 0; //Deploy configuration options $a_input['server_upload_path'] = Toolbox::addslashes_deep(implode(DIRECTORY_SEPARATOR, array(GLPI_PLUGIN_DOC_DIR, 'fusioninventory', 'upload'))); $a_input['alert_winpath'] = 1; $a_input['server_as_mirror'] = 1; $config->addValues($a_input, FALSE); $pfSetup = new PluginFusioninventorySetup(); $users_id = $pfSetup->createFusionInventoryUser(); $query = "UPDATE `glpi_plugin_fusioninventory_configs`\n SET `value`='" . $users_id . "'\n WHERE `type`='users_id'"; $DB->query($query); // Update fusinvinventory _config values to this plugin $input = array(); $input['import_software'] = 1; $input['import_volume'] = 1; $input['import_antivirus'] = 1; $input['import_registry'] = 1; $input['import_process'] = 1; $input['import_vm'] = 1; $input['component_processor'] = 1; $input['component_memory'] = 1; $input['component_harddrive'] = 1; $input['component_networkcard'] = 1; $input['component_graphiccard'] = 1; $input['component_soundcard'] = 1; $input['component_drive'] = 1; $input['component_networkdrive'] = 1; $input['component_control'] = 1; $input['states_id_default'] = 0; $input['location'] = 0; $input['group'] = 0; $input['component_networkcardvirtual'] = 1; $config->addValues($input, FALSE); // Add new config values if not added $input = $config->initConfigModule(TRUE); foreach ($input as $name => $value) { $a_conf = $config->find("`type`='" . $name . "'"); if (count($a_conf) == 0) { $config->add(array('type' => $name, 'value' => $value)); } } $migration->displayMessage("Clean printers"); /* * Remove / at the end of printers (bugs in older versions of agents. */ $printer = new Printer(); $query = "SELECT * FROM `glpi_printers`\n WHERE `serial` LIKE '%/' "; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $cleanSerial = preg_replace('/\\/$/', '', $data['serial']); $querynb = "SELECT * FROM `glpi_printers`\n WHERE `serial`='" . $cleanSerial . "'\n LIMIT 1"; $resultnb = $DB->query($querynb); if ($DB->numrows($resultnb) == '0') { $input = array(); $input['id'] = $data['id']; $input["serial"] = $cleanSerial; $printer->update($input); } } /* * Update blacklist */ $input = array(); $input['03000200-0400-0500-0006-000700080009'] = '2'; $input['6AB5B300-538D-1014-9FB5-B0684D007B53'] = '2'; $input['01010101-0101-0101-0101-010101010101'] = '2'; $input['20:41:53:59:4e:ff'] = '3'; $input['02:00:4e:43:50:49'] = '3'; $input['e2:e6:16:20:0a:35'] = '3'; $input['d2:0a:2d:a0:04:be'] = '3'; $input['00:a0:c6:00:00:00'] = '3'; $input['d2:6b:25:2f:2c:e7'] = '3'; $input['33:50:6f:45:30:30'] = '3'; $input['0a:00:27:00:00:00'] = '3'; $input['00:50:56:C0:00:01'] = '3'; $input['00:50:56:C0:00:02'] = '3'; $input['00:50:56:C0:00:03'] = '3'; $input['00:50:56:C0:00:04'] = '3'; $input['00:50:56:C0:00:08'] = '3'; $input['FE:FF:FF:FF:FF:FF'] = '3'; $input['00:00:00:00:00:00'] = '3'; $input['00:0b:ca:fe:00:00'] = '3'; $input['02:80:37:EC:02:00'] = '3'; $input['MB-1234567890'] = '1'; $input['Not Specified'] = '1'; $input['OEM_Serial'] = '1'; $input['SystemSerialNumb'] = '1'; $input['Not'] = '2'; foreach ($input as $value => $type) { $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputerblacklists`\n WHERE `plugin_fusioninventory_criterium_id`='" . $type . "'\n AND `value`='" . $value . "'"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $query = "INSERT INTO `glpi_plugin_fusioninventory_inventorycomputerblacklists`\n (`plugin_fusioninventory_criterium_id`, `value`) VALUES\n ( '" . $type . "', '" . $value . "')"; $DB->query($query); } } $migration->displayMessage("Add Crontasks"); /* * Add Crontask if not exist */ $crontask = new CronTask(); if ($crontask->getFromDBbyName('PluginFusioninventoryTaskjob', 'taskscheduler')) { $crontask->fields['itemtype'] = 'PluginFusioninventoryTask'; $crontask->updateInDB(array('itemtype')); } if (!$crontask->getFromDBbyName('PluginFusioninventoryTask', 'taskscheduler')) { CronTask::Register('PluginFusioninventoryTask', 'taskscheduler', '60', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30)); } if ($crontask->getFromDBbyName('PluginFusioninventoryTaskjobstate', 'cleantaskjob') and $crontask->getFromDBbyName('PluginFusioninventoryTaskjobstatus', 'cleantaskjob')) { $crontask->getFromDBbyName('PluginFusioninventoryTaskjobstatus', 'cleantaskjob'); $crontask->delete($crontask->fields); } if ($crontask->getFromDBbyName('PluginFusioninventoryTaskjobstatus', 'cleantaskjob')) { $query = "UPDATE `glpi_crontasks` SET `itemtype`='PluginFusioninventoryTaskjobstate'\n WHERE `itemtype`='PluginFusioninventoryTaskjobstatus'"; $DB->query($query); } if (!$crontask->getFromDBbyName('PluginFusioninventoryTaskjobstate', 'cleantaskjob')) { Crontask::Register('PluginFusioninventoryTaskjobstate', 'cleantaskjob', 3600 * 24, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30)); } if ($crontask->getFromDBbyName('PluginFusinvsnmpNetworkPortLog', 'cleannetworkportlogs')) { $crontask->delete($crontask->fields); } if (!$crontask->getFromDBbyName('PluginFusioninventoryNetworkPortLog', 'cleannetworkportlogs')) { Crontask::Register('PluginFusioninventoryNetworkPortLog', 'cleannetworkportlogs', 3600 * 24, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30)); } if ($crontask->getFromDBbyName('PluginFusioninventoryConfigurationManagement', 'checkdevices')) { $crontask->delete($crontask->fields); } if (!$crontask->getFromDBbyName('PluginFusioninventoryAgent', 'cleanoldagents')) { Crontask::Register('PluginFusioninventoryAgent', 'cleanoldagents', 86400, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'hourmin' => 22, 'hourmax' => 6, 'comment' => 'Clean agents not contacted since xxx days')); } /* * Update task's agents list from dynamic group periodically in order to automatically target new * computer. */ if (!$crontask->getFromDBbyName('PluginFusioninventoryTaskjob', 'updatedynamictasks')) { CronTask::Register('PluginFusioninventoryTaskjob', 'updatedynamictasks', '60', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'state' => 0)); } if (!$crontask->getFromDBbyName('PluginFusioninventoryAgentWakeup', 'wakeupAgents')) { Crontask::Register('PluginFusioninventoryAgentWakeup', 'wakeupAgents', 120, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'comment' => 'Wake agents ups')); } /** * Add field to manage which group can be refreshed by updatedynamictasks crontask */ if (!FieldExists('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'can_update_group')) { $migration->addField('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'can_update_group', 'bool'); $migration->addKey('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'can_update_group'); $migration->migrationOneTable('glpi_plugin_fusioninventory_deploygroups_dynamicdatas'); } // $pfIgnoredimportdevice = new PluginFusioninventoryIgnoredimportdevice(); // $pfIgnoredimportdevice->install(); //Change static & dynamic structure to fit the GLPI framework $migration->changeField('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'groups_id', 'plugin_fusioninventory_deploygroups_id', 'integer'); $migration->migrationOneTable('glpi_plugin_fusioninventory_deploygroups_dynamicdatas'); $migration->changeField('glpi_plugin_fusioninventory_deploygroups_staticdatas', 'groups_id', 'plugin_fusioninventory_deploygroups_id', 'integer'); $migration->migrationOneTable('glpi_plugin_fusioninventory_deploygroups_staticdatas'); // Delete data in glpi_logs(agent problem => ticket http://forge.fusioninventory.org/issues/1546) // ** Token $query = "DELETE FROM `glpi_logs`\n WHERE `itemtype`='PluginFusioninventoryAgent'\n AND `id_search_option`='9'"; $DB->query($query); // ** Last contact $query = "DELETE FROM `glpi_logs`\n WHERE `itemtype`='PluginFusioninventoryAgent'\n AND `id_search_option`='4'"; $DB->query($query); // ** Version $query = "DELETE FROM `glpi_logs`\n WHERE `itemtype`='PluginFusioninventoryAgent'\n AND `id_search_option`='8'\n AND `old_value`=`new_value`"; $DB->query($query); /* * Manage devices with is_dynamic */ $query = "SELECT * FROM `glpi_plugin_fusioninventory_networkequipments`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $DB->query("UPDATE `glpi_networkequipments` SET `is_dynamic`='1'\n WHERE `id`='" . $data['networkequipments_id'] . "'"); } $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercomputers`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $DB->query("UPDATE `glpi_computers` SET `is_dynamic`='1'\n WHERE `id`='" . $data['computers_id'] . "'"); } $query = "SELECT * FROM `glpi_plugin_fusioninventory_printers`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $DB->query("UPDATE `glpi_printers` SET `is_dynamic`='1'\n WHERE `id`='" . $data['printers_id'] . "'"); } // Update networkports types $pfNetworkporttype = new PluginFusioninventoryNetworkporttype(); $pfNetworkporttype->init(); if (TableExists('glpi_plugin_fusioninventory_profiles')) { //Migrate rights to the new system introduction in GLPI 0.85 PluginFusioninventoryProfile::migrateProfiles(); //Drop old table $migration->dropTable('glpi_plugin_fusioninventory_profiles'); } //Create first access to the current profile is needed if (isset($_SESSION['glpiactiveprofile'])) { PluginFusioninventoryProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); } // Define lastup field of fusion networkports $query = "SELECT * FROM `glpi_plugin_fusioninventory_mappings`\n WHERE `name`='ifstatus'\n LIMIT 1"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $query_np = "SELECT * FROM `glpi_plugin_fusioninventory_networkports`"; $result_np = $DB->query($query_np); while ($data_np = $DB->fetch_array($result_np)) { $query_nplog = "SELECT * FROM `glpi_plugin_fusioninventory_networkportlogs`\n WHERE `networkports_id`='" . $data_np['networkports_id'] . "'\n AND `plugin_fusioninventory_mappings_id`='" . $data['id'] . "'\n ORDER BY `date_mod` DESC\n LIMIT 1"; $result_nplog = $DB->query($query_nplog); while ($data_nplog = $DB->fetch_array($result_nplog)) { $DB->query("UPDATE `glpi_plugin_fusioninventory_networkports`\n SET `lastup`='" . $data_nplog['date_mod'] . "'\n WHERE `id`='" . $data_np['id'] . "'"); } } } //Migrate search params for dynamic groups doDynamicDataSearchParamsMigration(); }
You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkRight("networking", "r"); if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $netdevice = new NetworkEquipment(); if (isset($_POST["add"])) { $netdevice->check(-1, 'w', $_POST); $newID = $netdevice->add($_POST); Event::log($newID, "networkequipment", 4, "inventory", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])); Html::back(); } else { if (isset($_POST["delete"])) { $netdevice->check($_POST["id"], 'd'); $netdevice->delete($_POST); Event::log($_POST["id"], "networkequipment", 4, "inventory", sprintf(__('%s deletes an item'), $_SESSION["glpiname"])); $netdevice->redirectToList(); } else { if (isset($_POST["restore"])) { $netdevice->check($_POST["id"], 'd'); $netdevice->restore($_POST);