/** * Import the content (where have all devices) *@param $p_content CONTENT code to import * *@return errors string to be alimented if import ko / '' if ok **/ function importContent($arrayinventory) { PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkInventory->importContent().'); $pfAgent = new PluginFusioninventoryAgent(); $errors = ''; $nbDevices = 0; foreach ($arrayinventory as $childname => $child) { PluginFusioninventoryCommunication::addLog($childname); switch ($childname) { case 'DEVICE': $a_devices = array(); if (is_int(key($child))) { $a_devices = $child; } else { $a_devices[] = $child; } $xml_num = 0; foreach ($a_devices as $dchild) { $_SESSION['plugin_fusioninventory_xmlnum'] = $xml_num; $a_inventory = array(); if (isset($dchild['INFO'])) { if ($dchild['INFO']['TYPE'] == "NETWORKING") { $a_inventory = PluginFusioninventoryFormatconvert::networkequipmentInventoryTransformation($dchild); } else { if ($dchild['INFO']['TYPE'] == "PRINTER") { $a_inventory = PluginFusioninventoryFormatconvert::printerInventoryTransformation($dchild); } } } if (isset($dchild['ERROR'])) { $itemtype = ""; if ($dchild['ERROR']['TYPE'] == "NETWORKING") { $itemtype = "NetworkEquipment"; } else { if ($dchild['ERROR']['TYPE'] == "PRINTER") { $itemtype = "Printer"; } } $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] ' . $dchild['ERROR']['MESSAGE'] . ' [[' . $itemtype . '::' . $dchild['ERROR']['ID'] . ']]'; $this->addtaskjoblog(); } else { if ($a_inventory['PluginFusioninventory' . $a_inventory['itemtype']]['sysdescr'] == '' && $a_inventory[$a_inventory['itemtype']]['name'] == '' && $a_inventory[$a_inventory['itemtype']]['serial'] == '') { $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] No informations [[' . $a_inventory['itemtype'] . '::' . $dchild['INFO']['ID'] . ']]'; $this->addtaskjoblog(); } else { if (count($a_inventory) > 0) { $errors .= $this->sendCriteria($a_inventory); $nbDevices++; } } } $xml_num++; } break; case 'AGENT': if (isset($this->arrayinventory['CONTENT']['AGENT']['AGENTVERSION'])) { $agent = $pfAgent->InfosByKey($this->arrayinventory['DEVICEID']); $agent['fusioninventory_agent_version'] = $this->arrayinventory['CONTENT']['AGENT']['AGENTVERSION']; $agent['last_agent_update'] = date("Y-m-d H:i:s"); $pfAgent->update($agent); } break; case 'PROCESSNUMBER': break; case 'MODULEVERSION': break; default: $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] ' . __('Unattended element in', 'fusioninventory') . ' CONTENT : ' . $childname; $this->addtaskjoblog(); } } return $errors; }
/** * @test */ public function NetworkEquipmentConnectionMac() { global $DB; $DB->connect(); $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $a_inventory = array(); $a_inventory['INFO'] = array('COMMENTS' => 'Cisco IOS Software, C3750 Software (C3750-IPSERVICESK9-M), Version 12.2(55)SE, RELEASE SOFTWARE (fc2) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2010 by Cisco Systems, Inc. Compiled Sat 07-Aug-10 22:45 by prod_rel_team', 'ID' => '55', 'MAC' => '00:1b:2b:20:40:80', 'NAME' => 'sw1.siprossii.com', 'SERIAL' => 'CAT1109RGVK', 'TYPE' => 'NETWORKING'); $a_inventory['PORTS']['PORT'][1] = array('CONNECTIONS' => array('CONNECTION' => array('MAC' => array('00:0f:fe:0d:30:70'))), 'IFNAME' => 'Fa0/1', 'IFNUMBER' => 1, 'IFTYPE' => 6, 'MAC' => 'b4:39:d6:3a:7f:3a'); $a_inventory['PORTS']['PORT'][2] = array('CONNECTIONS' => array('CONNECTION' => array('MAC' => array('00:0f:fe:0d:30:76', '00:0f:fe:0d:30:77', '00:0f:fe:0d:30:78'))), 'IFNAME' => 'Fa0/2', 'IFNUMBER' => 2, 'IFTYPE' => 6, 'MAC' => 'b4:39:d6:3a:7f:3e'); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_return = $pfFormatconvert->networkequipmentInventoryTransformation($a_inventory); $a_reference = array('00:0f:fe:0d:30:70'); $this->assertEquals($a_reference, $a_return['connection-mac'][1]); $a_reference = array(); $a_reference = array('00:0f:fe:0d:30:76', '00:0f:fe:0d:30:77', '00:0f:fe:0d:30:78'); $this->assertEquals($a_reference, $a_return['connection-mac'][2]); $GLPIlog = new GLPIlogs(); $GLPIlog->testSQLlogs(); $GLPIlog->testPHPlogs(); }