/** * @test */ public function prepareTask2() { global $DB; // Verify prepare a network discovery task $DB->connect(); $pfTask = new PluginFusioninventoryTask(); $data = $pfTask->getJoblogs(array(2)); $ref = array(3 => 'computer3'); $this->assertEquals($ref, $data['agents']); }
static function board() { global $DB; // Computers $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercomputers`" . " LEFT JOIN `glpi_computers` " . " ON (`glpi_plugin_fusioninventory_inventorycomputercomputers`.`id`=`glpi_computers`.`id` " . " AND `glpi_computers`.`is_deleted`='0')" . " WHERE `glpi_computers`.`id` IS NOT NULL"; $result = $DB->query($query); $fusionComputers = $DB->numrows($result); $allComputers = countElementsInTable('glpi_computers', "`is_deleted`='0' AND `is_template`='0'"); $dataComputer = array(); $dataComputer[] = array('key' => 'FusionInventory computers : ' . $fusionComputers, 'y' => $fusionComputers, 'color' => '#3dff7d'); $dataComputer[] = array('key' => 'Other computers : ' . ($allComputers - $fusionComputers), 'y' => $allComputers - $fusionComputers, 'color' => "#dedede"); // SNMP $networkequipment = countElementsInTable('glpi_plugin_fusioninventory_networkequipments'); $printer = countElementsInTable('glpi_plugin_fusioninventory_printers'); $dataSNMP = array(); $dataSNMP[] = array('key' => 'NetworkEquipments (SNMP) : ' . $networkequipment, 'y' => $networkequipment, 'color' => '#3d94ff'); $dataSNMP[] = array('key' => 'Printers (SNMP) : ' . $printer, 'y' => $printer, 'color' => '#3dff7d'); // switches ports $allSwitchesPortSNMP = countElementsInTable('glpi_plugin_fusioninventory_networkports'); $query = "SELECT `glpi_networkports`.`id` FROM `glpi_networkports`\n LEFT JOIN `glpi_plugin_fusioninventory_networkports`\n ON `glpi_plugin_fusioninventory_networkports`.`networkports_id` = `glpi_networkports`.`id`\n LEFT JOIN glpi_networkports_networkports\n ON (`networkports_id_1`=`glpi_networkports`.`id`\n OR `networkports_id_2`=`glpi_networkports`.`id`)\n WHERE `glpi_plugin_fusioninventory_networkports`.`id` IS NOT NULL\n AND `glpi_networkports_networkports`.`id` IS NOT NULL"; $result = $DB->query($query); $networkPortsLinked = $DB->numrows($result); $dataPortL = array(); $dataPortL[] = array('key' => 'SNMP switch network ports linked : ' . $networkPortsLinked, 'y' => $networkPortsLinked, 'color' => '#3dff7d'); $dataPortL[] = array('key' => 'SNMP switch network ports not linked : ' . ($allSwitchesPortSNMP - $networkPortsLinked), 'y' => $allSwitchesPortSNMP - $networkPortsLinked, 'color' => '#dedede'); // Ports connected at last SNMP inventory $networkPortsConnected = countElementsInTable('glpi_plugin_fusioninventory_networkports', "`ifstatus`='1' OR `ifstatus`='up'"); $dataPortC = array(); $dataPortC[] = array('key' => 'Ports connected : ' . $networkPortsConnected, 'y' => $networkPortsConnected, 'color' => '#3dff7d'); $dataPortC[] = array('key' => 'Ports not connected : ' . ($allSwitchesPortSNMP - $networkPortsConnected), 'y' => $allSwitchesPortSNMP - $networkPortsConnected, 'color' => '#dedede'); // Number of computer inventories in last hour, 6 hours, 24 hours $dataInventory = PluginFusioninventoryInventoryComputerStat::getLastHours(); // Deploy $query = "SELECT `plugin_fusioninventory_tasks_id` FROM glpi_plugin_fusioninventory_taskjobs" . " WHERE method LIKE '%deploy%'" . " GROUP BY `plugin_fusioninventory_tasks_id`"; $result = $DB->query($query); $a_tasks = array(); while ($data = $DB->fetch_array($result)) { $a_tasks[] = $data['plugin_fusioninventory_tasks_id']; } $pfTask = new PluginFusioninventoryTask(); $data = $pfTask->getJoblogs($a_tasks); $dataDeploy = array(); $dataDeploy[0] = array('key' => 'Prepared and waiting', 'y' => 0, 'color' => '#efefef'); $dataDeploy[1] = array('key' => 'Running', 'y' => 0, 'color' => '#aaaaff'); $dataDeploy[2] = array('key' => 'Successfull', 'y' => 0, 'color' => '#aaffaa'); $dataDeploy[3] = array('key' => 'In error', 'y' => 0, 'color' => '#ff0000'); foreach ($data['tasks'] as $lev1) { foreach ($lev1['jobs'] as $lev2) { foreach ($lev2['targets'] as $lev3) { $dataDeploy[2]['y'] += count($lev3['counters']['agents_success']); $dataDeploy[3]['y'] += count($lev3['counters']['agents_error']); $dataDeploy[0]['y'] += count($lev3['counters']['agents_prepared']); $dataDeploy[1]['y'] += count($lev3['counters']['agents_running']); } } } for ($k = 0; $k < 4; $k++) { $dataDeploy[$k]['key'] .= " : " . $dataDeploy[$k]['y']; } echo "<table align='center'>"; echo "<tr height='280'>"; echo "<td width='380'>"; self::showChart('computers', $dataComputer); echo "</td>"; echo "<td width='380'>"; $title = __('Number of computer inventories of last hours', 'fusioninventory'); $title = ''; self::showChartBar('nbinventory', $dataInventory, $title); echo "</td>"; echo "<td width='380'>"; self::showChart('deploy', $dataDeploy, __('Deployment', 'fusioninventory')); echo "</td>"; echo "</tr>"; echo "<tr height='280'>"; echo "<td>"; self::showChart('snmp', $dataSNMP); echo "</td>"; echo "<td>"; self::showChart('ports', $dataPortL); echo "</td>"; echo "<td>"; self::showChart('portsconnected', $dataPortC); echo "</td>"; echo "</tr>"; echo "</table>"; }
/** * @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'); }
/** * @test */ public function prepareTaskDisabled() { global $DB; $DB->connect(); $pfTask = new PluginFusioninventoryTask(); $pfTask->update(array('id' => 1, 'is_active' => 0)); PluginFusioninventoryTask::cronTaskscheduler(); $data = $pfTask->getJoblogs(array(1)); $ref = array(); $this->assertEquals($ref, $data['agents'], 'Task inactive, so no agent prepared'); $ref_prepared = array(); $this->assertEquals($ref_prepared, $data['tasks']); }