/** * @test */ public function updatePrinterFromNetdiscovery() { global $DB; $DB->connect(); $pfCNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery(); $GLPIlog = new GLPIlogs(); $networkName = new NetworkName(); $iPAddress = new IPAddress(); $_SESSION['SOURCE_XMLDEVICE'] = array('AUTHSNMP' => '1', 'DESCRIPTION' => 'Photosmart D7200 series', 'ENTITY' => '0', 'FIRMWARE' => '', 'IP' => '192.168.20.102', 'MAC' => '00:21:5a:0b:bb:c4', 'MANUFACTURER' => 'Hewlett-Packard', 'MODEL' => '', 'MODELSNMP' => 'Printer0093', 'NETBIOSNAME' => 'HP00215A0BBBC4', 'SERIAL' => 'MY89AQG0V9050N', 'SNMPHOSTNAME' => 'HP0BBBC4new', 'TYPE' => 'PRINTER'); $printer = new Printer(); $a_printers = $printer->find("`serial`='MY89AQG0V9050N'"); $a_printer = current($a_printers); $printers_id = $a_printer['id']; $printer->getFromDB($printers_id); $pfCNetworkDiscovery->importDevice($printer); $GLPIlog->testSQLlogs(); $GLPIlog->testPHPlogs(); $printer->getFromDB($printers_id); $this->assertEquals('HP0BBBC4new', $printer->fields['name'], 'Name must be updated'); $a_printerextends = getAllDatasFromTable('glpi_plugin_fusioninventory_printers', "`printers_id`='" . $printers_id . "'"); $this->assertEquals('1', count($a_printerextends), 'May have one printer extend line for this printer'); $a_printerextend = current($a_printerextends); $this->assertEquals('1', $a_printerextend['plugin_fusioninventory_configsecurities_id'], 'SNMPauth may be with id 1'); $this->assertEquals('Photosmart D7200 series', $a_printerextend['sysdescr'], 'Sysdescr not updated correctly'); // Check mac $networkPort = new NetworkPort(); $a_ports = $networkPort->find("`itemtype`='Printer' AND `items_id`='" . $printers_id . "'"); $this->assertEquals('1', count($a_ports), 'May have one network port'); $a_port = current($a_ports); $this->assertEquals('00:21:5a:0b:bb:c4', $a_port['mac'], 'Mac address'); // check ip $a_networknames = $networkName->find("`itemtype`='NetworkPort'\n AND `items_id`='" . $a_port['id'] . "'"); $this->assertEquals('1', count($a_networknames), 'May have one networkname'); $a_networkname = current($a_networknames); $a_ipaddresses = $iPAddress->find("`itemtype`='NetworkName'\n AND `items_id`='" . $a_networkname['id'] . "'"); $this->assertEquals('1', count($a_ipaddresses), 'May have one IP address'); $a_ipaddress = current($a_ipaddresses); $this->assertEquals('192.168.20.102', $a_ipaddress['name'], 'IP address'); }
/** * @test */ public function PrinterDiscoveryImportDenied() { global $DB; $DB->connect(); $a_inventory = array('AUTHSNMP' => '1', 'DESCRIPTION' => 'Brother NC-6400h, Firmware Ver.1.11 (06.12.20),MID 84UZ92', 'ENTITY' => '0', 'FIRMWARE' => '', 'IP' => '10.36.4.29', 'MAC' => '00:80:77:d9:51:c3', 'MANUFACTURER' => 'Brother', 'MODEL' => '', 'MODELSNMP' => 'Printer0442', 'NETBIOSNAME' => 'UH4DLPT01', 'SERIAL' => 'E8J596100A', 'SNMPHOSTNAME' => 'UH4DLPT01', 'TYPE' => 'PRINTER'); $pfCommunicationNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery(); $printer = new Printer(); $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = 1; $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = '1'; $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'Printer'; $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = 0; $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = ''; $pfCommunicationNetworkDiscovery->sendCriteria($a_inventory); $a_printers = $printer->find(); $this->assertEquals(0, count($a_printers), 'May have only one Printer'); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $a_logs = $pfTaskjoblog->find("`comment` LIKE '%importdenied%'", '`id` DESC', 1); $a_log = current($a_logs); $this->assertEquals('==importdenied== [serial]:E8J596100A, ' . '[mac]:00:80:77:d9:51:c3, [ip]:10.36.4.29, [model]:Printer0442, ' . '[name]:UH4DLPT01, [entities_id]:0, [itemtype]:Printer', $a_log['comment'], 'Import denied message'); }
function import_netdiscovery($arrayinventory, $agentKey) { PluginFusioninventoryCommunication::addLog('Function PluginFusioninventorySnmpmodelImportExport->import_netdiscovery().'); $ptap = new PluginFusioninventoryStateDiscovery(); $pta = new PluginFusioninventoryAgent(); $agent = $pta->InfosByKey($agentKey); if (isset($arrayinventory['AGENT']['START'])) { $ptap->updateState($arrayinventory['PROCESSNUMBER'], array('start_time' => date("Y-m-d H:i:s")), $agent['id']); } else { if (isset($arrayinventory['AGENT']['END'])) { $ptap->updateState($arrayinventory['PROCESSNUMBER'], array('end_time' => date("Y-m-d H:i:s")), $agent['id']); } else { if (isset($arrayinventory['AGENT']['EXIT'])) { $ptap->endState($arrayinventory['PROCESSNUMBER'], date("Y-m-d H:i:s"), $agent['id']); } else { if (isset($arrayinventory['AGENT']['NBIP'])) { $ptap->updateState($arrayinventory['PROCESSNUMBER'], array('nb_ip' => $arrayinventory['AGENT']['NBIP']), $agent['id']); } } } } if (isset($arrayinventory['AGENT']['AGENTVERSION'])) { $agent['last_contact'] = date("Y-m-d H:i:s"); $pta->update($agent); } $_SESSION['glpi_plugin_fusioninventory_agentid'] = $agent['id']; $count_discovery_devices = 0; if (isset($arrayinventory['DEVICE'])) { if (is_int(key($arrayinventory['DEVICE']))) { $count_discovery_devices = count($arrayinventory['DEVICE']); } else { $count_discovery_devices = 1; } } if ($count_discovery_devices != "0") { $ptap->updateState($_SESSION['glpi_plugin_fusioninventory_processnumber'], array('nb_found' => $count_discovery_devices), $agent['id']); if (is_int(key($arrayinventory['DEVICE']))) { foreach ($arrayinventory['DEVICE'] as $discovery) { if (count($discovery) > 0) { $pfCommunicationNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery(); $pfCommunicationNetworkDiscovery->sendCriteria($discovery); } } } else { $pfCommunicationNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery(); $pfCommunicationNetworkDiscovery->sendCriteria($arrayinventory['DEVICE']); } } }
/** * @test */ public function UpdateNetworkEquipment() { // Load session rights $_SESSION['glpidefault_entity'] = 0; Session::initEntityProfiles(2); Session::changeProfile(4); // Update 2nd time $pfCND = new PluginFusioninventoryCommunicationNetworkDiscovery(); $networkEquipment = new NetworkEquipment(); $networkEquipment->getFromDB(1); $_SESSION['SOURCE_XMLDEVICE'] = $this->source_xmldevice; $pfCND->importDevice($networkEquipment); }
/** * @test * network discovery */ public function IgnoreNetworkDiscoveryImport() { global $DB; $DB->connect(); $a_inventory = array('DNSHOSTNAME' => 'pctest', 'ENTITY' => 0, 'IP' => '192.168.20.3'); $pfCommunicationNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery(); $computer = new Computer(); $pfUnmanaged = new PluginFusioninventoryUnmanaged(); $pfIgnoredimportdevice = new PluginFusioninventoryIgnoredimportdevice(); $GLPIlog = new GLPIlogs(); $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = 1; $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = '1'; $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'Computer'; $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = 0; $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = ''; $pfCommunicationNetworkDiscovery->sendCriteria($a_inventory); $a_computers = $computer->find(); $this->assertEquals(0, count($a_computers), 'Computer may not be added'); $a_unknown = $pfUnmanaged->find(); $this->assertEquals(0, count($a_unknown), 'Unmanaged may not be added'); $a_ignored = $pfIgnoredimportdevice->find(); $this->assertEquals(1, count($a_ignored), 'May have only one ignored device import'); }