Пример #1
0
 /**
  * @param CommonGLPI $item
  * @param int $tabnum
  * @param int $withtemplate
  * @return bool
  */
 static function displayTabContentForItem(CommonGLPI $item, $tabnum = 0, $withtemplate = 0)
 {
     if ($item->getType() == __CLASS__) {
         $ocs = new PluginOcsinventoryngOcsServer();
         $ipdisc = new PluginOcsinventoryngIpdiscoverOcslink();
         $snmp = new PluginOcsinventoryngSnmpOcslink();
         switch ($tabnum) {
             case 0:
                 $ocs->setupMenu($_SESSION["plugin_ocsinventoryng_ocsservers_id"]);
                 break;
             case 1:
                 $ocs->importMenu($_SESSION["plugin_ocsinventoryng_ocsservers_id"]);
                 break;
             case 2:
                 $ipdisc->ipDiscoverMenu();
                 break;
             case 3:
                 $snmp->snmpMenu($_SESSION["plugin_ocsinventoryng_ocsservers_id"]);
                 break;
         }
     }
     return true;
 }
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");
}
/**
 * @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;
}
Пример #4
0
    if (!isset($_GET['start'])) {
        $_GET['start'] = 0;
    }
    if (isset($_SESSION["ocs_linksnmp"])) {
        unset($_SESSION["ocs_linksnmp"]);
    }
    $values = $_GET;
    if (isset($_POST["search"])) {
        $values = $_POST;
    }
    $values['plugin_ocsinventoryng_ocsservers_id'] = $_SESSION["plugin_ocsinventoryng_ocsservers_id"];
    //$values['change_import_mode'] = $_SESSION["change_import_mode"];
    //$values['glpiactiveentities'] = $_SESSION["glpiactiveentities"];
    $values['tolinked'] = 1;
    PluginOcsinventoryngSnmpOcslink::searchForm($values);
    PluginOcsinventoryngSnmpOcslink::showSnmpDeviceToAdd($values);
} else {
    if (isset($_POST['tolink_items']) && count($_POST['tolink_items']) > 0) {
        $_SESSION["ocs_linksnmp_count"] = 0;
        foreach ($_POST['tolink_items'] as $key => $val) {
            if ($val) {
                $_SESSION["ocs_linksnmp"]["id"][] = $key;
                $_SESSION["ocs_linksnmp"]["items"][$key] = $_POST['tolink_items'][$key];
            }
            $_SESSION["ocs_linksnmp_count"]++;
        }
        foreach ($_POST['tolink_itemtype'] as $key => $val) {
            if ($val) {
                $_SESSION["ocs_linksnmp"]["itemtype"][$key] = $_POST['tolink_itemtype'][$key];
            }
        }
Пример #5
0
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';
Session::checkRight("plugin_ocsinventoryng", UPDATE);
Html::header('OCS Inventory NG', '', "tools", "pluginocsinventoryngmenu", "syncsnmp");
$display_list = true;
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']);