コード例 #1
0
 function run($jobstate)
 {
     $pfAgent = new PluginFusioninventoryAgent();
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfTaskjob = new PluginFusioninventoryTaskjob();
     $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
     $pfIPRange = new PluginFusioninventoryIPRange();
     $pfConfigSecurity = new PluginFusioninventoryConfigSecurity();
     $pfToolbox = new PluginFusioninventoryToolbox();
     $pfAgent->getFromDB($jobstate->fields['plugin_fusioninventory_agents_id']);
     $sxml_option = $this->message->addChild('OPTION');
     $sxml_option->addChild('NAME', 'NETDISCOVERY');
     $a_versions = importArrayFromDB($pfAgent->fields["version"]);
     // * Disabled by David Durieux, I think it's not required now * //
     //      if (((isset($a_versions["NETWORKDISCOVERY"])) AND ($a_versions["NETWORKDISCOVERY"] >= 1.3))
     //              OR !isset($a_versions["NETWORKDISCOVERY"])) {
     //         if (!file_exists(GLPI_PLUGIN_DOC_DIR."/fusioninventory/discovery.xml")) {
     //            PluginFusioninventorySnmpmodelImportExport::exportDictionnaryFile(FALSE);
     //         }
     //         $sxml_option->addChild('DICOHASH',
     //                                md5_file(GLPI_PLUGIN_DOC_DIR."/fusioninventory/discovery.xml"));
     //      }
     //      if (($pfAgent->fields["senddico"] == "1")) {
     //
     //         if (((isset($a_versions["NETWORKDISCOVERY"]))
     //                 AND ($a_versions["NETWORKDISCOVERY"] >= 1.3))) {
     //
     //            $sxml_option->addChild('DICO',
     //                                   file_get_contents(
     //                                           GLPI_PLUGIN_DOC_DIR."/fusioninventory/discovery.xml"));
     //         }
     //         $input = array();
     //         $input['id'] = $pfAgent->fields['id'];
     //         $input["senddico"] = "0";
     //         $pfAgent->update($input);
     //      }
     $sxml_param = $sxml_option->addChild('PARAM');
     $sxml_param->addAttribute('THREADS_DISCOVERY', $pfAgent->fields["threads_networkdiscovery"]);
     $sxml_param->addAttribute('TIMEOUT', $pfAgent->fields["timeout_networkdiscovery"]);
     $sxml_param->addAttribute('PID', $jobstate->fields['id']);
     $changestate = 0;
     //foreach ($a_Taskjobstates as $taskjobstate) {
     $taskjobstatedatas = $jobstate->fields;
     $sxml_rangeip = $sxml_option->addChild('RANGEIP');
     $pfTaskjob->getFromDB($taskjobstatedatas['plugin_fusioninventory_taskjobs_id']);
     $pfTaskjobstate->getFromDB($taskjobstatedatas['id']);
     $pfIPRange->getFromDB($taskjobstatedatas['items_id']);
     $sxml_rangeip->addAttribute('ID', $pfIPRange->fields['id']);
     if (!is_null($pfTaskjobstate->fields['specificity'])) {
         $a_split = explode("-", $pfTaskjobstate->fields['specificity']);
         $first_ip = $pfIPRange->getIp2long($pfIPRange->fields["ip_start"]);
         $last_ip = long2ip($first_ip + $a_split[1]);
         $first_ip = long2ip($first_ip + $a_split[0]);
         if ($first_ip != '0.0.0.0' && $last_ip != '0.0.0.0') {
             $sxml_rangeip->addAttribute('IPSTART', $first_ip);
             $sxml_rangeip->addAttribute('IPEND', $last_ip);
         }
     } else {
         $sxml_rangeip->addAttribute('IPSTART', $pfIPRange->fields["ip_start"]);
         $sxml_rangeip->addAttribute('IPEND', $pfIPRange->fields["ip_end"]);
     }
     $sxml_rangeip->addAttribute('ENTITY', $pfIPRange->fields["entities_id"]);
     if ($changestate == '0') {
         $pfTaskjobstate->changeStatus($pfTaskjobstate->fields['id'], 1);
         $pfTaskjoblog->addTaskjoblog($pfTaskjobstate->fields['id'], '0', 'PluginFusioninventoryAgent', '1', $pfAgent->fields["threads_networkdiscovery"] . ' threads', $pfAgent->fields["timeout_networkdiscovery"] . ' timeout');
         $changestate = $pfTaskjobstate->fields['id'];
     } else {
         $pfTaskjobstate->changeStatusFinish($pfTaskjobstate->fields['id'], $taskjobstatedatas['items_id'], $taskjobstatedatas['itemtype'], 0, "Merged with " . $changestate);
     }
     //}
     $pfIPRange_ConfigSecurity = new PluginFusioninventoryIPRange_ConfigSecurity();
     $a_auths = $pfIPRange_ConfigSecurity->find("`plugin_fusioninventory_ipranges_id`='" . $pfIPRange->fields['id'] . "'", "rank");
     foreach ($a_auths as $dataAuth) {
         $pfToolbox->addAuth($sxml_option, $dataAuth['plugin_fusioninventory_configsecurities_id']);
     }
     return $this->message;
 }
 /**
  * Import data
  *
  * @param $p_DEVICEID XML code to import
  * @param $p_CONTENT XML code to import
  * @param $p_xml value XML code to import
  *
  * @return "" (import ok) / error string (import ko)
  *
  **/
 function import($p_DEVICEID, $a_CONTENT, $arrayinventory)
 {
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfAgent = new PluginFusioninventoryAgent();
     PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkDiscovery->import().');
     $errors = '';
     $a_agent = $pfAgent->InfosByKey($p_DEVICEID);
     if (isset($a_CONTENT['PROCESSNUMBER'])) {
         $_SESSION['glpi_plugin_fusioninventory_processnumber'] = $a_CONTENT['PROCESSNUMBER'];
         if ($pfTaskjobstate->getFromDB($a_CONTENT['PROCESSNUMBER'])) {
             if ($pfTaskjobstate->fields['state'] != "3") {
                 $pfTaskjobstate->changeStatus($a_CONTENT['PROCESSNUMBER'], 2);
                 if (!isset($a_CONTENT['AGENT']['START']) and !isset($a_CONTENT['AGENT']['END'])) {
                     $nb_devices = 0;
                     if (isset($a_CONTENT['DEVICE'])) {
                         if (is_int(key($a_CONTENT['DEVICE']))) {
                             $nb_devices = count($a_CONTENT['DEVICE']);
                         } else {
                             $nb_devices = 1;
                         }
                     }
                     $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = $a_CONTENT['PROCESSNUMBER'];
                     $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = $a_agent['id'];
                     $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'PluginFusioninventoryAgent';
                     $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = '6';
                     $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = $nb_devices . ' ==devicesfound==';
                     $this->addtaskjoblog();
                 }
             }
         }
     }
     if ($pfTaskjobstate->getFromDB($a_CONTENT['PROCESSNUMBER'])) {
         if ($pfTaskjobstate->fields['state'] != "3") {
             $pfImportExport = new PluginFusioninventorySnmpmodelImportExport();
             $errors .= $pfImportExport->import_netdiscovery($a_CONTENT, $p_DEVICEID);
             if (isset($a_CONTENT['AGENT']['END'])) {
                 if (isset($a_CONTENT['DICO']) and $a_CONTENT['DICO'] == "REQUEST") {
                     $pfAgent->getFromDB($pfTaskjobstate->fields["plugin_fusioninventory_agents_id"]);
                     $input = array();
                     $input['id'] = $pfAgent->fields['id'];
                     $input["senddico"] = "1";
                     $pfAgent->update($input);
                     $pfTaskjobstate->changeStatusFinish($a_CONTENT['PROCESSNUMBER'], $a_agent['id'], 'PluginFusioninventoryAgent', '1', '==diconotuptodate==');
                 } else {
                     $messages = array('Total Found' => 0, 'Created' => 0, 'Updated' => 0);
                     $messages['Updated'] = countElementsInTable('glpi_plugin_fusioninventory_taskjoblogs', "`plugin_fusioninventory_taskjobstates_id`='" . $a_CONTENT['PROCESSNUMBER'] . "' " . " AND `comment` LIKE '%==updatetheitem==%'");
                     $messages['Created'] = countElementsInTable('glpi_plugin_fusioninventory_taskjoblogs', "`plugin_fusioninventory_taskjobstates_id`='" . $a_CONTENT['PROCESSNUMBER'] . "' " . " AND `comment` LIKE '%==addtheitem==%'");
                     $messages['Total Found'] = $messages['Updated'] + $messages['Created'];
                     $message = 'Total Found:' . $messages['Total Found'] . ' Created:' . $messages['Created'] . ' Updated:' . $messages['Updated'];
                     $pfTaskjobstate->changeStatusFinish($a_CONTENT['PROCESSNUMBER'], $a_agent['id'], 'PluginFusioninventoryAgent', '0', $message);
                 }
             }
         }
     }
     return $errors;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
 $jobstate = current($pfTaskjobstate->find("`uniqid`='" . $_GET['uuid'] . "'\n            AND `state`!='" . PluginFusioninventoryTaskjobstate::FINISHED . "'", '', 1));
 if (isset($jobstate['plugin_fusioninventory_agents_id'])) {
     $pfAgent->getFromDB($jobstate['plugin_fusioninventory_agents_id']);
     $computers_id = $pfAgent->fields['computers_id'];
     $a_values = $_GET;
     unset($a_values['action']);
     unset($a_values['uuid']);
     switch ($jobstate['itemtype']) {
         case 'PluginFusioninventoryCollect_Registry':
             // update registry content
             $pfCRC = new PluginFusioninventoryCollect_Registry_Content();
             $pfCRC->updateComputer($computers_id, $a_values, $jobstate['items_id']);
             $pfTaskjobstate->changeStatus($jobstate['id'], PluginFusioninventoryTaskjobstate::AGENT_HAS_SENT_DATA);
             if (isset($a_values['_cpt']) && $a_values['_cpt'] == 0) {
                 // it not find the path
                 $pfTaskjobstate->changeStatusFinish($jobstate['id'], $jobstate['items_id'], $jobstate['itemtype'], 1, 'Path not found');
             }
             if (isset($a_values['_cpt']) && $a_values['_cpt'] == 1) {
                 // it last value
                 $pfTaskjobstate->changeStatusFinish($jobstate['id'], $jobstate['items_id'], $jobstate['itemtype']);
             }
             break;
         case 'PluginFusioninventoryCollect_Wmi':
             // update registry content
             $pfCWC = new PluginFusioninventoryCollect_Wmi_Content();
             $pfCWC->updateComputer($computers_id, $a_values, $jobstate['items_id']);
             $pfTaskjobstate->changeStatus($jobstate['id'], PluginFusioninventoryTaskjobstate::AGENT_HAS_SENT_DATA);
             if ($a_values['_cpt'] == 1) {
                 // it last value
                 $pfTaskjobstate->changeStatusFinish($jobstate['id'], $jobstate['items_id'], $jobstate['itemtype']);
             }
コード例 #5
0
 function prepareRun($taskjob_id, $definitions_filter = NULL)
 {
     global $DB;
     $task = new PluginFusioninventoryTask();
     $job = new PluginFusioninventoryTaskjob();
     $joblog = new PluginFusioninventoryTaskjoblog();
     $jobstate = new PluginFusioninventoryTaskjobstate();
     $agent = new PluginFusioninventoryAgent();
     $agentmodule = new PluginFusioninventoryAgentmodule();
     $job->getFromDB($taskjob_id);
     $task->getFromDB($job->fields['plugin_fusioninventory_tasks_id']);
     $communication = $task->fields['communication'];
     $actions = importArrayFromDB($job->fields['action']);
     $definitions = importArrayFromDB($job->fields['definition']);
     $taskvalid = 0;
     $computers = array();
     foreach ($actions as $action) {
         $itemtype = key($action);
         $items_id = current($action);
         switch ($itemtype) {
             case 'Computer':
                 if ($this->definitionFiltered("Computer", $definitions_filter)) {
                     break;
                 }
                 $computers[] = $items_id;
                 break;
             case 'Group':
                 if ($this->definitionFiltered("Group", $definitions_filter)) {
                     break;
                 }
                 $computer_object = new Computer();
                 //find computers by user associated with this group
                 $group_users = new Group_User();
                 $group = new Group();
                 $group->getFromDB($items_id);
                 $members = array();
                 $computers_a_1 = array();
                 $computers_a_2 = array();
                 //array_keys($group_users->find("groups_id = '$items_id'"));
                 $members = $group_users->getGroupUsers($items_id);
                 foreach ($members as $member) {
                     $computers = $computer_object->find("users_id = '{$member['id']}' " . " AND `is_deleted`='0' AND `is_template`='0'");
                     foreach ($computers as $computer) {
                         $computers_a_1[] = $computer['id'];
                     }
                 }
                 //find computers directly associated with this group
                 $computers = $computer_object->find("groups_id = '{$items_id}' " . " AND `is_deleted`='0' AND `is_template`='0'");
                 foreach ($computers as $computer) {
                     $computers_a_2[] = $computer['id'];
                 }
                 //merge two previous array and deduplicate entries
                 $computers = array_unique(array_merge($computers_a_1, $computers_a_2));
                 break;
             case 'PluginFusioninventoryDeployGroup':
                 $group = new PluginFusioninventoryDeployGroup();
                 $group->getFromDB($items_id);
                 switch ($group->getField('type')) {
                     case 'STATIC':
                         if ($this->definitionFiltered("PluginFusioninventoryDeployGroupStatic", $definitions_filter)) {
                             break;
                         }
                         $query = "SELECT items_id\n                     FROM glpi_plugin_fusioninventory_deploygroups_staticdatas\n                     WHERE groups_id = '{$items_id}'\n                     AND itemtype = 'Computer'";
                         $res = $DB->query($query);
                         while ($row = $DB->fetch_assoc($res)) {
                             $computers[] = $row['items_id'];
                         }
                         break;
                     case 'DYNAMIC':
                         if ($this->definitionFiltered("PluginFusioninventoryDeployGroupDynamic", $definitions_filter)) {
                             break;
                         }
                         //$definitions_filter is NULL = update by crontask !
                         if ($definitions_filter != NULL) {
                             $where = " AND `can_update_group`='1'";
                         } else {
                             $where = "";
                         }
                         $query = "SELECT fields_array\n                     FROM glpi_plugin_fusioninventory_deploygroups_dynamicdatas\n                     WHERE groups_id = '{$items_id}' {$where}\n                     LIMIT 1";
                         $res = $DB->query($query);
                         $row = $DB->fetch_assoc($res);
                         //No dynamic groups have been found : break
                         if ($DB->numrows($res) == 0) {
                             break;
                         }
                         if (isset($_GET)) {
                             $get_tmp = $_GET;
                         }
                         if (isset($_SESSION["glpisearchcount"]['Computer'])) {
                             unset($_SESSION["glpisearchcount"]['Computer']);
                         }
                         if (isset($_SESSION["glpisearchcount2"]['Computer'])) {
                             unset($_SESSION["glpisearchcount2"]['Computer']);
                         }
                         $_GET = importArrayFromDB($row['fields_array']);
                         $_GET["glpisearchcount"] = count($_GET['field']);
                         if (isset($_GET['field2'])) {
                             $_GET["glpisearchcount2"] = count($_GET['field2']);
                         }
                         $pfSearch = new PluginFusioninventorySearch();
                         Search::manageParams('Computer');
                         $glpilist_limit = $_SESSION['glpilist_limit'];
                         $_SESSION['glpilist_limit'] = 999999999;
                         $result = $pfSearch->constructSQL('Computer', $_GET);
                         $_SESSION['glpilist_limit'] = $glpilist_limit;
                         while ($data = $DB->fetch_array($result)) {
                             $computers[] = $data['id'];
                         }
                         if (count($get_tmp) > 0) {
                             $_GET = $get_tmp;
                         }
                         break;
                 }
                 break;
         }
     }
     //Remove duplicatas from array
     //We are using isset for faster processing than array_unique because we might have many
     //entries in this list.
     $tmp_computers = array();
     foreach ($computers as $computer) {
         if (!isset($tmp_computers[$computer])) {
             $tmp_computers[$computer] = 1;
         }
     }
     $computers = array_keys($tmp_computers);
     $c_input = array();
     $c_input['plugin_fusioninventory_taskjobs_id'] = $job->fields['id'];
     $c_input['state'] = 0;
     $c_input['plugin_fusioninventory_agents_id'] = 0;
     $c_input['execution_id'] = $task->fields['execution_id'];
     $package = new PluginFusioninventoryDeployPackage();
     foreach ($computers as $computer_id) {
         //Unique Id match taskjobstatuses for an agent(computer)
         foreach ($definitions as $definition) {
             $uniqid = uniqid();
             $package->getFromDB($definition['PluginFusioninventoryDeployPackage']);
             $c_input['state'] = 0;
             $c_input['itemtype'] = 'PluginFusioninventoryDeployPackage';
             $c_input['items_id'] = $package->fields['id'];
             $c_input['date'] = date("Y-m-d H:i:s");
             $c_input['uniqid'] = $uniqid;
             //get agent for this computer
             $agents_id = $agent->getAgentWithComputerid($computer_id);
             if ($agents_id === FALSE) {
                 $jobstates_id = $jobstate->add($c_input);
                 $jobstate->changeStatusFinish($jobstates_id, 0, '', 1, "No agent found for [[Computer::" . $computer_id . "]]", 0, 0);
             } else {
                 if ($agentmodule->isAgentCanDo('DEPLOY', $agents_id)) {
                     $c_input['plugin_fusioninventory_agents_id'] = $agents_id;
                     $jobstates_running = $jobstate->find(implode(" ", array("    `itemtype` = 'PluginFusioninventoryDeployPackage'", "AND `items_id` = " . $package->fields['id'], "AND `state` <> " . PluginFusioninventoryTaskjobstate::FINISHED, "AND `plugin_fusioninventory_agents_id` = " . $agents_id)));
                     if (count($jobstates_running) == 0) {
                         # Push the agent, in the stack of agent to awake
                         if ($communication == "push") {
                             $_SESSION['glpi_plugin_fusioninventory']['agents'][$agents_id] = 1;
                         }
                         $jobstates_id = $jobstate->add($c_input);
                         //Add log of taskjob
                         $c_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                         $c_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                         $taskvalid++;
                         $joblog->add($c_input);
                         unset($c_input['state']);
                         unset($c_input['plugin_fusioninventory_agents_id']);
                     }
                 }
             }
         }
     }
     if ($taskvalid > 0) {
         $job->fields['status'] = 1;
         $job->update($job->fields);
     } else {
         $job->reinitializeTaskjobs($job->fields['plugin_fusioninventory_tasks_id']);
     }
 }
コード例 #6
0
 /**
  * Get all devices and put in taskjobstate each task for
  * each device for each agent
  *
  * @param type $taskjobs_id id of taskjob esx
  *
  * @return uniqid value
  */
 function prepareRun($taskjobs_id)
 {
     $task = new PluginFusioninventoryTask();
     $job = new PluginFusioninventoryTaskjob();
     $joblog = new PluginFusioninventoryTaskjoblog();
     $jobstate = new PluginFusioninventoryTaskjobstate();
     $uniqid = uniqid();
     $job->getFromDB($taskjobs_id);
     $task->getFromDB($job->fields['plugin_fusioninventory_tasks_id']);
     $communication = $task->fields['communication'];
     //list all agents
     $agent_actions = importArrayFromDB($job->fields['action']);
     $task_definitions = importArrayFromDB($job->fields['definition']);
     $agent_actionslist = array();
     foreach ($agent_actions as $targets) {
         foreach ($targets as $itemtype => $items_id) {
             $item = new $itemtype();
             // Detect if agent exists
             if ($item->getFromDB($items_id)) {
                 $agent_actionslist[$items_id] = 1;
             }
         }
     }
     // *** Add jobstate
     if (empty($agent_actionslist)) {
         $a_input = array();
         $a_input['plugin_fusioninventory_taskjobs_id'] = $taskjobs_id;
         $a_input['state'] = 0;
         $a_input['plugin_fusioninventory_agents_id'] = 0;
         $a_input['uniqid'] = $uniqid;
         $a_input['execution_id'] = $task->fields['execution_id'];
         foreach ($task_definitions as $task_definition) {
             foreach ($task_definition as $task_itemtype => $task_items_id) {
                 $a_input['itemtype'] = $task_itemtype;
                 $a_input['items_id'] = $task_items_id;
                 $jobstates_id = $jobstate->add($a_input);
                 //Add log of taskjob
                 $a_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                 $a_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                 $a_input['date'] = date("Y-m-d H:i:s");
                 $joblog->add($a_input);
                 $jobstate->changeStatusFinish($jobstates_id, 0, 'PluginFusioninventoryInventoryComputerESX', 1, "Unable to find agent to run this job");
             }
         }
         $job->update($job->fields);
     } else {
         foreach ($agent_actions as $targets) {
             foreach ($targets as $items_id) {
                 if ($communication == "push") {
                     $_SESSION['glpi_plugin_fusioninventory']['agents'][$items_id] = 1;
                 }
                 foreach ($task_definitions as $task_definition) {
                     foreach ($task_definition as $task_itemtype => $task_items_id) {
                         $a_input = array();
                         $a_input['plugin_fusioninventory_taskjobs_id'] = $taskjobs_id;
                         $a_input['state'] = 0;
                         $a_input['plugin_fusioninventory_agents_id'] = $items_id;
                         $a_input['itemtype'] = $task_itemtype;
                         $a_input['items_id'] = $task_items_id;
                         $a_input['uniqid'] = $uniqid;
                         $a_input['date'] = date("Y-m-d H:i:s");
                         $a_input['execution_id'] = $task->fields['execution_id'];
                         $jobstates_id = $jobstate->add($a_input);
                         //Add log of taskjob
                         $a_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                         $a_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                         $joblog->add($a_input);
                         unset($a_input['state']);
                     }
                 }
             }
         }
         $job->fields['status'] = 1;
         $job->update($job->fields);
     }
     return $uniqid;
 }
 /**
  * Import data
  *
  *@param $p_DEVICEID XML code to import
  *@param $p_CONTENT XML code to import
  *@return "" (import ok) / error string (import ko)
  **/
 function import($p_DEVICEID, $a_CONTENT, $arrayinventory)
 {
     //$_SESSION['SOURCEXML'] = $p_xml;
     PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkInventory->import().');
     $pfAgent = new PluginFusioninventoryAgent();
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $this->agent = $pfAgent->InfosByKey($p_DEVICEID);
     $this->arrayinventory = $arrayinventory;
     $_SESSION['glpi_plugin_fusioninventory_processnumber'] = $a_CONTENT['PROCESSNUMBER'];
     if (!isset($a_CONTENT['AGENT']['START']) and !isset($a_CONTENT['AGENT']['END'])) {
         $nb_devices = 0;
         if (isset($a_CONTENT['DEVICE'])) {
             if (is_int(key($a_CONTENT['DEVICE']))) {
                 $nb_devices = count($a_CONTENT['DEVICE']);
             } else {
                 $nb_devices = 1;
             }
         }
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = $a_CONTENT['PROCESSNUMBER'];
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = $this->agent['id'];
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'PluginFusioninventoryAgent';
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = '6';
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = $nb_devices . ' ==devicesqueried==';
         $this->addtaskjoblog();
     }
     $this->importContent($a_CONTENT);
     if (isset($a_CONTENT['AGENT']['END'])) {
         $cnt = countElementsInTable('glpi_plugin_fusioninventory_taskjoblogs', "`plugin_fusioninventory_taskjobstates_id`='" . $a_CONTENT['PROCESSNUMBER'] . "' " . " AND `comment` LIKE '%[==detail==] Update %'");
         $pfTaskjobstate->changeStatusFinish($a_CONTENT['PROCESSNUMBER'], $this->agent['id'], 'PluginFusioninventoryAgent', '0', 'Total updated:' . $cnt);
     }
     if (isset($a_CONTENT['AGENT']['START'])) {
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = $a_CONTENT['PROCESSNUMBER'];
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = $this->agent['id'];
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'PluginFusioninventoryAgent';
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = '6';
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '==inventorystarted==';
         $this->addtaskjoblog();
     }
 }
コード例 #8
0
 /**
  * Update agent status for a task
  *
  * @param params parameters from the GET HTTP request
  *
  * @return nothing
  */
 static function updateLog($params = array())
 {
     global $DB;
     $p = array();
     $p['machineid'] = '';
     //DeviceId
     $p['uuid'] = '';
     //Task uuid
     $p['msg'] = 'ok';
     //status of the task
     $p['code'] = '';
     //current step of processing
     foreach ($params as $key => $value) {
         $p[$key] = $value;
     }
     //Get the agent ID by its deviceid
     $agent = PluginFusioninventoryAgent::getByDeviceID($p['machineid']);
     //No need to continue since the requested agent doesn't exists in database
     if ($agent === FALSE) {
         self::sendError();
         return;
     }
     //Get task job status : identifier is the uuid given by the agent
     $taskjobstates = $DB->request(getTableForItemType('PluginFusioninventoryTaskjobstate'), "`uniqid`='" . $p['uuid'] . "'");
     $taskjobstate = new PluginFusioninventoryTaskjobstate();
     foreach ($taskjobstates as $jobstate) {
         $taskjobstate->getFromDB($jobstate['id']);
         //Get taskjoblog associated
         $taskjoblog = new PluginFusioninventoryTaskjobLog();
         $taskjoblog->getFromDBByQuery("WHERE `plugin_fusioninventory_taskjobstates_id`=" . $jobstate['id']);
         switch ($p['code']) {
             case 'running':
                 $taskjoblog->addTaskjoblog($taskjobstate->fields['id'], $taskjobstate->fields['items_id'], $taskjobstate->fields['itemtype'], PluginFusioninventoryTaskjoblog::TASK_RUNNING, $p['msg']);
                 break;
             case 'ok':
                 $taskjobstate->changeStatusFinish($taskjobstate->fields['id'], $taskjobstate->fields['items_id'], $taskjobstate->fields['itemtype'], 0, $p['msg']);
                 break;
             case 'ko':
                 $taskjobstate->changeStatusFinish($taskjobstate->fields['id'], $taskjobstate->fields['items_id'], $taskjobstate->fields['itemtype'], 1, $p['msg']);
                 break;
         }
     }
     self::sendOk();
 }
コード例 #9
0
 function prepareRun($taskjobs_id)
 {
     global $DB;
     $task = new PluginFusioninventoryTask();
     $job = new PluginFusioninventoryTaskjob();
     $joblog = new PluginFusioninventoryTaskjoblog();
     $jobstate = new PluginFusioninventoryTaskjobstate();
     $agent = new PluginFusioninventoryAgent();
     $uniqid = uniqid();
     $job->getFromDB($taskjobs_id);
     $task->getFromDB($job->fields['plugin_fusioninventory_tasks_id']);
     $communication = $task->fields['communication'];
     $actions = importArrayFromDB($job->fields['action']);
     $definitions = importArrayFromDB($job->fields['definition']);
     $taskvalid = 0;
     $computers = array();
     foreach ($actions as $action) {
         $itemtype = key($action);
         $items_id = current($action);
         switch ($itemtype) {
             case 'Computer':
                 $computers[] = $items_id;
                 break;
             case 'Group':
                 $computer_object = new Computer();
                 //find computers by user associated with this group
                 $group_users = new Group_User();
                 $group = new Group();
                 $group->getFromDB($items_id);
                 $members = array();
                 $computers_a_1 = array();
                 $computers_a_2 = array();
                 //array_keys($group_users->find("groups_id = '$items_id'"));
                 $members = $group_users->getGroupUsers($items_id);
                 foreach ($members as $member) {
                     $computers = $computer_object->find("users_id = '{$member['id']}'");
                     foreach ($computers as $computer) {
                         $computers_a_1[] = $computer['id'];
                     }
                 }
                 //find computers directly associated with this group
                 $computers = $computer_object->find("groups_id = '{$items_id}'");
                 foreach ($computers as $computer) {
                     $computers_a_2[] = $computer['id'];
                 }
                 //merge two previous array and deduplicate entries
                 $computers = array_unique(array_merge($computers_a_1, $computers_a_2));
                 break;
             case 'PluginFusioninventoryDeployGroup':
                 $group = new PluginFusioninventoryDeployGroup();
                 $group->getFromDB($items_id);
                 switch ($group->getField('type')) {
                     case 'STATIC':
                         $query = "SELECT items_id\n                     FROM glpi_plugin_fusioninventory_deploygroups_staticdatas\n                     WHERE groups_id = '{$items_id}'\n                     AND itemtype = 'Computer'";
                         $res = $DB->query($query);
                         while ($row = $DB->fetch_assoc($res)) {
                             $computers[] = $row['items_id'];
                         }
                         break;
                     case 'DYNAMIC':
                         $query = "SELECT fields_array\n                     FROM glpi_plugin_fusioninventory_deploygroups_dynamicdatas\n                     WHERE groups_id = '{$items_id}'\n                     LIMIT 1";
                         $res = $DB->query($query);
                         $row = $DB->fetch_assoc($res);
                         if (isset($_GET)) {
                             $get_tmp = $_GET;
                         }
                         if (isset($_SESSION["glpisearchcount"]['Computer'])) {
                             unset($_SESSION["glpisearchcount"]['Computer']);
                         }
                         if (isset($_SESSION["glpisearchcount2"]['Computer'])) {
                             unset($_SESSION["glpisearchcount2"]['Computer']);
                         }
                         $_GET = importArrayFromDB($row['fields_array']);
                         $_GET["glpisearchcount"] = count($_GET['field']);
                         if (isset($_GET['field2'])) {
                             $_GET["glpisearchcount2"] = count($_GET['field2']);
                         }
                         $pfSearch = new PluginFusioninventorySearch();
                         Search::manageGetValues('Computer');
                         $glpilist_limit = $_SESSION['glpilist_limit'];
                         $_SESSION['glpilist_limit'] = 999999999;
                         $result = $pfSearch->constructSQL('Computer', $_GET);
                         $_SESSION['glpilist_limit'] = $glpilist_limit;
                         while ($data = $DB->fetch_array($result)) {
                             $computers[] = $data['id'];
                         }
                         if (count($get_tmp) > 0) {
                             $_GET = $get_tmp;
                         }
                         break;
                 }
                 break;
         }
     }
     $c_input = array();
     $c_input['plugin_fusioninventory_taskjobs_id'] = $taskjobs_id;
     $c_input['state'] = 0;
     $c_input['plugin_fusioninventory_agents_id'] = 0;
     $c_input['execution_id'] = $task->fields['execution_id'];
     $pfCollect = new PluginFusioninventoryCollect();
     foreach ($computers as $computer_id) {
         //get agent if for this computer
         $agents_id = $agent->getAgentWithComputerid($computer_id);
         if ($agents_id === FALSE) {
             $jobstates_id = $jobstate->add($c_input);
             $jobstate->changeStatusFinish($jobstates_id, 0, '', 1, "No agent found for [[Computer::" . $computer_id . "]]", 0, 0);
         } else {
             foreach ($definitions as $definition) {
                 $pfCollect->getFromDB($definition['PluginFusioninventoryCollect']);
                 switch ($pfCollect->fields['type']) {
                     case 'registry':
                         // get all registry
                         $pfCollect_Registry = new PluginFusioninventoryCollect_Registry();
                         $a_registries = $pfCollect_Registry->find("`plugin_fusioninventory_collects_id`='" . $pfCollect->fields['id'] . "'");
                         foreach ($a_registries as $data_r) {
                             $uniqid = uniqid();
                             $c_input['state'] = 0;
                             $c_input['itemtype'] = 'PluginFusioninventoryCollect_Registry';
                             $c_input['items_id'] = $data_r['id'];
                             $c_input['date'] = date("Y-m-d H:i:s");
                             $c_input['uniqid'] = $uniqid;
                             $c_input['plugin_fusioninventory_agents_id'] = $agents_id;
                             # Push the agent, in the stack of agent to awake
                             if ($communication == "push") {
                                 $_SESSION['glpi_plugin_fusioninventory']['agents'][$agents_id] = 1;
                             }
                             $jobstates_id = $jobstate->add($c_input);
                             //Add log of taskjob
                             $c_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                             $c_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                             $taskvalid++;
                             $joblog->add($c_input);
                         }
                         break;
                     case 'wmi':
                         // get all wmi
                         $pfCollect_Wmi = new PluginFusioninventoryCollect_Wmi();
                         $a_wmies = $pfCollect_Wmi->find("`plugin_fusioninventory_collects_id`='" . $pfCollect->fields['id'] . "'");
                         foreach ($a_wmies as $data_r) {
                             $uniqid = uniqid();
                             $c_input['state'] = 0;
                             $c_input['itemtype'] = 'PluginFusioninventoryCollect_Wmi';
                             $c_input['items_id'] = $data_r['id'];
                             $c_input['date'] = date("Y-m-d H:i:s");
                             $c_input['uniqid'] = $uniqid;
                             $c_input['plugin_fusioninventory_agents_id'] = $agents_id;
                             # Push the agent, in the stack of agent to awake
                             if ($communication == "push") {
                                 $_SESSION['glpi_plugin_fusioninventory']['agents'][$agents_id] = 1;
                             }
                             $jobstates_id = $jobstate->add($c_input);
                             //Add log of taskjob
                             $c_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                             $c_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                             $taskvalid++;
                             $joblog->add($c_input);
                         }
                         break;
                     case 'file':
                         // find files
                         $pfCollect_File = new PluginFusioninventoryCollect_File();
                         $a_files = $pfCollect_File->find("`plugin_fusioninventory_collects_id`='" . $pfCollect->fields['id'] . "'");
                         foreach ($a_files as $data_r) {
                             $uniqid = uniqid();
                             $c_input['state'] = 0;
                             $c_input['itemtype'] = 'PluginFusioninventoryCollect_File';
                             $c_input['items_id'] = $data_r['id'];
                             $c_input['date'] = date("Y-m-d H:i:s");
                             $c_input['uniqid'] = $uniqid;
                             $c_input['plugin_fusioninventory_agents_id'] = $agents_id;
                             # Push the agent, in the stack of agent to awake
                             if ($communication == "push") {
                                 $_SESSION['glpi_plugin_fusioninventory']['agents'][$agents_id] = 1;
                             }
                             $jobstates_id = $jobstate->add($c_input);
                             //Add log of taskjob
                             $c_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                             $c_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                             $taskvalid++;
                             $joblog->add($c_input);
                         }
                         break;
                 }
             }
         }
     }
     if ($taskvalid > 0) {
         $job->fields['status'] = 1;
         $job->update($job->fields);
     } else {
         $job->reinitializeTaskjobs($job->fields['plugin_fusioninventory_tasks_id']);
     }
 }
コード例 #10
0
 /**
  * Force end task
  */
 function forceEnd()
 {
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $a_taskjobstates = $pfTaskjobstate->find("`plugin_fusioninventory_taskjobs_id`='" . $this->fields["id"] . "'");
     //TODO: in order to avoid too many atomic operations on DB, convert the
     //following into a massive prepared operation (ie. ids in one massive action)
     foreach ($a_taskjobstates as $a_taskjobstate) {
         $pfTaskjobstate->getFromDB($a_taskjobstate['id']);
         if ($a_taskjobstate['state'] != PluginFusioninventoryTaskjobstate::FINISHED) {
             $pfTaskjobstate->changeStatusFinish($a_taskjobstate['id'], 0, '', 1, "Action cancelled by user", 0, 0);
         }
     }
     $this->reinitializeTaskjobs($this->fields['plugin_fusioninventory_tasks_id']);
 }
コード例 #11
0
 /**
  *  When agent contact server, this function send datas to agent
  */
 function run($jobstate)
 {
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
     $NetworkPort = new NetworkPort();
     $sxml_option = $this->message->addChild('OPTION');
     $sxml_option->addChild('NAME', 'WAKEONLAN');
     $changestate = 0;
     //      foreach ($taskjobstates as $jobstate) {
     $data = $jobstate->fields;
     $a_networkPort = $NetworkPort->find("`itemtype`='Computer' AND `items_id`='" . $data['items_id'] . "' ");
     $computerip = 0;
     foreach ($a_networkPort as $datanetwork) {
         //if ($datanetwork['ip'] != "127.0.0.1") {
         if ($datanetwork['mac'] != '') {
             $computerip++;
             $sxml_param = $sxml_option->addChild('PARAM');
             $sxml_param->addAttribute('MAC', $datanetwork['mac']);
             //$sxml_param->addAttribute('IP', $datanetwork['ip']);
             if ($changestate == '0') {
                 $pfTaskjobstate->changeStatus($data['id'], 1);
                 $pfTaskjoblog->addTaskjoblog($data['id'], '0', 'Computer', '1', '');
                 $changestate = $pfTaskjobstate->fields['id'];
             } else {
                 $pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 0, "Merged with " . $changestate);
             }
             // Update taskjobstate (state = 3 : finish); Because we haven't return of agent on this action
             $pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 0, 'WakeOnLan have not return state', 1);
         }
         //}
     }
     if ($computerip == '0') {
         $pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 1, "No IP found on the computer");
     }
     //}
     return $this->message;
 }