/** * @test */ public function PrinterSnmpExtension() { global $DB; $DB->connect(); $pfPrinter = new PluginFusioninventoryPrinter(); $a_printer = current($pfPrinter->find("`printers_id`='1'", "", 1)); unset($a_printer['last_fusioninventory_update']); $a_reference = array('id' => '1', 'printers_id' => '1', 'sysdescr' => 'HP ETHERNET MULTI-ENVIRONMENT', 'plugin_fusioninventory_configsecurities_id' => '0', 'frequence_days' => '1', 'serialized_inventory' => NULL); $this->assertEquals($a_reference, $a_printer); }
/** * Function to update Printer * * @param array $a_inventory data fron agent inventory * @param id $items_id id of the printer * * @return nothing */ function updatePrinter($a_inventory, $items_id) { global $DB; $printer = new Printer(); $pfPrinter = new PluginFusioninventoryPrinter(); $printer->getFromDB($items_id); if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = $printer->fields['entities_id']; } if (!isset($_SESSION['glpiactiveentities'])) { $_SESSION['glpiactiveentities'] = array($printer->fields['entities_id']); } if (!isset($_SESSION['glpiactive_entity'])) { $_SESSION['glpiactive_entity'] = $printer->fields['entities_id']; } // * Printer $db_printer = $printer->fields; $a_lockable = PluginFusioninventoryLock::getLockFields('glpi_printers', $items_id); $a_ret = PluginFusioninventoryToolbox::checkLock($a_inventory['Printer'], $db_printer, $a_lockable); $a_inventory['Printer'] = $a_ret[0]; $input = $a_inventory['Printer']; $input['id'] = $items_id; $printer->update($input); // * Printer fusion (ext) $db_printer = array(); $query = "SELECT *\n FROM `" . getTableForItemType("PluginFusioninventoryPrinter") . "`\n WHERE `printers_id` = '{$items_id}'"; $result = $DB->query($query); while ($data = $DB->fetch_assoc($result)) { foreach ($data as $key => $value) { $db_printer[$key] = Toolbox::addslashes_deep($value); } } if (count($db_printer) == '0') { // Add $a_inventory['PluginFusioninventoryPrinter']['printers_id'] = $items_id; $pfPrinter->add($a_inventory['PluginFusioninventoryPrinter']); } else { // Update $idtmp = $db_printer['id']; unset($db_printer['id']); unset($db_printer['printers_id']); unset($db_printer['plugin_fusioninventory_configsecurities_id']); $a_ret = PluginFusioninventoryToolbox::checkLock($a_inventory['PluginFusioninventoryPrinter'], $db_printer); $a_inventory['PluginFusioninventoryPrinter'] = $a_ret[0]; $input = $a_inventory['PluginFusioninventoryPrinter']; $input['id'] = $idtmp; $pfPrinter->update($input); } // * Ports $this->importPorts($a_inventory, $items_id); // Page counters $this->importPageCounters($a_inventory['pagecounters'], $items_id); // Cartridges $this->importCartridges($a_inventory['cartridge'], $items_id); }
static function showInfo($item) { // Manage locks pictures PluginFusioninventoryLock::showLockIcon('Printer'); $pfPrinter = new PluginFusioninventoryPrinter(); $a_printerextend = current($pfPrinter->find("`printers_id`='" . $item->getID() . "'", "", 1)); if (empty($a_printerextend)) { return; } echo '<table class="tab_glpi" width="100%">'; echo '<tr>'; echo '<th colspan="2">' . __('FusionInventory', 'fusioninventory') . '</th>'; echo '</tr>'; echo '<tr class="tab_bg_1">'; echo '<td>'; echo __('Last inventory', 'fusioninventory'); echo '</td>'; echo '<td>'; echo Html::convDateTime($a_printerextend['last_fusioninventory_update']); echo '</td>'; echo '</tr>'; echo '<tr class="tab_bg_1">'; echo '<td>'; echo __('Type'); echo '</td>'; echo '<td>'; echo "SNMP"; echo '</td>'; echo '</tr>'; echo "</table>"; }
function run($jobstate) { $pfAgent = new PluginFusioninventoryAgent(); $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $pfConfigSecurity = new PluginFusioninventoryConfigSecurity(); $pfToolbox = new PluginFusioninventoryToolbox(); $current = $jobstate; $pfAgent->getFromDB($current->fields['plugin_fusioninventory_agents_id']); $ip = current(PluginFusioninventoryToolbox::getIPforDevice($jobstate->fields['itemtype'], $jobstate->fields['items_id'])); if ($ip == '') { $pfTaskjobstate->changeStatusFinish($jobstate->fields['id'], $jobstate->fields['items_id'], $jobstate->fields['itemtype'], 1, "Device have no ip"); } else { $sxml_option = $this->message->addChild('OPTION'); $sxml_option->addChild('NAME', 'SNMPQUERY'); $sxml_param = $sxml_option->addChild('PARAM'); $sxml_param->addAttribute('THREADS_QUERY', $pfAgent->fields["threads_networkinventory"]); $sxml_param->addAttribute('TIMEOUT', $pfAgent->fields["timeout_networkinventory"]); $sxml_param->addAttribute('PID', $current->fields['id']); $changestate = 0; $taskjobstatedatas = $jobstate->fields; $sxml_device = $sxml_option->addChild('DEVICE'); $a_extended = array('plugin_fusioninventory_configsecurities_id' => 0); if ($jobstate->fields['itemtype'] == 'Printer') { $sxml_device->addAttribute('TYPE', 'PRINTER'); $pfPrinter = new PluginFusioninventoryPrinter(); $a_extended = current($pfPrinter->find("`printers_id`='" . $jobstate->fields['items_id'] . "'", '', 1)); } else { if ($jobstate->fields['itemtype'] == 'NetworkEquipment') { $sxml_device->addAttribute('TYPE', 'NETWORKING'); $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment(); $a_extended = current($pfNetworkEquipment->find("`networkequipments_id`='" . $jobstate->fields['items_id'] . "'", '', 1)); } } $sxml_device->addAttribute('ID', $jobstate->fields['items_id']); $sxml_device->addAttribute('IP', $ip); $sxml_device->addAttribute('AUTHSNMP_ID', $a_extended['plugin_fusioninventory_configsecurities_id']); if ($changestate == '0') { $pfTaskjobstate->changeStatus($taskjobstatedatas['id'], 1); $pfTaskjoblog->addTaskjoblog($taskjobstatedatas['id'], '0', 'PluginFusioninventoryAgent', '1', $pfAgent->fields["threads_networkinventory"] . ' threads', $pfAgent->fields["timeout_networkinventory"] . ' timeout'); $changestate = $pfTaskjobstate->fields['id']; } else { $pfTaskjobstate->changeStatusFinish($taskjobstatedatas['id'], $taskjobstatedatas['items_id'], $taskjobstatedatas['itemtype'], 0, "Merged with " . $changestate); } $snmpauthlist = $pfConfigSecurity->find(); if (count($snmpauthlist)) { foreach ($snmpauthlist as $snmpauth) { $pfToolbox->addAuth($sxml_option, $snmpauth['id']); } } } return $this->message; }
/** * @test */ public function PrinterToInventoryWithoutIP() { self::restore_database(); $printer = new Printer(); $networkport = new NetworkPort(); $networkName = new NetworkName(); $pfPrinter = new PluginFusioninventoryPrinter(); $pfTask = new PluginFusioninventoryTask(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $computer = new Computer(); $pfAgent = new PluginFusioninventoryAgent(); $communication = new PluginFusioninventoryCommunication(); // 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 printer $input = array('name' => 'printer 001', 'entities_id' => 0); $printers_id = $printer->add($input); // Add port $networkports_id = $networkport->add(array('itemtype' => 'Printer', 'instantiation_type' => 'NetworkPortEthernet', 'items_id' => $printers_id, 'entities_id' => 0)); $networknames_id = $networkName->add(array('entities_id' => 0, 'itemtype' => 'NetworkPort', 'items_id' => $networkports_id)); $input = array('printers_id' => 1, 'plugin_fusioninventory_configsecurities_id' => 2); $pfPrinter->add($input); // Add task // 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' => '[{"Printer":"' . $printers_id . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"1"}]'); $pfTaskjob->add($input); PluginFusioninventoryTask::cronTaskscheduler(); $data = $pfTask->getJoblogs(array(1)); // Task is prepared // Agent will get data $communication->getTaskAgent(1); $message = $communication->getMessage(); $json = json_encode($message); $array = json_decode($json, TRUE); $ref = array(); $this->assertEquals($ref, $array, 'XML of SNMP inventory task'); }
@author David Durieux @co-author @copyright Copyright (c) 2010-2014 FusionInventory team @license AGPL License 3.0 or (at your option) any later version http://www.gnu.org/licenses/agpl-3.0-standalone.html @link http://www.fusioninventory.org/ @link http://forge.fusioninventory.org/projects/fusioninventory-for-glpi/ @since 2010 ------------------------------------------------------------------------ */ include "../../../inc/includes.php"; Session::checkRight('plugin_fusioninventory_printer', READ); if (isset($_POST['update']) && isset($_POST['id'])) { Session::checkRight('plugin_fusioninventory_printer', UPDATE); $plugin_fusioninventory_printer = new PluginFusioninventoryPrinter(); $_POST['printers_id'] = $_POST['id']; unset($_POST['id']); $query = "SELECT *\n FROM `glpi_plugin_fusioninventory_printers`\n WHERE `printers_id`='" . $_POST['printers_id'] . "' "; $result = $DB->query($query); if ($DB->numrows($result) == "0") { $queryInsert = "INSERT INTO `glpi_plugin_fusioninventory_printers`(`printers_id`)\n VALUES('" . $_POST['printers_id'] . "');"; $DB->query($queryInsert); $query = "SELECT *\n FROM `glpi_plugin_fusioninventory_printers`\n WHERE `printers_id`='" . $_POST['printers_id'] . "' "; $result = $DB->query($query); } $data = $DB->fetch_assoc($result); $_POST['id'] = $data['id']; $plugin_fusioninventory_printer->update($_POST); } $arg = "";
function getSerialized_InventoryArray($itemtype, $items_id) { $item_extend = new PluginFusioninventoryLock(); if ($itemtype == 'Computer') { $item_extend = new PluginFusioninventoryInventoryComputerComputer(); } else { if ($itemtype == 'NetworkEquipment') { $item_extend = new PluginFusioninventoryNetworkEquipment(); } else { if ($itemtype == 'Printer') { $item_extend = new PluginFusioninventoryPrinter(); } } } if ($item_extend->getType() != 'PluginFusioninventoryLock') { // Get device info + field 'serialized_inventory' $a_lists = $item_extend->find("`" . getForeignKeyFieldForItemType($itemtype) . "`='" . $items_id . "'", "", 1); if (count($a_lists) == 1) { $a_list = current($a_lists); if (!empty($a_list['serialized_inventory'])) { $serialized = unserialize(gzuncompress($a_list['serialized_inventory'])); return $serialized[$itemtype]; } } } return array(); }
/** * 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); }