diff options
Diffstat (limited to 'modules-available/statistics/inc/hardwareparser.inc.php')
-rw-r--r-- | modules-available/statistics/inc/hardwareparser.inc.php | 83 |
1 files changed, 56 insertions, 27 deletions
diff --git a/modules-available/statistics/inc/hardwareparser.inc.php b/modules-available/statistics/inc/hardwareparser.inc.php index d356e226..15534749 100644 --- a/modules-available/statistics/inc/hardwareparser.inc.php +++ b/modules-available/statistics/inc/hardwareparser.inc.php @@ -308,29 +308,29 @@ class HardwareParser foreach ($out as $entry) { if (!isset($pci[$entry['class']])) { $class = 'c.' . $entry['class']; - $res = Page_Statistics::getPciId('CLASS', $class); - if ($res === false || $res['dateline'] < $NOW) { + $res = PciId::getPciId('CLASS', $class); + if ($res === false) { $pci[$entry['class']]['lookupClass'] = 'do-lookup'; $pci[$entry['class']]['class'] = $class; } else { - $pci[$entry['class']]['class'] = $res['value']; + $pci[$entry['class']]['class'] = $res; } } $new = array( 'ven' => $entry['ven'], 'dev' => $entry['ven'] . ':' . $entry['dev'], ); - $res = Page_Statistics::getPciId('VENDOR', $new['ven']); - if ($res === false || $res['dateline'] < $NOW) { + $res = PciId::getPciId('VENDOR', $new['ven']); + if ($res === false) { $new['lookupVen'] = 'do-lookup'; } else { - $new['ven'] = $res['value']; + $new['ven'] = $res; } - $res = Page_Statistics::getPciId('DEVICE', $new['dev']); - if ($res === false || $res['dateline'] < $NOW) { + $res = PciId::getPciId('DEVICE', $new['dev']); + if ($res === false) { $new['lookupDev'] = 'do-lookup'; } else { - $new['dev'] = $res['value'] . ' (' . $new['dev'] . ')'; + $new['dev'] = $res . ' (' . $new['dev'] . ')'; } $pci[$entry['class']]['entries'][] = $new; } @@ -444,8 +444,8 @@ class HardwareParser return (int)($out[1] * self::SI_LOOKUP[strtoupper($out[2])]); } // Count, size (unitless) - if (is_numeric($val) && preg_match('/^[0-9]+$/', $val) - && preg_match('/used|occupied|count|number|size/', $key)) { + if (is_numeric($val) && preg_match('/^-?[0-9]+$/', $val) + && preg_match('/used|occupied|count|number|size|temperature/', $key)) { return (int)$val; } // Date @@ -538,7 +538,7 @@ class HardwareParser { $ret = []; foreach ($data as $key => $vals) { - $val = trim($vals['values'][0]); + $val = trim($vals['values'][0] ?? 'NULL'); if ($val === '[Empty]' || $val === 'NULL') continue; $val = preg_replace('/[^a-z0-9]/', '', strtolower($val)); @@ -567,7 +567,7 @@ class HardwareParser */ private static function markDisconnected(string $uuid, string $dbType, array $excludedHwIds) { - error_log("Marking disconnected for $dbType from " . implode(', ', $excludedHwIds)); + error_log("Marking disconnected for $dbType except " . implode(', ', $excludedHwIds)); if (empty($excludedHwIds)) { Database::exec("UPDATE machine_x_hw mxh, statistic_hw h SET mxh.disconnecttime = UNIX_TIMESTAMP() @@ -630,10 +630,12 @@ class HardwareParser $globalMainboardExtra['Memory Slot Count'] += $mem['Number Of Devices']; } if (isset($mem['Maximum Capacity'])) { - $globalMainboardExtra['Memory Maximum Capacity'] += self::convertSize($mem['Maximum Capacity'], 'M', false); + $globalMainboardExtra['Memory Maximum Capacity'] + += self::convertSize($mem['Maximum Capacity'], 'M', false); } } - $globalMainboardExtra['Memory Maximum Capacity'] = self::convertSize($globalMainboardExtra['Memory Maximum Capacity'] . ' MB'); + $globalMainboardExtra['Memory Maximum Capacity'] + = self::convertSize($globalMainboardExtra['Memory Maximum Capacity'] . ' MB', 'G'); // BIOS section - need to cross-match this with mainboard or system model, as it doesn't have a meaningful // identifier on its own $bios = self::prepareDmiProperties(self::getDmiHandles($data, 0)[0]); @@ -651,8 +653,14 @@ class HardwareParser } } // Using the general helper function - $ramModCount = self::updateHwTypeFromDmi($uuid, $data, 17, HardwareInfo::RAM_MODULE, function (array $flat): bool { - return self::convertSize(($flat['Size'] ?? 0), '', false) > 65 * 1024 * 1024; + $capa = 0; + $ramModCount = self::updateHwTypeFromDmi($uuid, $data, 17, HardwareInfo::RAM_MODULE, function (array $flat) use (&$capa): bool { + $size = self::convertSize(($flat['Size'] ?? 0), '', false); + if ($size > 65 * 1024 * 1024) { + $capa += $size; + return true; + } + return false; }, ['Locator'], ['Data Width', @@ -669,6 +677,7 @@ class HardwareParser ); // Fake RAM slots used/total into this $localMainboardExtra['Memory Slot Occupied'] = $ramModCount; + $localMainboardExtra['Memory Installed Capacity'] = self::convertSize($capa, 'G', true); self::updateHwTypeFromDmi($uuid, $data, 2, HardwareInfo::MAINBOARD, ['Manufacturer', 'Product Name'], [], ['Manufacturer', 'Product Name', 'Type', 'Version'], @@ -714,15 +723,18 @@ class HardwareParser // ---- lspci ------------------------------------ $pciHwIds = []; foreach (($data['lspci'] ?? []) as $dev) { - $hwid = self::writeGlobalHardwareData(HardwareInfo::PCI_DEVICE, - self::propsFromArray($dev, 'vendor', 'device', 'rev', 'class')); + $props = self::propsFromArray($dev, 'vendor', 'device', 'rev', 'class'); + if (!isset($props['vendor']) || !isset($props['device'])) + continue; + $hwid = self::writeGlobalHardwareData(HardwareInfo::PCI_DEVICE, $props); $mappingId = self::writeLocalHardwareData($uuid, $hwid, $dev['slot'] ?? 'unknown', - self::propsFromArray($dev, 'slot', 'subsystem', 'subsystem_vendor')); + self::propsFromArray($dev, 'slot', 'subsystem', 'subsystem_vendor', 'iommu_group')); $pciHwIds[] = $mappingId; } self::markDisconnected($uuid, HardwareInfo::PCI_DEVICE, $pciHwIds); // ---- Disks ------------------------------------0Y3R3K $hddHwIds = []; + $id44 = $id45 = 0; foreach (($data['drives'] ?? []) as $dev) { if (empty($dev['readlink'])) continue; @@ -739,11 +751,12 @@ class HardwareParser if (!isset($smart['rotation_rate']) && isset($lsblk['rota']) && !$lsblk['rota']) { $smart['rotation_rate'] = 0; } + $size = $lsblk['size'] ?? $smart['user_capacity']['bytes'] ?? 'unknown'; $hwid = self::writeGlobalHardwareData(HardwareInfo::HDD, [ // Try to use the model name as the unique identifier 'model' => $smart['model_name'] ?? $lsblk['model'] ?? 'unknown', // Append device size as some kind of fallback, in case model is unknown - 'size' => $lsblk['size'] ?? $smart['user_capacity']['bytes'] ?? 'unknown', + 'size' => $size, 'physical_block_size' => $smart['physical_block_size'] ?? $lsblk['phy-sec'] ?? 0, 'logical_block_size' => $smart['logical_block_size'] ?? $lsblk['log-sec'] ?? 0, ] + self::propsFromArray($smart, @@ -781,6 +794,7 @@ class HardwareParser }, ARRAY_FILTER_USE_BOTH); } // Partitions - find special ones + $used = 0; if (isset($dev['sfdisk']['partitiontable'])) { $table['partition_table'] = $dev['sfdisk']['partitiontable']['label'] ?? 'none'; switch ($dev['sfdisk']['partitiontable']['unit'] ?? 'sectors') { @@ -795,6 +809,13 @@ class HardwareParser } $i = 0; foreach (($dev['sfdisk']['partitiontable']['partitions'] ?? []) as $part) { + if (!isset($part['size'])) + continue; + $type = hexdec($part['type'] ?? '0'); + if ($type === 0x0 || $type === 0x5 || $type === 0xf || $type === 0x15 || $type === 0x1f + || $type === 0x85 || $type === 0xc5 || $type == 0xcf) + continue; // Extended partition, ignore + $used += $part['size'] * $fac; $id = 'part_' . $i . '_'; foreach (['start', 'size', 'type', 'uuid', 'name'] as $item) { if (!isset($part[$item])) @@ -811,19 +832,23 @@ class HardwareParser if ($type == '44' || strtolower($type) === '87f86132-ff94-4987-b250-444444444444' || $name === 'OpenSLX-ID44') { $table[$id . 'slxtype'] = '44'; + $id44 += $part['size'] * $fac; } elseif ($type == '45' || strtolower($type) === '87f86132-ff94-4987-b250-454545454545' || $name === 'OpenSLX-ID45') { $table[$id . 'slxtype'] = '45'; + $id45 += $part['size'] * $fac; } // ++$i; } } + $table['unused'] = $size - $used; + $table += self::propsFromArray($smart + ($lsblk ?? []), + 'serial_number', 'firmware_version', + 'interface_speed//current//string', + 'smart_status//passed', 'temperature//current', 'temperature//min', 'temperature//max'); $mappingId = self::writeLocalHardwareData($uuid, $hwid, $dev['readlink'], - self::propsFromArray($smart + ($lsblk ?? []), - 'serial_number', 'firmware_version', - 'interface_speed//current//string', - 'smart_status//passed', 'temperature//current', 'temperature//min', 'temperature//max') + $table); + $table); // Delete old partition and smart attribute entries Database::exec("DELETE FROM machine_x_hw_prop WHERE machinehwid = :id AND prop NOT IN (:keep) AND prop NOT LIKE '@%'", [ @@ -836,8 +861,12 @@ class HardwareParser self::markDisconnected($uuid, HardwareInfo::HDD, $hddHwIds); // // Mark parse date - Database::exec("UPDATE machine SET dataparsetime = UNIX_TIMESTAMP() WHERE machineuuid = :uuid", - ['uuid' => $uuid]); + Database::exec("UPDATE machine SET dataparsetime = UNIX_TIMESTAMP(), id44mb = :id44, id45mb = :id45 + WHERE machineuuid = :uuid", [ + 'uuid' => $uuid, + 'id44' => round($id44 / (1024 * 1024)), + 'id45' => round($id45 / (1024 * 1024)), + ]); } /** |