/** * Used to add log in the task */ function addtaskjoblog() { $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $pfTaskjoblog->addTaskjoblog($_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'], $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'], $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'], $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'], $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment']); }
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; }
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; }
/** * 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; }