/** * @param $threads_id * @param $cfg_ocs * @param $server * @param $thread_nbr * @param $threadid * @param $fields * @param $config * * @return mixed */ function importSNMPFromOcsServer($threads_id, $cfg_ocs, $server, $thread_nbr, $threadid, $fields, $config) { global $DB; echo "\tThread #" . $threadid . ": synchronize SNMP objects from server: '" . $cfg_ocs["name"] . "'\n"; $multiThread = false; if ($threadid != -1 && $thread_nbr > 1) { $multiThread = true; } $ocsServerId = $cfg_ocs['id']; $ocsClient = PluginOcsinventoryngOcsServer::getDBocs($ocsServerId); $already_linked_query = "SELECT `glpi_plugin_ocsinventoryng_snmpocslinks`.`ocs_id`,`glpi_plugin_ocsinventoryng_snmpocslinks`.`id`\n FROM `glpi_plugin_ocsinventoryng_snmpocslinks`\n WHERE `glpi_plugin_ocsinventoryng_snmpocslinks`.`plugin_ocsinventoryng_ocsservers_id`\n = '{$ocsServerId}'"; $already_linked_result = $DB->query($already_linked_query); $already_linked_ids = array(); if ($DB->numrows($already_linked_result) > 0) { while ($data = $DB->fetch_assoc($already_linked_result)) { $already_linked_ocs_ids[] = $data['ocs_id']; // $already_linked_ids [] = $data['id']; } } $ocsResult = $ocsClient->getSnmp(array('ORDER' => 'LASTDATE', 'COMPLETE' => '0', 'FILTER' => array('IDS' => $already_linked_ocs_ids))); //Unset SNMP objects not updated by OCS foreach ($ocsResult['SNMP'] as $ID => $snmpids) { $last_update = date('Y-m-d H:m:s'); //Compute lastest synchronization date $query = "SELECT `last_update`\n FROM `glpi_plugin_ocsinventoryng_snmpocslinks`\n WHERE `ocs_id` = '{$ID}'"; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { if ($DB->result($result, 0, 0) != '') { $last_update = $DB->result($result, 0, 0); } } } if ($snmpids['META']['LASTDATE'] < $last_update) { if (($key = array_search($ID, $already_linked_ocs_ids)) !== false) { unset($already_linked_ocs_ids[$key]); } } } $already_linked_ids = array(); //List definitive SNMP objects to update if (count($already_linked_ocs_ids) > 0) { $query = "SELECT `glpi_plugin_ocsinventoryng_snmpocslinks`.`id`\n FROM `glpi_plugin_ocsinventoryng_snmpocslinks`\n WHERE `ocs_id` IN (" . implode(",", $already_linked_ocs_ids) . ")"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_assoc($result)) { $already_linked_ids[] = $data['id']; } } } $nb = count($already_linked_ids); echo "\tThread #{$threadid}: {$nb} object(s)\n"; $fields["total_number_machines"] += $nb; // $thread = new PluginOcsinventoryngThread(); // $notimport = new PluginOcsinventoryngNotimportedcomputer(); // $i = 0; foreach ($already_linked_ids as $ID) { /* TODO create thread & update it ? * if ($i == $config->fields["thread_log_frequency"]) { $fields["status"] = PLUGIN_OCSINVENTORYNG_STATE_RUNNING; $thread->update($fields); $i = 0; } else { $i++; }*/ echo "."; $action = PluginOcsinventoryngSnmpOcslink::updateSnmp($ID, $ocsServerId); PluginOcsinventoryngOcsServer::manageImportStatistics($fields, $action['status']); /* TODO log it ? /*switch ($action['status']) { case PluginOcsinventoryngOcsServer::SNMP_FAILED_IMPORT: $notimport->logNotImported($ocsServerId, $ID, $action); break; default: $notimport->cleanNotImported($ocsServerId, $ID); //Log detail $detail = new PluginOcsinventoryngDetail(); $detail->logProcessedComputer($ID, $ocsServerId, $action, $threadid, $threads_id); break; }*/ } return $fields; }
https://github.com/pluginsGLPI/ocsinventoryng ------------------------------------------------------------------------- LICENSE This file is part of ocsinventoryng. ocsinventoryng is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ocsinventoryng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ocsinventoryng. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include '../../../inc/includes.php'; if (isset($_POST["force_ocssnmp_resynch"])) { $item = new $_POST['itemtype'](); $item->check($_POST['items_id'], UPDATE); PluginOcsinventoryngSnmpOcslink::updateSnmp($_POST["id"], $_POST["plugin_ocsinventoryng_ocsservers_id"]); Html::back(); } else { Html::displayErrorAndDie("lost"); }
if (isset($_POST["delete"]) && isset($_POST["toupdate"])) { if ($count = count($_POST["toupdate"])) { foreach ($_POST['toupdate'] as $key => $val) { if ($val == "on") { $link = new PluginOcsinventoryngSnmpOcslink(); $link->delete(array('id' => $key), 1); } } Html::redirect($_SERVER['PHP_SELF']); } } if (isset($_SESSION["ocs_updatesnmp"]['id'])) { if ($count = count($_SESSION["ocs_updatesnmp"]['id'])) { $percent = min(100, round(100 * ($_SESSION["ocs_updatesnmp_count"] - $count) / $_SESSION["ocs_updatesnmp_count"], 0)); $key = array_pop($_SESSION["ocs_updatesnmp"]['id']); $action = PluginOcsinventoryngSnmpOcslink::updateSnmp($key, $_SESSION["plugin_ocsinventoryng_ocsservers_id"]); PluginOcsinventoryngOcsServer::manageImportStatistics($_SESSION["ocs_updatesnmp"]['statistics'], $action['status'], true); PluginOcsinventoryngOcsServer::showStatistics($_SESSION["ocs_updatesnmp"]['statistics'], false, true); Html::displayProgressBar(400, $percent); Html::redirect($_SERVER['PHP_SELF']); } else { if (isset($_SESSION["ocs_updatesnmp"]['statistics'])) { PluginOcsinventoryngOcsServer::showStatistics($_SESSION["ocs_updatesnmp"]['statistics'], false, true); } else { echo "<div class='center b red'>"; _e('No synchronization: the plugin will not synchronize these elements', 'ocsinventoryng'); echo "</div>"; } unset($_SESSION["ocs_updatesnmp"]); $display_list = false; echo "<div class='center b'><br>";