static function computerInventoryTransformation($array) { global $DB, $PF_ESXINVENTORY, $CFG_GLPI; // Initialize $a_inventory = array('Computer' => array(), 'fusioninventorycomputer' => array(), 'processor' => array(), 'memory' => array(), 'harddrive' => array(), 'drive' => array(), 'graphiccard' => array(), 'networkcard' => array(), 'soundcard' => array(), 'controller' => array(), 'SOFTWARES' => array(), 'virtualmachine' => array(), 'computerdisk' => array(), 'networkport' => array(), 'antivirus' => array(), 'licenseinfo' => array(), 'batteries' => array(), 'monitor' => array(), 'printer' => array(), 'peripheral' => array(), 'storage' => array()); $thisc = new self(); $pfConfig = new PluginFusioninventoryConfig(); $ignorecontrollers = array(); if (isset($array['ACCOUNTINFO'])) { $a_inventory['ACCOUNTINFO'] = $array['ACCOUNTINFO']; } // * HARDWARE $array_tmp = $thisc->addValues($array['HARDWARE'], array('NAME' => 'name', 'OSNAME' => 'operatingsystems_id', 'OSVERSION' => 'operatingsystemversions_id', 'WINPRODID' => 'os_licenseid', 'WINPRODKEY' => 'os_license_number', 'WORKGROUP' => 'domains_id', 'UUID' => 'uuid', 'LASTLOGGEDUSER' => 'users_id', 'operatingsystemservicepacks_id' => 'operatingsystemservicepacks_id', 'manufacturers_id' => 'manufacturers_id', 'computermodels_id' => 'computermodels_id', 'serial' => 'serial', 'computertypes_id' => 'computertypes_id')); if ($array_tmp['operatingsystemservicepacks_id'] == '' && isset($array['HARDWARE']['OSCOMMENTS']) && $array['HARDWARE']['OSCOMMENTS'] != '') { $array_tmp['operatingsystemservicepacks_id'] = $array['HARDWARE']['OSCOMMENTS']; } if (isset($array_tmp['users_id'])) { if ($array_tmp['users_id'] == '') { unset($array_tmp['users_id']); } else { $array_tmp['contact'] = $array_tmp['users_id']; $tmp_users_id = $array_tmp['users_id']; $split_user = explode("@", $tmp_users_id); $query = "SELECT `id`\n FROM `glpi_users`\n WHERE `name` = '" . $split_user[0] . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == 1) { $array_tmp['users_id'] = $DB->result($result, 0, 0); } else { $array_tmp['users_id'] = 0; } } } $array_tmp['is_dynamic'] = 1; $a_inventory['Computer'] = $array_tmp; $array_tmp = $thisc->addValues($array['HARDWARE'], array('OSINSTALLDATE' => 'operatingsystem_installationdate', 'WINOWNER' => 'winowner', 'WINCOMPANY' => 'wincompany')); $array_tmp['last_fusioninventory_update'] = date('Y-m-d H:i:s'); // * Determine "Public contact address" if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { // Try "X-Forwarded-For" HTTP header // Parse "X-Forwarded-For" header (can contain multiple IP addresses, client should be first) $forwarded_for_ip_tmp = explode(', ', $_SERVER['HTTP_X_FORWARDED_FOR']); $forwarded_for_ip_tmp = new IPAddress($forwarded_for_ip_tmp[0]); if ($forwarded_for_ip_tmp->is_valid()) { $array_tmp['remote_addr'] = $forwarded_for_ip_tmp->getTextual(); } } elseif (isset($_SERVER['HTTP_X_REAL_IP'])) { // Then try "X-Real-IP" HTTP header $real_ip_tmp = new IPAddress($_SERVER['HTTP_X_REAL_IP']); if ($real_ip_tmp->is_valid()) { $array_tmp['remote_addr'] = $real_ip_tmp->getTextual(); } } elseif (isset($_SERVER['REMOTE_ADDR'])) { // Fall back on the currently connected IP $array_tmp['remote_addr'] = $_SERVER['REMOTE_ADDR']; } $a_inventory['fusioninventorycomputer'] = $array_tmp; if (isset($array['OPERATINGSYSTEM']['INSTALL_DATE']) && !empty($array['OPERATINGSYSTEM']['INSTALL_DATE'])) { $a_inventory['fusioninventorycomputer']['operatingsystem_installationdate'] = $array['OPERATINGSYSTEM']['INSTALL_DATE']; } if (isset($array['HARDWARE']['DESCRIPTION'])) { $a_inventory['fusioninventorycomputer']['oscomment'] = $array['HARDWARE']['DESCRIPTION']; } if (empty($a_inventory['fusioninventorycomputer']['operatingsystem_installationdate'])) { $a_inventory['fusioninventorycomputer']['operatingsystem_installationdate'] = "NULL"; } // * BIOS if (isset($array['BIOS'])) { if (isset($array['BIOS']['ASSETTAG'])) { $a_inventory['fusioninventorycomputer']['bios_assettag'] = $array['BIOS']['ASSETTAG']; } if (isset($array['BIOS']['SMANUFACTURER']) and !empty($array['BIOS']['SMANUFACTURER'])) { $a_inventory['Computer']['manufacturers_id'] = $array['BIOS']['SMANUFACTURER']; } else { if (isset($array['BIOS']['MMANUFACTURER']) and !empty($array['BIOS']['MMANUFACTURER'])) { $a_inventory['Computer']['manufacturers_id'] = $array['BIOS']['MMANUFACTURER']; } else { if (isset($array['BIOS']['BMANUFACTURER']) and !empty($array['BIOS']['BMANUFACTURER'])) { $a_inventory['Computer']['manufacturers_id'] = $array['BIOS']['BMANUFACTURER']; } else { if (isset($array['BIOS']['MMANUFACTURER']) and !empty($array['BIOS']['MMANUFACTURER'])) { $a_inventory['Computer']['manufacturers_id'] = $array['BIOS']['MMANUFACTURER']; } else { if (isset($array['BIOS']['BMANUFACTURER']) and !empty($array['BIOS']['BMANUFACTURER'])) { $a_inventory['Computer']['manufacturers_id'] = $array['BIOS']['BMANUFACTURER']; } } } } } if (isset($array['BIOS']['MMANUFACTURER']) and !empty($array['BIOS']['MMANUFACTURER'])) { $a_inventory['Computer']['mmanufacturer'] = $array['BIOS']['MMANUFACTURER']; } if (isset($array['BIOS']['BMANUFACTURER']) and !empty($array['BIOS']['BMANUFACTURER'])) { $a_inventory['Computer']['bmanufacturer'] = $array['BIOS']['BMANUFACTURER']; } if (isset($array['BIOS']['SMODEL']) and $array['BIOS']['SMODEL'] != '') { $a_inventory['Computer']['computermodels_id'] = $array['BIOS']['SMODEL']; } else { if (isset($array['BIOS']['MMODEL']) and $array['BIOS']['MMODEL'] != '') { $a_inventory['Computer']['computermodels_id'] = $array['BIOS']['MMODEL']; } } if (isset($array['BIOS']['MMODEL']) and $array['BIOS']['MMODEL'] != '') { $a_inventory['Computer']['mmodel'] = $array['BIOS']['MMODEL']; } if (isset($array['BIOS']['SSN'])) { $a_inventory['Computer']['serial'] = trim($array['BIOS']['SSN']); // HP patch for serial begin with 'S' if (isset($a_inventory['Computer']['manufacturers_id']) and strstr($a_inventory['Computer']['manufacturers_id'], "ewlett") && preg_match("/^[sS]/", $a_inventory['Computer']['serial'])) { $a_inventory['Computer']['serial'] = trim(preg_replace("/^[sS]/", "", $a_inventory['Computer']['serial'])); } } if (isset($array['BIOS']['MSN'])) { $a_inventory['Computer']['mserial'] = trim($array['BIOS']['MSN']); } } // * Type of computer //First the HARDWARE/VMSYSTEM is not Physical : then it's a virtual machine if (isset($array['HARDWARE']['VMSYSTEM']) && $array['HARDWARE']['VMSYSTEM'] != '' && $array['HARDWARE']['VMSYSTEM'] != 'Physical') { $a_inventory['Computer']['computertypes_id'] = $array['HARDWARE']['VMSYSTEM']; // HACK FOR BSDJail, remove serial and UUID (because it's of host, not contener) if ($array['HARDWARE']['VMSYSTEM'] == 'BSDJail') { if (isset($a_inventory['Computer']['serial'])) { $a_inventory['Computer']['serial'] = ''; } $a_inventory['Computer']['uuid'] .= "-" . $a_inventory['Computer']['name']; } } else { //It's not a virtual machine, then check : //1 - HARDWARE/CHASSIS_TYPE //2 - BIOS/TYPE //3 - BIOS/MMODEL //4 - HARDWARE/VMSYSTEM (should not go there) if (isset($array['HARDWARE']['CHASSIS_TYPE']) && !empty($array['HARDWARE']['CHASSIS_TYPE'])) { $a_inventory['Computer']['computertypes_id'] = $array['HARDWARE']['CHASSIS_TYPE']; } else { if (isset($array['BIOS']['TYPE']) && !empty($array['BIOS']['TYPE'])) { $a_inventory['Computer']['computertypes_id'] = $array['BIOS']['TYPE']; } else { if (isset($array['BIOS']['MMODEL']) && !empty($array['BIOS']['MMODEL'])) { $a_inventory['Computer']['computertypes_id'] = $array['BIOS']['MMODEL']; } else { if (isset($array['HARDWARE']['VMSYSTEM']) && !empty($array['HARDWARE']['VMSYSTEM'])) { $a_inventory['Computer']['computertypes_id'] = $array['HARDWARE']['VMSYSTEM']; } } } } } // if (isset($array['BIOS']['SKUNUMBER'])) { // $a_inventory['BIOS']['PARTNUMBER'] = $array['BIOS']['SKUNUMBER']; // } if (isset($array['BIOS']['BDATE'])) { $a_split = explode("/", $array['BIOS']['BDATE']); // 2011-06-29 13:19:48 if (isset($a_split[0]) and isset($a_split[1]) and isset($a_split[2])) { $a_inventory['fusioninventorycomputer']['bios_date'] = $a_split[2] . "-" . $a_split[0] . "-" . $a_split[1]; } } if (isset($array['BIOS']['BVERSION'])) { $a_inventory['fusioninventorycomputer']['bios_version'] = $array['BIOS']['BVERSION']; } if (isset($array['BIOS']['BMANUFACTURER'])) { $a_inventory['fusioninventorycomputer']['bios_manufacturers_id'] = $array['BIOS']['BMANUFACTURER']; } $CFG_GLPI['plugin_fusioninventory_computermanufacturer'][$a_inventory['Computer']['manufacturers_id']] = $a_inventory['Computer']['manufacturers_id']; // * OPERATINGSYSTEM if (isset($array['OPERATINGSYSTEM'])) { $array_tmp = $thisc->addValues($array['OPERATINGSYSTEM'], array('FULL_NAME' => 'operatingsystems_id', 'VERSION' => 'operatingsystemversions_id', 'SERVICE_PACK' => 'operatingsystemservicepacks_id', 'ARCH' => 'plugin_fusioninventory_computerarchs_id')); if (!isset($array['OPERATINGSYSTEM']['VERSION']) && isset($array['OPERATINGSYSTEM']['KERNEL_VERSION'])) { $array_tmp['operatingsystemversions_id'] = $array['OPERATINGSYSTEM']['KERNEL_VERSION']; } foreach ($array_tmp as $key => $value) { if (isset($a_inventory['Computer'][$key]) && $a_inventory['Computer'][$key] != '') { $a_inventory['Computer'][$key] = $value; } } if (isset($array_tmp['plugin_fusioninventory_computerarchs_id']) && $array_tmp['plugin_fusioninventory_computerarchs_id'] != '') { $rulecollection = new PluginFusioninventoryRuleDictionnaryComputerArchCollection(); $res_rule = $rulecollection->processAllRules(array("name" => $array_tmp['plugin_fusioninventory_computerarchs_id'])); if (isset($res_rule['name'])) { $a_inventory['fusioninventorycomputer']['plugin_fusioninventory_computerarchs_id'] = $res_rule['name']; } else { $a_inventory['fusioninventorycomputer']['plugin_fusioninventory_computerarchs_id'] = $array_tmp['plugin_fusioninventory_computerarchs_id']; } } } // otherserial (on tag) if defined in config if ($pfConfig->getValue('otherserial') == 1) { if (isset($array['ACCOUNTINFO'])) { //In very rare case, ACCOUNTINFO section is present twice in the XML file... if (isset($array['ACCOUNTINFO'][0])) { $tmpacc = $array['ACCOUNTINFO'][0]; $array['ACCOUNTINFO'] = $tmpacc; } if (isset($array['ACCOUNTINFO']['KEYNAME']) && $array['ACCOUNTINFO']['KEYNAME'] == 'TAG') { if (isset($array['ACCOUNTINFO']['KEYVALUE']) && $array['ACCOUNTINFO']['KEYVALUE'] != '') { $a_inventory['Computer']['otherserial'] = $array['ACCOUNTINFO']['KEYVALUE']; } } } } // Hack for problems of ESX inventory with same deviceid than real computer inventory if (isset($a_inventory['Computer']['operatingsystems_id']) && strstr($a_inventory['Computer']['operatingsystems_id'], 'VMware ESX')) { $PF_ESXINVENTORY = TRUE; } // * BATTERIES // $a_inventory['batteries'] = array(); // if (isset($array['BATTERIES'])) { // foreach ($array['BATTERIES'] as $a_batteries) { // $a_inventory['soundcard'][] = $thisc->addValues($a_batteries, // array( // 'NAME' => 'name', // 'MANUFACTURER' => 'manufacturers_id', // 'SERIAL' => 'serial', // 'DATE' => 'date', // 'CAPACITY' => 'capacity', // 'CHEMISTRY' => 'plugin_fusioninventory_inventorycomputerchemistries_id', // 'VOLTAGE' => 'voltage')); // } // } // * SOUNDS $a_inventory['soundcard'] = array(); if ($pfConfig->getValue('component_soundcard') == 1) { if (isset($array['SOUNDS'])) { foreach ($array['SOUNDS'] as $a_sounds) { $a_inventory['soundcard'][] = $thisc->addValues($a_sounds, array('NAME' => 'designation', 'MANUFACTURER' => 'manufacturers_id', 'DESCRIPTION' => 'comment')); $ignorecontrollers[$a_sounds['NAME']] = 1; } } } // * VIDEOS $a_inventory['graphiccard'] = array(); if ($pfConfig->getValue('component_graphiccard') == 1) { if (isset($array['VIDEOS'])) { foreach ($array['VIDEOS'] as $a_videos) { if (is_array($a_videos) && isset($a_videos['NAME'])) { $array_tmp = $thisc->addValues($a_videos, array('NAME' => 'designation', 'MEMORY' => 'memory')); $array_tmp['designation'] = trim($array_tmp['designation']); $a_inventory['graphiccard'][] = $array_tmp; if (isset($a_videos['NAME'])) { $ignorecontrollers[$a_videos['NAME']] = 1; } if (isset($a_videos['CHIPSET'])) { $ignorecontrollers[$a_videos['CHIPSET']] = 1; } } } } } // * NETWORK CARD $a_inventory['networkcard'] = array(); if ($pfConfig->getValue('component_networkcard') == 1) { if (isset($array['NETWORKS'])) { foreach ($array['NETWORKS'] as $a_netcards) { if (is_array($a_netcards) && isset($a_netcards['DESCRIPTION'])) { // Search in controller if find NAME = CONTROLLER TYPE $a_found = array(); if (isset($array['CONTROLLERS'])) { foreach ($array['CONTROLLERS'] as $a_controllers) { if (count($a_found) == 0) { if (isset($a_controllers['TYPE']) && ($a_netcards['DESCRIPTION'] == $a_controllers['TYPE'] || strtolower($a_netcards['DESCRIPTION'] . " controller") == strtolower($a_controllers['TYPE'])) && !isset($ignorecontrollers[$a_controllers['NAME']])) { $a_found = $a_controllers; if (isset($a_netcards['MACADDR'])) { $a_found['MACADDR'] = $a_netcards['MACADDR']; } } } } } if (count($a_found) > 0) { $array_tmp = $thisc->addValues($a_found, array('NAME' => 'designation', 'MANUFACTURER' => 'manufacturers_id', 'MACADDR' => 'mac')); if (isset($a_found['PCIID'])) { $a_PCIData = PluginFusioninventoryInventoryExternalDB::getDataFromPCIID($a_found['PCIID']); if (isset($a_PCIData['manufacturer'])) { $array_tmp['manufacturers_id'] = $a_PCIData['manufacturer']; } if (isset($a_PCIData['name'])) { $array_tmp['designation'] = $a_PCIData['name']; } $array_tmp['designation'] = Toolbox::addslashes_deep($array_tmp['designation']); } $array_tmp['mac'] = strtolower($array_tmp['mac']); $a_inventory['networkcard'][] = $array_tmp; if (isset($a_found['NAME'])) { $ignorecontrollers[$a_found['NAME']] = 1; } } } } } } // * NETWORKS $a_inventory['networkport'] = array(); if ($pfConfig->getValue('component_networkcard') == 1) { if (isset($array['NETWORKS'])) { $a_networknames = array(); foreach ($array['NETWORKS'] as $a_networks) { $virtual_import = 1; if ($pfConfig->getValue("component_networkcardvirtual") == 0) { if (isset($a_networks['VIRTUALDEV']) && $a_networks['VIRTUALDEV'] == 1) { $virtual_import = 0; } } if ($virtual_import == 1) { $array_tmp = $thisc->addValues($a_networks, array('DESCRIPTION' => 'name', 'MACADDR' => 'mac', 'TYPE' => 'instantiation_type', 'IPADDRESS' => 'ip', 'VIRTUALDEV' => 'virtualdev', 'IPSUBNET' => 'subnet', 'SSID' => 'ssid', 'IPGATEWAY' => 'gateway', 'IPMASK' => 'netmask', 'IPDHCP' => 'dhcpserver', 'SPEED' => 'speed')); if (isset($array_tmp['name']) && $array_tmp['name'] != '' || isset($array_tmp['mac']) && $array_tmp['mac'] != '') { if (!isset($array_tmp['virtualdev']) || $array_tmp['virtualdev'] != 1) { $array_tmp['virtualdev'] = 0; } $array_tmp['logical_number'] = 1; if ($array_tmp['virtualdev'] == 1) { $array_tmp['logical_number'] = 0; } $array_tmp['mac'] = strtolower($array_tmp['mac']); if (isset($a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']])) { if (isset($array_tmp['ip']) && $array_tmp['ip'] != '') { if (!in_array($array_tmp['ip'], $a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']]['ipaddress'])) { $a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']]['ipaddress'][] = $array_tmp['ip']; } } if (isset($a_networks['IPADDRESS6']) && $a_networks['IPADDRESS6'] != '') { if (!in_array($a_networks['IPADDRESS6'], $a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']]['ipaddress'])) { $a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']]['ipaddress'][] = $a_networks['IPADDRESS6']; } } } else { if (isset($array_tmp['ip']) && $array_tmp['ip'] != '') { $array_tmp['ipaddress'] = array($array_tmp['ip']); unset($array_tmp['ip']); } else { $array_tmp['ipaddress'] = array(); } if (isset($a_networks['IPADDRESS6']) && $a_networks['IPADDRESS6'] != '') { $array_tmp['ipaddress'][] = $a_networks['IPADDRESS6']; } if (isset($array_tmp["instantiation_type"]) and $array_tmp["instantiation_type"] == 'Ethernet') { $array_tmp["instantiation_type"] = 'NetworkPortEthernet'; } else { if (isset($array_tmp["instantiation_type"]) and ($array_tmp["instantiation_type"] == 'wifi' or $array_tmp["instantiation_type"] == 'IEEE')) { $array_tmp["instantiation_type"] = 'NetworkPortWifi'; } else { if ($array_tmp['mac'] != '') { $array_tmp["instantiation_type"] = 'NetworkPortEthernet'; } else { $array_tmp["instantiation_type"] = 'NetworkPortLocal'; } } } if (isset($array_tmp['ip'])) { unset($array_tmp['ip']); } if (isset($array_tmp['speed']) && is_numeric($array_tmp['speed'])) { // Old agent version have speed in b/s instead Mb/s if ($array_tmp['speed'] > 100000) { $array_tmp['speed'] = $array_tmp['speed'] / 1000000; } } else { $array_tmp['speed'] = 0; } $a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']] = $array_tmp; } } } } $a_inventory['networkport'] = $a_networknames; } } // * CONTROLLERS $a_inventory['controller'] = array(); if ($pfConfig->getValue('component_control') == 1) { if (isset($array['CONTROLLERS'])) { foreach ($array['CONTROLLERS'] as $a_controllers) { if (isset($a_controllers["NAME"]) and !isset($ignorecontrollers[$a_controllers["NAME"]])) { $array_tmp = $thisc->addValues($a_controllers, array('NAME' => 'designation', 'MANUFACTURER' => 'manufacturers_id', 'type' => 'interfacetypes_id')); if (isset($a_controllers['PCIID'])) { $a_PCIData = PluginFusioninventoryInventoryExternalDB::getDataFromPCIID($a_controllers['PCIID']); if (isset($a_PCIData['manufacturer'])) { $array_tmp['manufacturers_id'] = $a_PCIData['manufacturer']; } if (isset($a_PCIData['name'])) { $array_tmp['designation'] = $a_PCIData['name']; } $array_tmp['designation'] = Toolbox::addslashes_deep($array_tmp['designation']); } $a_inventory['controller'][] = $array_tmp; } } } } // * CPUS $a_inventory['processor'] = array(); if ($pfConfig->getValue('component_processor') == 1) { if (isset($array['CPUS'])) { foreach ($array['CPUS'] as $a_cpus) { if (is_array($a_cpus) && (isset($a_cpus['NAME']) || isset($a_cpus['TYPE']))) { $array_tmp = $thisc->addValues($a_cpus, array('SPEED' => 'frequency', 'MANUFACTURER' => 'manufacturers_id', 'SERIAL' => 'serial', 'NAME' => 'designation', 'CORE' => 'nbcores', 'THREAD' => 'nbthreads')); if ($array_tmp['designation'] == '' && isset($a_cpus['TYPE'])) { $array_tmp['designation'] = $a_cpus['TYPE']; } $array_tmp['frequence'] = $array_tmp['frequency']; $array_tmp['frequency_default'] = $array_tmp['frequency']; $a_inventory['processor'][] = $array_tmp; } } } } // * DRIVES $a_inventory['computerdisk'] = array(); if (isset($array['DRIVES'])) { foreach ($array['DRIVES'] as $a_drives) { if ($pfConfig->getValue("component_drive") == '0' or $pfConfig->getValue("component_networkdrive") == '0' and (isset($a_drives['TYPE']) and $a_drives['TYPE'] == 'Network Drive' or isset($a_drives['FILESYSTEM']) and $a_drives['FILESYSTEM'] == 'nfs') or isset($a_drives['TYPE']) and ($a_drives['TYPE'] == "Removable Disk" or $a_drives['TYPE'] == "Compact Disc")) { } else { if ($pfConfig->getValue('import_volume') == 1) { $array_tmp = $thisc->addValues($a_drives, array('VOLUMN' => 'device', 'FILESYSTEM' => 'filesystems_id', 'TOTAL' => 'totalsize', 'FREE' => 'freesize')); if (isset($a_drives['LABEL']) and !empty($a_drives['LABEL'])) { $array_tmp['name'] = $a_drives['LABEL']; } else { if ((!isset($a_drives['VOLUMN']) or empty($a_drives['VOLUMN'])) and isset($a_drives['LETTER'])) { $array_tmp['name'] = $a_drives['LETTER']; } else { if (isset($a_drives['TYPE'])) { $array_tmp['name'] = $a_drives['TYPE']; } else { if (isset($a_drives['VOLUMN'])) { $array_tmp['name'] = $a_drives['VOLUMN']; } } } } if (isset($a_drives['MOUNTPOINT'])) { $array_tmp['mountpoint'] = $a_drives['MOUNTPOINT']; } else { if (isset($a_drives['LETTER'])) { $array_tmp['mountpoint'] = $a_drives['LETTER']; } else { if (isset($a_drives['TYPE'])) { $array_tmp['mountpoint'] = $a_drives['TYPE']; } } } $a_inventory['computerdisk'][] = $array_tmp; } } } } // * MEMORIES $a_inventory['memory'] = array(); if ($pfConfig->getValue('component_memory') == 1) { if (isset($array['MEMORIES'])) { foreach ($array['MEMORIES'] as $a_memories) { if (!isset($a_memories["CAPACITY"]) or isset($a_memories["CAPACITY"]) and !preg_match("/^[0-9]+\$/i", $a_memories["CAPACITY"])) { // Nothing } else { $array_tmp = $thisc->addValues($a_memories, array('CAPACITY' => 'size', 'SPEED' => 'frequence', 'TYPE' => 'devicememorytypes_id', 'SERIALNUMBER' => 'serial', 'NUMSLOTS' => 'busID')); if ($array_tmp['size'] > 0) { $array_tmp['designation'] = ""; if (isset($a_memories["TYPE"]) && $a_memories["TYPE"] != "Empty Slot" && $a_memories["TYPE"] != "Unknown") { $array_tmp["designation"] = $a_memories["TYPE"]; } if (isset($a_memories["DESCRIPTION"])) { if (!empty($array_tmp["designation"])) { $array_tmp["designation"] .= " - "; } $array_tmp["designation"] .= $a_memories["DESCRIPTION"]; } $a_inventory['memory'][] = $array_tmp; } } } } } // * MONITORS $a_inventory['monitor'] = array(); if (isset($array['MONITORS'])) { $a_serialMonitor = array(); foreach ($array['MONITORS'] as $a_monitors) { $array_tmp = $thisc->addValues($a_monitors, array('CAPTION' => 'name', 'MANUFACTURER' => 'manufacturers_id', 'SERIAL' => 'serial', 'DESCRIPTION' => 'comment')); if (!isset($array_tmp['name'])) { $array_tmp['name'] = ''; } if ($array_tmp['name'] == '' && isset($array_tmp['comment'])) { $array_tmp['name'] = $array_tmp['comment']; } if (isset($array_tmp['comment'])) { unset($array_tmp['comment']); } if (!isset($array_tmp['serial'])) { $array_tmp['serial'] = ''; } if (!isset($array_tmp['manufacturers_id'])) { $array_tmp['manufacturers_id'] = ''; } if (!isset($a_serialMonitor[$array_tmp['serial']])) { $a_inventory['monitor'][] = $array_tmp; $a_serialMonitor[$array_tmp['serial']] = 1; } } } // * PRINTERS $a_inventory['printer'] = array(); if (isset($array['PRINTERS'])) { $rulecollection = new RuleDictionnaryPrinterCollection(); foreach ($array['PRINTERS'] as $a_printers) { $array_tmp = $thisc->addValues($a_printers, array('NAME' => 'name', 'PORT' => 'port', 'SERIAL' => 'serial')); if (strstr($array_tmp['port'], "USB")) { $array_tmp['have_usb'] = 1; } else { $array_tmp['have_usb'] = 0; } unset($array_tmp['port']); $res_rule = $rulecollection->processAllRules(array("name" => $array_tmp['name'])); if (isset($res_rule['_ignore_ocs_import']) && $res_rule['_ignore_ocs_import'] == "1") { // Ignrore import printer } else { if (isset($res_rule['_ignore_import']) && $res_rule['_ignore_import'] == "1") { // Ignrore import printer } else { if (isset($res_rule['name'])) { $array_tmp['name'] = $res_rule['name']; } if (isset($res_rule['manufacturer'])) { $array_tmp['manufacturers_id'] = $res_rule['manufacturer']; } $a_inventory['printer'][] = $array_tmp; } } } } // * PERIPHERAL $a_inventory['peripheral'] = array(); $a_peripheral_name = array(); $per = 0; if (isset($array['USBDEVICES'])) { foreach ($array['USBDEVICES'] as $a_peripherals) { $array_tmp = $thisc->addValues($a_peripherals, array('NAME' => 'name', 'MANUFACTURER' => 'manufacturers_id', 'SERIAL' => 'serial', 'PRODUCTNAME' => 'productname')); if (isset($a_peripherals['VENDORID']) and $a_peripherals['VENDORID'] != '' and isset($a_peripherals['PRODUCTID'])) { $dataArray = PluginFusioninventoryInventoryExternalDB::getDataFromUSBID($a_peripherals['VENDORID'], $a_peripherals['PRODUCTID']); $dataArray[0] = preg_replace('/&(?!\\w+;)/', '&', $dataArray[0]); if (!empty($dataArray[0]) and empty($array_tmp['manufacturers_id'])) { $array_tmp['manufacturers_id'] = $dataArray[0]; } $dataArray[1] = preg_replace('/&(?!\\w+;)/', '&', $dataArray[1]); if (!empty($dataArray[1]) and empty($a_peripherals['productname'])) { $a_peripherals['productname'] = $dataArray[1]; } } if ($array_tmp['productname'] != '') { $array_tmp['name'] = $array_tmp['productname']; } unset($array_tmp['productname']); $a_inventory['peripheral'][] = $array_tmp; $a_peripheral_name[$array_tmp['name']] = $per; $per++; } } if (isset($array['INPUTS'])) { $a_pointingtypes = array(3 => 'Mouse', 4 => 'Trackball', 5 => 'Track Point', 6 => 'Glide Point', 7 => 'Touch Pad', 8 => 'Touch Screen', 9 => 'Mouse - Optical Sensor'); foreach ($array['INPUTS'] as $a_peripherals) { $array_tmp = $thisc->addValues($a_peripherals, array('NAME' => 'name', 'MANUFACTURER' => 'manufacturers_id')); $array_tmp['serial'] = ''; $array_tmp['peripheraltypes_id'] = ''; if (isset($a_peripherals['POINTINGTYPE']) && isset($a_pointingtypes[$a_peripherals['POINTINGTYPE']])) { $array_tmp['peripheraltypes_id'] = $a_pointingtypes[$a_peripherals['POINTINGTYPE']]; } if (isset($a_peripherals['LAYOUT'])) { $array_tmp['peripheraltypes_id'] = 'keyboard'; } if (isset($a_peripheral_name[$array_tmp['name']])) { $a_inventory['peripheral'][$a_peripheral_name[$array_tmp['name']]]['peripheraltypes_id'] = $array_tmp['peripheraltypes_id']; } else { $a_inventory['peripheral'][] = $array_tmp; } } } // * SLOTS // * SOFTWARES $a_inventory['SOFTWARES'] = array(); if ($pfConfig->getValue('import_software') == 1) { if (isset($array['SOFTWARES'])) { $a_inventory['SOFTWARES'] = $array['SOFTWARES']; } } // * STORAGES/COMPUTERDISK $a_inventory['harddrive'] = array(); if (isset($array['STORAGES'])) { foreach ($array['STORAGES'] as $a_storage) { $type_tmp = PluginFusioninventoryFormatconvert::getTypeDrive($a_storage); if ($type_tmp == "Drive") { // it's cd-rom / dvd // if ($pfConfig->getValue(, // "component_drive") =! 0) { if ($pfConfig->getValue('component_drive') == 1) { $array_tmp = $thisc->addValues($a_storage, array('SERIALNUMBER' => 'serial', 'NAME' => 'designation', 'TYPE' => 'interfacetypes_id', 'MANUFACTURER' => 'manufacturers_id')); if ($array_tmp['designation'] == '') { if (isset($a_storage['DESCRIPTION'])) { $array_tmp['designation'] = $a_storage['DESCRIPTION']; } } $a_inventory['drive'][] = $array_tmp; } } else { // it's harddisk // if ($pfConfig->getValue(, // "component_harddrive") != 0) { if (is_array($a_storage)) { if ($pfConfig->getValue('component_harddrive') == 1) { $array_tmp = $thisc->addValues($a_storage, array('DISKSIZE' => 'capacity', 'INTERFACE' => 'interfacetypes_id', 'MANUFACTURER' => 'manufacturers_id', 'MODEL' => 'designation', 'SERIALNUMBER' => 'serial')); if ($array_tmp['designation'] == '') { if (isset($a_storage['NAME'])) { $array_tmp['designation'] = $a_storage['NAME']; } else { if (isset($a_storage['DESIGNATION'])) { $array_tmp['designation'] = $a_storage['DESIGNATION']; } } } $a_inventory['harddrive'][] = $array_tmp; } } } } } // * USERS $cnt = 0; if (isset($array['USERS'])) { if (count($array['USERS']) > 0) { $user_temp = ''; if (isset($a_inventory['Computer']['contact'])) { $user_temp = $a_inventory['Computer']['contact']; } $a_inventory['Computer']['contact'] = ''; } foreach ($array['USERS'] as $a_users) { $array_tmp = $thisc->addValues($a_users, array('LOGIN' => 'login', 'DOMAIN' => 'domain')); $user = ''; if (isset($array_tmp['login'])) { $user = $array_tmp['login']; if (isset($array_tmp['domain']) && !empty($array_tmp['domain'])) { $user .= "@" . $array_tmp['domain']; } } if ($cnt == 0) { if (isset($array_tmp['login'])) { $query = "SELECT `id`\n FROM `glpi_users`\n WHERE `name` = '" . $array_tmp['login'] . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == 1) { $a_inventory['Computer']['users_id'] = $DB->result($result, 0, 0); } } } if ($user != '') { if (isset($a_inventory['Computer']['contact'])) { if ($a_inventory['Computer']['contact'] == '') { $a_inventory['Computer']['contact'] = $user; } else { $a_inventory['Computer']['contact'] .= "/" . $user; } } else { $a_inventory['Computer']['contact'] = $user; } } $cnt++; } if (empty($a_inventory['Computer']['contact'])) { $a_inventory['Computer']['contact'] = $user_temp; } } // * VIRTUALMACHINES $a_inventory['virtualmachine'] = array(); if ($pfConfig->getValue('import_vm') == 1) { if (isset($array['VIRTUALMACHINES'])) { foreach ($array['VIRTUALMACHINES'] as $a_virtualmachines) { $array_tmp = $thisc->addValues($a_virtualmachines, array('NAME' => 'name', 'VCPU' => 'vcpu', 'MEMORY' => 'ram', 'VMTYPE' => 'virtualmachinetypes_id', 'SUBSYSTEM' => 'virtualmachinesystems_id', 'STATUS' => 'virtualmachinestates_id', 'UUID' => 'uuid')); $array_tmp['is_dynamic'] = 1; // Hack for BSD jails if ($array_tmp['virtualmachinetypes_id'] == 'jail') { $array_tmp['uuid'] = $a_inventory['Computer']['uuid'] . "-" . $array_tmp['name']; } $a_inventory['virtualmachine'][] = $array_tmp; } } } if ($pfConfig->getValue('create_vm') == 1) { if (isset($array['VIRTUALMACHINES'])) { foreach ($array['VIRTUALMACHINES'] as $a_virtualmachines) { if (strstr($a_virtualmachines['MEMORY'], 'MB')) { $a_virtualmachines['MEMORY'] = str_replace('MB', '', $a_virtualmachines['MEMORY']); } else { if (strstr($a_virtualmachines['MEMORY'], 'KB')) { $a_virtualmachines['MEMORY'] = str_replace('KB', '', $a_virtualmachines['MEMORY']); $a_virtualmachines['MEMORY'] = $a_virtualmachines['MEMORY'] / 1000; } else { if (strstr($a_virtualmachines['MEMORY'], 'GB')) { $a_virtualmachines['MEMORY'] = str_replace('GB', '', $a_virtualmachines['MEMORY']); $a_virtualmachines['MEMORY'] = $a_virtualmachines['MEMORY'] * 1000; } else { if (strstr($a_virtualmachines['MEMORY'], 'B')) { $a_virtualmachines['MEMORY'] = str_replace('B', '', $a_virtualmachines['MEMORY']); $a_virtualmachines['MEMORY'] = $a_virtualmachines['MEMORY'] / 1000000; } } } } $array_tmp = $thisc->addValues($a_virtualmachines, array('NAME' => 'name', 'VCPU' => 'vcpu', 'MEMORY' => 'ram', 'VMTYPE' => 'computertypes_id', 'UUID' => 'uuid', 'OPERATINGSYSTEM' => 'operatingsystems_id', 'CUSTOMFIELDS' => 'comment')); $array_tmp['is_dynamic'] = 1; if (isset($array_tmp['comment']) && is_array($array_tmp['comment'])) { $a_com_temp = $array_tmp['comment']; $array_tmp['comment'] = ''; foreach ($a_com_temp as $data) { $array_tmp['comment'] .= $data['NAME'] . ' : ' . $data['VALUE'] . '\\n'; } } $array_tmp['networkport'] = array(); if (isset($a_virtualmachines['NETWORKS']) && is_array($a_virtualmachines['NETWORKS'])) { foreach ($a_virtualmachines['NETWORKS'] as $data) { $array_tmp_np = $thisc->addValues($data, array('DESCRIPTION' => 'name', 'MACADDR' => 'mac', 'IPADDRESS' => 'ip')); $array_tmp_np['instantiation_type'] = 'NetworkPortEthernet'; $array_tmp_np['mac'] = strtolower($array_tmp_np['mac']); if (isset($array_tmp['networkport'][$array_tmp_np['name'] . '-' . $array_tmp_np['mac']])) { if (isset($array_tmp_np['ip'])) { $array_tmp['networkport'][$array_tmp_np['name'] . '-' . $array_tmp_np['mac']]['ipaddress'][] = $array_tmp_np['ip']; } } else { if (isset($array_tmp_np['ip']) && $array_tmp_np['ip'] != '') { $array_tmp_np['ipaddress'] = array($array_tmp_np['ip']); unset($array_tmp_np['ip']); } else { $array_tmp_np['ipaddress'] = array(); } $array_tmp['networkport'][$array_tmp_np['name'] . '-' . $array_tmp_np['mac']] = $array_tmp_np; } } } $a_inventory['virtualmachine_creation'][] = $array_tmp; } } } // * ANTIVIRUS $a_inventory['antivirus'] = array(); if (isset($array['ANTIVIRUS'])) { foreach ($array['ANTIVIRUS'] as $a_antiviruses) { $array_tmp = $thisc->addValues($a_antiviruses, array('NAME' => 'name', 'COMPANY' => 'manufacturers_id', 'VERSION' => 'version', 'ENABLED' => 'is_active', 'UPTODATE' => 'uptodate')); $a_inventory['antivirus'][] = $array_tmp; } } // * STORAGE/VOLUMES $a_inventory['storage'] = array(); /* begin code, may works at 90% if (isset($array['PHYSICAL_VOLUMES'])) { foreach ($array['PHYSICAL_VOLUMES'] as $a_physicalvolumes) { $array_tmp = $thisc->addValues($a_physicalvolumes, array( 'DEVICE' => 'name', 'PV_UUID' => 'uuid', 'VG_UUID' => 'uuid_link', 'SIZE' => 'totalsize', 'FREE' => 'freesize')); $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'partition'; $a_inventory['storage'][] = $array_tmp; } } if (isset($array['STORAGES'])) { foreach ($array['STORAGES'] as $a_storage) { $type_tmp = PluginFusioninventoryFormatconvert::getTypeDrive($a_storage); if ($type_tmp != "Drive") { if (isset($a_storage['NAME']) AND $a_storage['NAME'] != '') { $detectsize = 0; $array_tmp = array(); foreach ($a_inventory['storage'] as $a_physicalvol) { if (preg_match("/^\/dev\/".$a_storage['NAME']."/", $a_physicalvol['name'])) { $array_tmp['name'] = $a_storage['NAME']; if (isset($a_storage['SERIALNUMBER'])) { $array_tmp['uuid'] = $a_storage['SERIALNUMBER']; } else { $array_tmp['uuid'] = $a_storage['NAME']; } $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'hard disk'; if (!isset($array_tmp['uuid_link'])) { $array_tmp['uuid_link'] = array(); } $array_tmp['uuid_link'][] = $a_physicalvol['uuid']; $detectsize += $a_physicalvol['totalsize']; } } if (isset($a_storage['DISKSIZE']) && $a_storage['DISKSIZE'] != '') { $array_tmp['totalsize'] = $a_storage['DISKSIZE']; $array_tmp['size_dynamic'] = 0; } else { $array_tmp['totalsize'] = $detectsize; $array_tmp['size_dynamic'] = 1; } $a_inventory['storage'][] = $array_tmp; } } } } if (isset($array['VOLUME_GROUPS'])) { foreach ($array['VOLUME_GROUPS'] as $a_volumegroups) { $array_tmp = $thisc->addValues($a_volumegroups, array( 'VG_NAME' => 'name', 'VG_UUID' => 'uuid', 'SIZE' => 'totalsize', 'FREE' => 'freesize')); $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'volume groups'; $a_inventory['storage'][] = $array_tmp; } } if (isset($array['LOGICAL_VOLUMES'])) { foreach ($array['LOGICAL_VOLUMES'] as $a_logicalvolumes) { $array_tmp = $thisc->addValues($a_logicalvolumes, array( 'LV_NAME' => 'name', 'LV_UUID' => 'uuid', 'VG_UUID' => 'uuid_link', 'SIZE' => 'totalsize')); $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'logical volumes'; $a_inventory['storage'][] = $array_tmp; } } if (isset($array['DRIVES'])) { foreach ($array['DRIVES'] as $a_drives) { if ((((isset($a_drives['TYPE']) AND $a_drives['TYPE'] == 'Network Drive') OR isset($a_drives['FILESYSTEM']) AND $a_drives['FILESYSTEM'] == 'nfs')) OR ((isset($a_drives['TYPE'])) AND (($a_drives['TYPE'] == "Removable Disk") OR ($a_drives['TYPE'] == "Compact Disc")))) { } else if (isset($a_drives['VOLUMN']) && strstr($a_drives['VOLUMN'], "/dev/mapper")){ // LVM $a_split = explode("-", $a_drives['VOLUMN']); $volumn = end($a_split); $detectsize = 0; $array_tmp = array(); foreach ($a_inventory['storage'] as $num=>$a_physicalvol) { if ($a_physicalvol['plugin_fusioninventory_inventorycomputerstoragetypes_id'] == 'logical volumes') { if ($volumn == $a_physicalvol['name']) { $array_tmp['name'] = $a_drives['TYPE']; if (isset($a_drives['SERIAL'])) { $array_tmp['uuid'] = $a_drives['SERIAL']; } else { $array_tmp['uuid'] = $a_drives['TYPE']; } $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'mount'; if (!isset($array_tmp['uuid_link'])) { $array_tmp['uuid_link'] = array(); } $array_tmp['uuid_link'][] = $a_physicalvol['uuid']; $detectsize += $a_physicalvol['totalsize']; } } } if (isset($array_tmp['name'])) { $array_tmp['totalsize'] = $a_drives['TOTAL']; $a_inventory['storage'][] = $array_tmp; } } else if (isset($a_drives['VOLUMN']) && strstr($a_drives['VOLUMN'], "/dev/")){ $detectsize = 0; $array_tmp = array(); foreach ($a_inventory['storage'] as $num=>$a_physicalvol) { $volumn = $a_drives['VOLUMN']; $volumn = substr_replace($volumn , "", -1); $volumn = str_replace("/dev/", "", $volumn); if ($volumn == $a_physicalvol['name']) { $array_tmp['name'] = $a_drives['VOLUMN']; if (isset($a_drives['SERIAL'])) { $array_tmp['uuid'] = $a_drives['SERIAL']; } else { $array_tmp['uuid'] = $a_drives['TYPE']; } $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'partition'; if (!isset($array_tmp['uuid_link'])) { $array_tmp['uuid_link'] = array(); } $array_tmp['uuid_link'][] = $a_physicalvol['uuid']; $detectsize += $a_physicalvol['totalsize']; if ($a_physicalvol['size_dynamic'] == 1) { $a_inventory['storage'][$num]['totalsize'] += $a_drives['TOTAL']; } } } if (isset($array_tmp['name'])) { $array_tmp['totalsize'] = $a_drives['TOTAL']; $a_inventory['storage'][] = $array_tmp; $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'mount'; $array_tmp['name'] = $a_drives['TYPE']; $array_tmp['uuid_link'] = array(); $array_tmp['uuid_link'][] = $array_tmp['uuid']; $array_tmp['uuid'] = $array_tmp['uuid']."-mount"; $a_inventory['storage'][] = $array_tmp; } } } } */ // * LICENSEINFOS $a_inventory['licenseinfo'] = array(); if (isset($array['LICENSEINFOS'])) { foreach ($array['LICENSEINFOS'] as $a_licenseinfo) { $array_tmp = $thisc->addValues($a_licenseinfo, array('NAME' => 'name', 'FULLNAME' => 'fullname', 'KEY' => 'serial')); $a_inventory['licenseinfo'][] = $array_tmp; } } return $a_inventory; }