/** * @test */ public function prepareDB() { global $DB; $DB->connect(); $pfDeployPackage = new PluginFusioninventoryDeployPackage(); $pfDeployGroup = new PluginFusioninventoryDeployGroup(); $pfTask = new PluginFusioninventoryTask(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfTaskjobState = new PluginFusioninventoryTaskjobstate(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $pfDeployGroup_Dynamicdata = new PluginFusioninventoryDeployGroup_Dynamicdata(); // Create package $input = array('entities_id' => 0, 'name' => 'package'); $packages_id = $pfDeployPackage->add($input); // Create fusioninventory dynamic group $input = array('name' => 'all computers have name computer', 'type' => 'DYNAMIC'); $groups_id = $pfDeployGroup->add($input); $input = array('plugin_fusioninventory_deploygroups_id' => $groups_id, 'fields_array' => 'a:2:{s:8:"criteria";a:1:{i:0;a:3:{s:5:"field";s:1:"1";s:10:"searchtype";s:8:"contains";s:5:"value";s:8:"computer";}}s:12:"metacriteria";s:0:"";}'); $pfDeployGroup_Dynamicdata->add($input); // create task $input = array('entities_id' => 0, 'name' => 'deploy', 'is_active' => 1); self::$tasks_id = $pfTask->add($input); // create taskjob $input = array('plugin_fusioninventory_tasks_id' => self::$tasks_id, 'entities_id' => 0, 'name' => 'deploy', 'method' => 'deployinstall', 'targets' => '[{"PluginFusioninventoryDeployPackage":"' . $packages_id . '"}]', 'actors' => '[{"PluginFusioninventoryDeployGroup":"' . self::$tasks_id . '"}]'); self::$taskjobs_id = $pfTaskjob->add($input); //create taskjobstate $input = array('plugin_fusioninventory_taskjobs_id' => self::$taskjobs_id, 'items_id' => 0, 'itemtype' => 'Computer', 'state' => PluginFusioninventoryTaskjobstate::FINISHED, 'plugin_fusioninventory_agents_id' => 0, 'specificity' => 0, 'uniqid' => 0); self::$taskjobstates_id = $pfTaskjobState->add($input); //crfeate taskjoblogR $input = array('plugin_fusioninventory_taskjobstates_id' => self::$taskjobstates_id, 'date ' => date('Y-m-d H:i:s'), 'items_id' => 0, 'itemtype' => 'Computer', 'state' => PluginFusioninventoryTaskjoblog::TASK_RUNNING, 'comment' => "1 ==devicesfound=="); self::$taskjoblogs_id = $pfTaskjoblog->add($input); }
/** * @test */ public function prepareDB() { global $DB; $DB->connect(); $computer = new Computer(); $pfAgent = new PluginFusioninventoryAgent(); $pfTask = new PluginFusioninventoryTask(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfIPRange = new PluginFusioninventoryIPRange(); // 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); $input = array('entities_id' => 0, 'name' => 'computer2'); $computers_id = $computer->add($input); $input = array('entities_id' => 0, 'name' => 'computer2', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer2', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id); $pfAgent->add($input); $input = array('entities_id' => 0, 'name' => 'computer3'); $computers_id = $computer->add($input); $input = array('entities_id' => 0, 'name' => 'computer3', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer3', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id); $pfAgent->add($input); // Add IPRange $input = array('entities_id' => 0, 'name' => 'Office', 'ip_start' => '10.0.0.1', 'ip_end' => '10.0.0.254'); $ipranges_id = $pfIPRange->add($input); $input = array('entities_id' => 0, 'name' => 'Office2', 'ip_start' => '10.0.2.1', 'ip_end' => '10.0.2.254'); $ipranges_id2 = $pfIPRange->add($input); // Allow all agents to do network discovery $query = "UPDATE `glpi_plugin_fusioninventory_agentmodules` " . " SET `is_active`='1' " . " WHERE `modulename`='NETWORKDISCOVERY'"; $DB->query($query); // create task $input = array('entities_id' => 0, 'name' => 'network discovery', 'is_active' => 1); $tasks_id = $pfTask->add($input); // create taskjob $input = array('plugin_fusioninventory_tasks_id' => $tasks_id, 'entities_id' => 0, 'name' => 'discovery', 'method' => 'networkdiscovery', 'targets' => '[{"PluginFusioninventoryIPRange":"' . $ipranges_id . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"2"}]'); $pfTaskjob->add($input); // create task $input = array('entities_id' => 0, 'name' => 'network discovery2', 'is_active' => 1); $tasks2_id = $pfTask->add($input); // create taskjob $input = array('plugin_fusioninventory_tasks_id' => $tasks2_id, 'entities_id' => 0, 'name' => 'discovery', 'method' => 'networkdiscovery', 'targets' => '[{"PluginFusioninventoryIPRange":"' . $ipranges_id2 . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"3"}]'); $pfTaskjob->add($input); }
/** * @test */ public function prepareDB() { global $DB; $DB->connect(); $computer = new Computer(); $pfAgent = new PluginFusioninventoryAgent(); $pfDeployPackage = new PluginFusioninventoryDeployPackage(); $pfDeployGroup = new PluginFusioninventoryDeployGroup(); $pfTask = new PluginFusioninventoryTask(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfDeployGroup_Dynamicdata = new PluginFusioninventoryDeployGroup_Dynamicdata(); // Create package $input = array('entities_id' => 0, 'name' => 'package'); $packages_id = $pfDeployPackage->add($input); // Create fusioninventory dynamic group $input = array('name' => 'all computers have name computer', 'type' => 'DYNAMIC'); $groups_id = $pfDeployGroup->add($input); $input = array('plugin_fusioninventory_deploygroups_id' => $groups_id, 'fields_array' => 'a:2:{s:8:"criteria";a:1:{i:0;a:3:{s:5:"field";s:1:"1";s:10:"searchtype";s:8:"contains";s:5:"value";s:8:"computer";}}s:12:"metacriteria";s:0:"";}'); $pfDeployGroup_Dynamicdata->add($input); // create task $input = array('entities_id' => 0, 'name' => 'deploy', 'is_active' => 1); $tasks_id = $pfTask->add($input); // create takjob $input = array('plugin_fusioninventory_tasks_id' => $tasks_id, 'entities_id' => 0, 'name' => 'deploy', 'method' => 'deployinstall', 'targets' => '[{"PluginFusioninventoryDeployPackage":"' . $packages_id . '"}]', 'actors' => '[{"PluginFusioninventoryDeployGroup":"' . $tasks_id . '"}]'); $pfTaskjob->add($input); // Create computers + agents $input = array('entities_id' => 0, 'name' => 'computer1'); $computers_id = $computer->add($input); $input = array('entities_id' => 0, 'name' => 'portdavid', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'portdavid', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id); $pfAgent->add($input); $input = array('entities_id' => 0, 'name' => 'computer2'); $computers_id = $computer->add($input); $input = array('entities_id' => 0, 'name' => 'computer2', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer2', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id); $pfAgent->add($input); $input = array('entities_id' => 0, 'name' => 'computer3'); $computers_id = $computer->add($input); $input = array('entities_id' => 0, 'name' => 'computer3', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer3', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id); $pfAgent->add($input); }
foreach ($a_taskjobreties as $taskjob_id_next => $datas2) { $pfTaskjob->showForm($taskjob_id_next); } } else { $j = 0; } } echo "<br/>"; } break; case 1: $pfTask->getFromDB($_POST["id"]); if ($pfTask->fields['is_advancedmode'] == '0') { $taskjob = current($a_taskjob); if (!isset($taskjob["id"])) { $taskjobs_id = $pfTaskjob->add(array('name' => $pfTask->fields['name'], 'entities_id' => $pfTask->fields['entities_id'], 'plugin_fusioninventory_tasks_id' => $_POST["id"])); $pfTaskjob->showForm($taskjobs_id); } else { $pfTaskjob->showForm($taskjob["id"]); } } break; } if ($_POST['glpi_tab'] > 1) { foreach ($a_taskjob as $taskjob_id => $datas) { $i++; if ($_POST['glpi_tab'] == $i) { $pfTaskjob->showForm($taskjob_id); echo "<br/>"; $pfTaskjoblog->showHistory($taskjob_id); $taskjob_id_next = $taskjob_id;
/** * @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'); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { $pfTask = new self(); $pfTaskjob = new PluginFusioninventoryTaskjob(); switch ($ma->getAction()) { case "transfert": foreach ($ids as $key) { if ($pfTask->getFromDB($key)) { $a_taskjobs = $pfTaskjob->find("`plugin_fusioninventory_tasks_id`='" . $key . "'"); foreach ($a_taskjobs as $data1) { $input = array(); $input['id'] = $data1['id']; $input['entities_id'] = $_POST['entities_id']; $pfTaskjob->update($input); } $input = array(); $input['id'] = $key; $input['entities_id'] = $_POST['entities_id']; if ($pfTask->update($input)) { //set action massive ok for this item $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { // KO $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } break; case 'target_task': $taskjob = new PluginFusioninventoryTaskjob(); $tasks = array(); // prepare base insertion $input = array('plugin_fusioninventory_tasks_id' => $ma->POST['tasks_id'], 'entities_id' => 0, 'name' => 'deploy', 'method' => 'deployinstall', 'targets' => '[{"PluginFusioninventoryDeployPackage":"' . $ma->POST['packages_id'] . '"}]', 'actor' => array()); if (array_key_exists('separate_jobs', $_POST)) { foreach ($ids as $key) { $input['actors'] = '[{"Computer":"' . $key . '"}]'; if ($pfTaskjob->add($input)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } else { foreach ($ids as $key) { $input['actors'][] = array('Computer' => $key); $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } $input['actors'] = json_encode($input['actors']); $pfTaskjob->add($input); } break; } }
/** * @test */ public function TaskWithPC() { $this->mark_incomplete(); global $DB; $_SESSION['glpiactiveentities_string'] = 0; $pfDeployGroup = new PluginFusioninventoryDeployGroup(); $pfDeployGroup_Dynamicdata = new PluginFusioninventoryDeployGroup_Dynamicdata(); $pfDeployPackage = new PluginFusioninventoryDeployPackage(); $pfTask = new PluginFusioninventoryTask(); $pfTaskJob = new PluginFusioninventoryTaskjob(); $input = array('name' => 'test', 'type' => 'DYNAMIC'); $pfDeployGroup->add($input); $input = array('groups_id' => 1, 'fields_array' => '{"entities_id":"0","name":"","field":["1"],"searchtype":["contains"],"contains":["^pc"],"plugin_fusioninventory_deploygroup_dynamicdatas_id":"1","id":"1","updaterule":"Update this rule","itemtype":"Computer"}'); $pfDeployGroup_Dynamicdata->add($input); $input = array('name' => 'ls', 'entities_id' => 0); $pfDeployPackage->add($input); $input = array('name' => 'deploy', 'is_active' => 1, 'communication' => 'pull'); $pfTask->add($input); $a_plugins = current(getAllDatasFromTable('glpi_plugins', '`directory`="fusioninventory"')); $input = array('plugin_fusioninventory_tasks_id' => 1, 'name' => 'deploy', 'plugins_id' => $a_plugins['id'], 'method' => 'deployinstall', 'action' => '[{"PluginFusioninventoryDeployGroup":"1"}]'); $pfTaskJob->add($input); $DB->query('UPDATE `glpi_plugin_fusioninventory_taskjobs` SET `definition`=\'[{"PluginFusioninventoryDeployPackage":"1"}]\' WHERE `id`="1"'); // Force task prepation $pfTaskJob->forceRunningTask(1); $a_jobstates = getAllDatasFromTable("glpi_plugin_fusioninventory_taskjobstates"); foreach ($a_jobstates as $num => $data) { unset($data['uniqid']); $a_jobstates[$num] = $data; } $a_reference = array(1 => array('id' => 1, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 1, 'specificity' => '', 'execution_id' => '0'), 2 => array('id' => 2, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 2, 'specificity' => '', 'execution_id' => '0'), 3 => array('id' => 3, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 3, 'specificity' => '', 'execution_id' => '0'), 4 => array('id' => 4, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 4, 'specificity' => '', 'execution_id' => '0'), 5 => array('id' => 5, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 5, 'specificity' => '', 'execution_id' => '0'), 6 => array('id' => 6, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 6, 'specificity' => '', 'execution_id' => '0'), 7 => array('id' => 7, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 7, 'specificity' => '', 'execution_id' => '0'), 8 => array('id' => 8, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 8, 'specificity' => '', 'execution_id' => '0'), 9 => array('id' => 9, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 9, 'specificity' => '', 'execution_id' => '0'), 10 => array('id' => 10, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 10, 'specificity' => '', 'execution_id' => '0'), 11 => array('id' => 11, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 11, 'specificity' => '', 'execution_id' => '0'), 12 => array('id' => 12, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 12, 'specificity' => '', 'execution_id' => '0'), 13 => array('id' => 13, 'plugin_fusioninventory_taskjobs_id' => 1, 'items_id' => 1, 'itemtype' => "PluginFusioninventoryDeployPackage", 'state' => 0, 'plugin_fusioninventory_agents_id' => 13, 'specificity' => '', 'execution_id' => '0')); $this->assertEquals($a_reference, $a_jobstates); }