/**
  * Get agents can do a "module name"
  *
  * @param $module_name value Name of the module
  *
  * @return array of agents
  *
  **/
 function getAgentsCanDo($module_name)
 {
     $pfAgent = new PluginFusioninventoryAgent();
     if ($module_name == 'SNMPINVENTORY') {
         $module_name = 'SNMPQUERY';
     }
     $agentModule = $this->getActivationExceptions($module_name);
     $where = "";
     if ($agentModule['is_active'] == 0) {
         $a_agentList = importArrayFromDB($agentModule['exceptions']);
         if (count($a_agentList) > 0) {
             $where = " `id` IN (";
             $i = 0;
             $sep = '';
             foreach ($a_agentList as $agent_id) {
                 if ($i > 0) {
                     $sep = ', ';
                 }
                 $where .= $sep . $agent_id;
                 $i++;
             }
             $where .= ") ";
             if (isset($_SESSION['glpiactiveentities_string'])) {
                 $where .= getEntitiesRestrictRequest("AND", $pfAgent->getTable());
             }
         } else {
             return array();
         }
     } else {
         $a_agentList = importArrayFromDB($agentModule['exceptions']);
         if (count($a_agentList) > 0) {
             $where = " `id` NOT IN (";
             $i = 0;
             $sep = '';
             foreach ($a_agentList as $agent_id) {
                 if ($i > 0) {
                     $sep = ', ';
                 }
                 $where .= $sep . $agent_id;
                 $i++;
             }
             $where .= ") ";
             if (isset($_SESSION['glpiactiveentities_string'])) {
                 $where .= getEntitiesRestrictRequest("AND", $pfAgent->getTable());
             }
         }
     }
     $a_agents = $pfAgent->find($where);
     return $a_agents;
 }
 /**
  * Import agent : create if not exist and update if yet exist
  *
  * @param $p_xml simpleXMLobject
  *
  **/
 function importToken($arrayinventory)
 {
     if (isset($arrayinventory['DEVICEID'])) {
         $pfAgent = new PluginFusioninventoryAgent();
         $a_agent = $pfAgent->find("`device_id`='" . $arrayinventory['DEVICEID'] . "'", "", "1");
         if (empty($a_agent)) {
             $a_input = array();
             if (isset($arrayinventory['TOKEN'])) {
                 $a_input['token'] = $arrayinventory['TOKEN'];
             }
             $a_input['name'] = $arrayinventory['DEVICEID'];
             $a_input['device_id'] = $arrayinventory['DEVICEID'];
             $a_input['entities_id'] = 0;
             $a_input['last_contact'] = date("Y-m-d H:i:s");
             if (isset($_SERVER['HTTP_USER_AGENT'])) {
                 $a_input['useragent'] = $_SERVER['HTTP_USER_AGENT'];
             }
             return $pfAgent->add($a_input);
         } else {
             foreach ($a_agent as $data) {
                 $input = array();
                 $input['id'] = $data['id'];
                 if (isset($arrayinventory['TOKEN'])) {
                     $input['token'] = $arrayinventory['TOKEN'];
                 }
                 $input['last_contact'] = date("Y-m-d H:i:s");
                 if (isset($_SERVER['HTTP_USER_AGENT'])) {
                     $input['useragent'] = $_SERVER['HTTP_USER_AGENT'];
                 }
                 $pfAgent->update($input);
                 return $data['id'];
             }
         }
     }
     return;
 }
예제 #3
0
 /**
  * @test
  */
 public function newAgentChangeEntity()
 {
     $pfAgent = new PluginFusioninventoryAgent();
     // Load Agent
     $this->assertTrue($pfAgent->getFromDBByQuery("WHERE `device_id` = 'port004.bureau.siprossii.com-2013-01-01-16-27-27' " . "LIMIT 1"), "Could not load agent");
     $pfAgent->setAgentWithComputerid(100, 'port004.bureau.siprossii.com-2013-01-01-16-27-27', 0);
     $pfAgent = new PluginFusioninventoryAgent();
     $a_agents = current($pfAgent->find("`computers_id`='100'"));
     $this->assertEquals(0, $a_agents['entities_id']);
 }
$docopt = new \Docopt\Handler();
$args = $docopt->handle($doc);
$logger = new Logging();
$logger->setLevelFromArgs($args['--quiet'], $args['--debug']);
$logger->debug($args);
$agent = new PluginFusioninventoryAgent();
$computer = new Computer();
$task = new PluginFusioninventoryTask();
$staticmisc_methods = PluginFusioninventoryStaticmisc::getmethods();
$methods = array();
foreach ($staticmisc_methods as $method) {
    $methods[$method['method']] = $method['method'];
}
$device_ids = array();
if (count($args['<device_ids>']) == 0) {
    $agents = array_values($agent->find());
    $randid = rand(0, count($agents));
    $device_ids = array($agents[$randid]['device_id']);
} else {
    //$agents = $agent->find("device_id in ('".implode("','", $args['<device_ids>'])."')");
    //$device_ids[] = $agent_data['device_id'];
    $device_ids = $args['<device_ids>'];
}
//$logger->debug($device_ids);
foreach ($device_ids as $device_id) {
    $logger->info("Get prepared jobs for Agent '{$device_id}'");
    //   $jobstates = $task->getTaskjobstatesForAgent($device_id, $methods, array('read_only'=>true));
    //   $jobstates = $task->getTaskjobstatesForAgent($device_id, $methods);
    $time = microtime(true);
    file_get_contents("http://glpi.kroy-laptop.sandbox/glpi/plugins/fusioninventory/b/deploy/?action=getJobs&machineid=" . $device_id);
    $time = microtime(true) - $time;