/**
  * @test
  */
 public function AddNetworkEquipment()
 {
     global $DB;
     self::restore_database();
     $this->update_time = date('Y-m-d H:i:s');
     $a_inventory = array('PluginFusioninventoryNetworkEquipment' => array('sysdescr' => 'Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 12.2(50)SE4, RELEASE SOFTWARE (fc1)\\nTechnical Support: http://www.cisco.com/techsupport\\nCopyright (c) 1986-2010 by Cisco Systems, Inc.\\nCompiled Fri 26-Mar-10 09:14 by prod_rel_team', 'last_fusioninventory_update' => $this->update_time, 'cpu' => 5, 'memory' => 18, 'uptime' => '157 days, 02:14:44.00'), 'networkport' => array(), 'connection-mac' => array(), 'vlans' => array(), 'connection-lldp' => array(), 'internalport' => array('192.168.30.2'), 'itemtype' => 'NetworkEquipment');
     $a_inventory['NetworkEquipment'] = array('name' => 'switchr2d2', 'id' => 96, 'serial' => 'FOC147UJXXX', 'otherserial' => '', 'manufacturers_id' => 29, 'locations_id' => 3, 'networkequipmentmodels_id' => 3, 'networkequipmentfirmwares_id' => 3, 'memory' => 18, 'ram' => 64, 'is_dynamic' => 1, 'mac' => '6c:50:4d:39:59:90');
     $a_inventory['networkport'] = array('10001' => array('ifdescr' => 'FastEthernet0/1', 'ifinerrors' => 869, 'ifinoctets' => 1953319640, 'ifinternalstatus' => 1, 'iflastchange' => '156 days, 08:37:22.84', 'ifmtu' => 1500, 'name' => 'Fa0/1', 'logical_number' => 10001, 'ifouterrors' => 0, 'ifoutoctets' => 554008368, 'speed' => 100000000, 'ifstatus' => 1, 'iftype' => 6, 'mac' => '6c:50:4d:39:59:81', 'trunk' => 0, 'ifspeed' => 100000000));
     $a_inventory['connection-mac'] = array('10001' => array('cc:f9:54:a1:03:45'));
     $a_inventory['vlans'] = array();
     $a_inventory['connection-lldp'] = array();
     $pfiNetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib();
     $networkEquipment = new NetworkEquipment();
     $this->items_id = $networkEquipment->add(array('serial' => 'FOC147UJXXX', 'entities_id' => 0));
     $this->assertGreaterThan(0, $this->items_id);
     $pfiNetworkEquipmentLib->updateNetworkEquipment($a_inventory, $this->items_id);
     // To be sure not have 2 same informations
     $pfiNetworkEquipmentLib->updateNetworkEquipment($a_inventory, $this->items_id);
 }
 /**
  * @test
  */
 public function AddNetworkEquipment()
 {
     global $DB;
     $DB->connect();
     $DB->query("UPDATE `glpi_plugin_fusioninventory_networkporttypes`" . " SET `import`='1'" . " WHERE `number`='54'");
     $this->datelatupdate = date('Y-m-d H:i:s');
     $a_inventory = array('PluginFusioninventoryNetworkEquipment' => array('sysdescr' => 'Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 12.2(50)SE4, RELEASE SOFTWARE (fc1)\\nTechnical Support: http://www.cisco.com/techsupport\\nCopyright (c) 1986-2010 by Cisco Systems, Inc.\\nCompiled Fri 26-Mar-10 09:14 by prod_rel_team', 'last_fusioninventory_update' => $this->datelatupdate, 'cpu' => 5, 'memory' => 18, 'uptime' => '157 days, 02:14:44.00'), 'networkport' => array(), 'connection-mac' => array(), 'vlans' => array(), 'connection-lldp' => array(), 'internalport' => array('192.168.30.67', '192.168.40.67', '192.168.50.67'), 'itemtype' => 'NetworkEquipment');
     $a_inventory['NetworkEquipment'] = array('name' => 'switchr2d2', 'id' => 96, 'serial' => 'FOC147UJEU4', 'manufacturers_id' => 29, 'locations_id' => 3, 'networkequipmentmodels_id' => 3, 'networkequipmentfirmwares_id' => 3, 'memory' => 18, 'ram' => 64, 'is_dynamic' => 1, 'mac' => '6c:50:4d:39:59:80');
     $a_inventory['networkport'] = array('10001' => array('ifdescr' => 'FastEthernet0/1', 'ifinerrors' => 869, 'ifinoctets' => 1953319640, 'ifinternalstatus' => 1, 'iflastchange' => '156 days, 08:37:22.84', 'ifmtu' => 1500, 'name' => 'Fa0/1', 'logical_number' => 10001, 'ifouterrors' => 0, 'ifoutoctets' => 554008368, 'speed' => 100000000, 'ifstatus' => 1, 'iftype' => 6, 'mac' => '6c:50:4d:39:59:81', 'trunk' => 0, 'ifspeed' => 100000000), '10002' => array('ifdescr' => 'FastEthernet0/2', 'ifinerrors' => 0, 'ifinoctets' => 1953319640, 'ifinternalstatus' => 1, 'iflastchange' => '53.53 seconds', 'ifmtu' => 1500, 'name' => 'Fa0/2', 'logical_number' => 10002, 'ifouterrors' => 0, 'ifoutoctets' => 554008368, 'speed' => 10000000, 'ifstatus' => 1, 'iftype' => 6, 'mac' => '6c:50:4d:39:59:82', 'trunk' => 1, 'ifspeed' => 10000000), '5005' => array('ifdescr' => 'Port-channel10', 'ifinerrors' => 0, 'ifinoctets' => 1076823325, 'ifinternalstatus' => 1, 'iflastchange' => '53.53 seconds', 'ifmtu' => 1500, 'name' => 'Po10', 'logical_number' => 5005, 'ifouterrors' => 0, 'ifoutoctets' => 2179528910, 'speed' => 4294967295, 'ifstatus' => 1, 'iftype' => 53, 'mac' => '6c:50:4d:39:59:88', 'trunk' => 1, 'ifspeed' => 4294967295), '5006' => array('ifdescr' => 'vlan0', 'ifinerrors' => 0, 'ifinoctets' => 1076823325, 'ifinternalstatus' => 1, 'iflastchange' => '53.53 seconds', 'ifmtu' => 1500, 'name' => 'vlan0', 'logical_number' => 5006, 'ifouterrors' => 0, 'ifoutoctets' => 2179528910, 'speed' => 4294967295, 'ifstatus' => 1, 'iftype' => 54, 'mac' => '6c:50:4d:39:59:89', 'trunk' => 1, 'ifspeed' => 4294967295));
     $a_inventory['connection-mac'] = array('10001' => array('cc:f9:54:a1:03:35'), '10002' => array('cc:f9:54:a1:03:36'));
     $a_inventory['vlans'] = array('10001' => array('281' => array('name' => 'printer', 'tag' => 281)), '10002' => array('281' => array('name' => 'printer', 'tag' => 281), '280' => array('name' => 'admin', 'tag' => 280)));
     $a_inventory['connection-lldp'] = array('10002' => array('ifdescr' => 'GigabitEthernet1/0/2', 'ip' => '192.168.100.100', 'model' => 'cisco WS-C3750G-24PS', 'sysdescr' => 'Cisco IOS Software, C3750 Software (C3750-ADVIPSERVICESK9-M), Version 12.2(46)SE, RELEASE SOFTWARE (fc2)\\nCopyright (c) 1986-2008 by Cisco Systems, Inc.\\nCompiled Thu 21-Aug-08 15:43 by nachen', 'name' => 'CENTRALSWITCH', 'logical_number' => '', 'mac' => ''));
     $a_inventory['aggregate'] = array('5005' => array('10001', '10002'));
     $pfiNetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib();
     $networkEquipment = new NetworkEquipment();
     $this->items_id = $networkEquipment->add(array('serial' => 'FOC147UJEU4', 'entities_id' => 0));
     $this->assertGreaterThan(0, $this->items_id);
     $pfiNetworkEquipmentLib->updateNetworkEquipment($a_inventory, $this->items_id);
     $DB->query("UPDATE `glpi_plugin_fusioninventory_networkporttypes`" . " SET `import`='0'" . " WHERE `number`='54'");
     // To be sure not have 2 sme informations
     $pfiNetworkEquipmentLib->updateNetworkEquipment($a_inventory, $this->items_id);
 }
 /**
  * @test
  */
 public function Cisco2Switch()
 {
     global $DB;
     $DB->connect();
     self::restore_database();
     $a_lldp = array('ifdescr' => 'ge-0/0/1.0', 'logical_number' => '504', 'sysdescr' => 'Juniper Networks, Inc. ex2200-24t-4g , version 10.1R1.8 Build date: 2010-02-12 16:59:31 UTC ', 'model' => '', 'ip' => '', 'mac' => '2c:6b:f5:98:f9:70', 'name' => 'juniperswitch3');
     $pfINetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib();
     $networkEquipment = new NetworkEquipment();
     $networkport = new NetworkPort();
     $pfNetworkPort = new PluginFusioninventoryNetworkPort();
     // Cisco switch
     $networkequipments_id = $networkEquipment->add(array('name' => 'cisco2', 'entities_id' => 0));
     $networkports_id = $networkport->add(array('itemtype' => 'NetworkEquipment', 'items_id' => $networkequipments_id, 'entities_id' => 0));
     // Another switch
     $networkequipments_other_id = $networkEquipment->add(array('name' => 'juniperswitch3', 'entities_id' => 0));
     // Port ge-0/0/1.0
     $networkports_other_id = $networkport->add(array('itemtype' => 'NetworkEquipment', 'items_id' => $networkequipments_other_id, 'entities_id' => 0, 'mac' => '2c:6b:f5:98:f9:70', 'logical_number' => 504));
     $pfNetworkPort->add(array('networkports_id' => $networkports_other_id, 'ifdescr' => 'ge-0/0/1.0'));
     $pfINetworkEquipmentLib->importConnectionLLDP($a_lldp, $networkports_id);
     $a_portslinks = getAllDatasFromTable('glpi_networkports_networkports');
     $this->assertEquals(1, count($a_portslinks), 'May have 1 connection between 2 network ports');
     $a_networkports = getAllDatasFromTable('glpi_networkports');
     $this->assertEquals(2, count($a_networkports), 'May have 2 network ports (' . print_r($a_networkports, TRUE) . ')');
     $a_ref = array('id' => 1, 'networkports_id_1' => $networkports_id, 'networkports_id_2' => $networkports_other_id);
     $this->assertEquals($a_ref, current($a_portslinks), 'Link port');
 }
 /**
  * Import one device
  *
  * @param type $itemtype
  * @param type $items_id
  *
  * @return errors string to be alimented if import ko / '' if ok
  */
 function importDevice($itemtype, $items_id, $a_inventory)
 {
     global $PLUGIN_FUSIONINVENTORY_XML;
     PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkInventory->importDevice().');
     $pfFormatconvert = new PluginFusioninventoryFormatconvert();
     $a_inventory = $pfFormatconvert->replaceids($a_inventory);
     // Write XML file
     if (count($a_inventory) > 0) {
         $xml = $PLUGIN_FUSIONINVENTORY_XML->CONTENT->DEVICE[$_SESSION['plugin_fusioninventory_xmlnum']]->asXML();
         PluginFusioninventoryToolbox::writeXML($items_id, $xml, $itemtype);
         //         $folder = substr($items_id, 0, -1);
         //         if (empty($folder)) {
         //            $folder = '0';
         //         }
         //         if (!file_exists(GLPI_PLUGIN_DOC_DIR."/fusioninventory/".$itemtype."/".$folder)) {
         //            mkdir(GLPI_PLUGIN_DOC_DIR."/fusioninventory/".$itemtype."/".$folder, 0777, TRUE);
         //         }
         //         $fileopen = fopen(GLPI_PLUGIN_DOC_DIR."/fusioninventory/".$itemtype."/".$folder."/".
         //                           $items_id, 'w');
         //         fwrite($fileopen, print_r($a_inventory, TRUE));
         //         fclose($fileopen);
     }
     $errors = '';
     $this->deviceId = $items_id;
     $serialized = gzcompress(serialize($a_inventory));
     if (isset($a_inventory['name']) && $a_inventory['name'] == '') {
         unset($a_inventory['name']);
     }
     if (isset($a_inventory['serial']) && $a_inventory['serial'] == '') {
         unset($a_inventory['serial']);
     }
     switch ($itemtype) {
         case 'Printer':
             $pfiPrinterLib = new PluginFusioninventoryInventoryPrinterLib();
             $a_inventory['PluginFusioninventoryPrinter']['serialized_inventory'] = Toolbox::addslashes_deep($serialized);
             $pfiPrinterLib->updatePrinter($a_inventory, $items_id);
             break;
         case 'NetworkEquipment':
             $pfiNetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib();
             $a_inventory['PluginFusioninventoryNetworkEquipment']['serialized_inventory'] = Toolbox::addslashes_deep($serialized);
             $pfiNetworkEquipmentLib->updateNetworkEquipment($a_inventory, $items_id);
             break;
         default:
             $errors .= __('Unattended element in', 'fusioninventory') . ' TYPE : ' . $a_inventory['itemtype'] . "\n";
     }
 }