/** * After rule engine passed, update task (log) and create item if required * * @param type $items_id * @param type $itemtype * @param type $entities_id */ function rulepassed($items_id, $itemtype, $entities_id = 0) { PluginFusioninventoryLogger::logIfExtradebug("pluginFusioninventory-rules", "Rule passed : " . $items_id . ", " . $itemtype . "\n"); PluginFusioninventoryLogger::logIfExtradebugAndDebugMode('fusioninventorycommunication', 'Function PluginFusinvsnmpCommunicationNetDiscovery->rulepassed().'); if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = "'" . $entities_id . "'"; } $_SESSION['glpiactive_entity'] = $entities_id; $item = new $itemtype(); if ($items_id == "0") { $input = array(); $input['date_mod'] = date("Y-m-d H:i:s"); $input['entities_id'] = $entities_id; $items_id = $item->add($input); if (isset($_SESSION['plugin_fusioninventory_rules_id'])) { $pfRulematchedlog = new PluginFusioninventoryRulematchedlog(); $inputrulelog = array(); $inputrulelog['date'] = date('Y-m-d H:i:s'); $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id']; if (isset($_SESSION['plugin_fusioninventory_agents_id'])) { $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id']; } $inputrulelog['items_id'] = $items_id; $inputrulelog['itemtype'] = $itemtype; $inputrulelog['method'] = 'netdiscovery'; $pfRulematchedlog->add($inputrulelog); $pfRulematchedlog->cleanOlddata($items_id, $itemtype); unset($_SESSION['plugin_fusioninventory_rules_id']); } if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = "'" . $entities_id . "'"; } $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] ==addtheitem== ' . $item->getTypeName() . ' [[' . $itemtype . '::' . $items_id . ']]'; $this->addtaskjoblog(); } else { $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] ==updatetheitem== ' . $item->getTypeName() . ' [[' . $itemtype . '::' . $items_id . ']]'; $this->addtaskjoblog(); } $item->getFromDB($items_id); $this->importDevice($item); }
/** * After rules import device * * @param integer $items_id id of the device in GLPI DB (0 = created, other = merge) * @param varchar $itemtype itemtype of the device * * @return type */ function rulepassed($items_id, $itemtype) { PluginFusioninventoryLogger::logIfExtradebug("pluginFusioninventory-rules", "Rule passed : " . $items_id . ", " . $itemtype . "\n"); PluginFusioninventoryLogger::logIfExtradebugAndDebugMode('fusioninventorycommunication', 'Function PluginFusinvsnmpCommunicationSNMPQuery->rulepassed().'); $_SESSION["plugin_fusioninventory_entity"] = 0; PluginFusioninventoryConfig::logIfExtradebug("pluginFusioninventory-rules", "Rule passed : " . $items_id . ", " . $itemtype . "\n"); PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkInventory->rulepassed().'); $a_inventory = $_SESSION['SOURCE_XMLDEVICE']; $errors = ''; $class = new $itemtype(); if ($items_id == "0") { $input = array(); $input['date_mod'] = date("Y-m-d H:i:s"); if ($class->getFromDB($a_inventory[$a_inventory['itemtype']]['id'])) { $input['entities_id'] = $class->fields['entities_id']; } else { $input['entities_id'] = 0; } if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = "'" . $input['entities_id'] . "'"; } $_SESSION["plugin_fusioninventory_entity"] = $input['entities_id']; $items_id = $class->add($input); if (isset($_SESSION['plugin_fusioninventory_rules_id'])) { $pfRulematchedlog = new PluginFusioninventoryRulematchedlog(); $inputrulelog = array(); $inputrulelog['date'] = date('Y-m-d H:i:s'); $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id']; if (isset($_SESSION['plugin_fusioninventory_agents_id'])) { $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id']; } $inputrulelog['items_id'] = $items_id; $inputrulelog['itemtype'] = $itemtype; $inputrulelog['method'] = 'snmpinventory'; $pfRulematchedlog->add($inputrulelog); $pfRulematchedlog->cleanOlddata($items_id, $itemtype); unset($_SESSION['plugin_fusioninventory_rules_id']); } } if ($itemtype == "PluginFusioninventoryUnmanaged") { $class->getFromDB($items_id); $input = array(); $input['id'] = $class->fields['id']; if (!empty($a_inventory[$a_inventory['itemtype']]['name'])) { $input['name'] = $a_inventory[$a_inventory['itemtype']]['name']; } if (!empty($a_inventory[$a_inventory['itemtype']]['serial'])) { $input['serial'] = $a_inventory[$a_inventory['itemtype']]['serial']; } if (!empty($a_inventory['itemtype'])) { $input['itemtype'] = $a_inventory['itemtype']; } // TODO : add import ports PluginFusioninventoryToolbox::writeXML($items_id, serialize($_SESSION['SOURCE_XMLDEVICE']), 'PluginFusioninventoryUnmanaged'); $class->update($input); $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] ==updatetheitem== Update ' . PluginFusioninventoryUnmanaged::getTypeName() . ' [[PluginFusioninventoryUnmanaged::' . $items_id . ']]'; $this->addtaskjoblog(); } else { $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] Update ' . $class->getTypeName() . ' [[' . $itemtype . '::' . $items_id . ']]'; $this->addtaskjoblog(); $errors .= $this->importDevice($itemtype, $items_id, $a_inventory); } return $errors; }