summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics
diff options
context:
space:
mode:
authorSimon Rettberg2022-10-26 15:16:10 +0200
committerSimon Rettberg2022-10-26 15:16:10 +0200
commit451faa21fb625a36c7216d39480ca8e579b03ed6 (patch)
tree8082763a6b4816fa3b58dda5bebfaaec6eb8b38e /modules-available/statistics
parent[inc/Database] Force utf8mb4 explicitly via SET NAMES (diff)
downloadslx-admin-451faa21fb625a36c7216d39480ca8e579b03ed6.tar.gz
slx-admin-451faa21fb625a36c7216d39480ca8e579b03ed6.tar.xz
slx-admin-451faa21fb625a36c7216d39480ca8e579b03ed6.zip
[statistics] Use partition numbers from kernel
Diffstat (limited to 'modules-available/statistics')
-rw-r--r--modules-available/statistics/inc/hardwareparser.inc.php32
-rw-r--r--modules-available/statistics/pages/machine.inc.php2
2 files changed, 24 insertions, 10 deletions
diff --git a/modules-available/statistics/inc/hardwareparser.inc.php b/modules-available/statistics/inc/hardwareparser.inc.php
index 5dd29e16..565c9a54 100644
--- a/modules-available/statistics/inc/hardwareparser.inc.php
+++ b/modules-available/statistics/inc/hardwareparser.inc.php
@@ -256,13 +256,16 @@ class HardwareParser
* @param array $global associative array of properties this hardware has
* @return int id of this hardware; primary key of row in statistic_hw_prop
*/
- private static function writeGlobalHardwareData(string $dbType, array $global): int
+ private static function writeGlobalHardwareData(string $dbType, array $global, array $globalExtra = []): int
{
static $cache = [];
// Since the global properties are supposed to be unique for a specific piece of hardware, use them all
// to generate a combined ID for this hardware entity, as opposed to $localProps, which should differ
// between instances of the same hardware entity, e.g. one specific HDD model has different serial numbers.
$id = md5(implode(' ', $global));
+ // But don't include our "fake" fields in this as we might add more there later, which would
+ // change the ID then.
+ $global += $globalExtra;
if (!isset($cache[$id])) {
// Cache lookup, make sure we insert this only once for every run, as this is supposed to be general
// information about the hardware, e.g. model number, max. resolution, capacity, ...
@@ -391,16 +394,16 @@ class HardwareParser
$localMainboardExtra['nic-duplex'] = $bootNic['duplex'] ?? 'unknown';
}
// Finally handle mainbard data, with all of our gathered extra fields
- self::updateHwTypeFromDmi($uuid, $data, 2, HardwareInfo::MAINBOARD, ['Manufacturer', 'Product Name'],
+ self::updateHwTypeFromDmi($uuid, $data, 2, HardwareInfo::MAINBOARD, [],
[],
- ['Manufacturer', 'Product Name', 'Type', 'Version'],
+ ['Manufacturer', 'Product Name', 'Type', 'Version'], // Global props, don't change
['Serial Number', 'Asset Tag', 'Location In Chassis'],
$globalMainboardExtra, $localMainboardExtra
);
// System information, mostly set by OEMs, might be empty/bogus on custom systems
self::updateHwTypeFromDmi($uuid, $data, 1, HardwareInfo::DMI_SYSTEM, ['Manufacturer', 'Product Name'],
[],
- ['Manufacturer', 'Product Name', 'Version', 'Wake-up Type'],
+ ['Manufacturer', 'Product Name', 'Version', 'Wake-up Type'], // Global props, don't change
['Serial Number', 'UUID', 'SKU Number']
);
// Might contain more or less accurate information. Mostly works on servers and OEM systems
@@ -408,13 +411,13 @@ class HardwareParser
['Location',
'Power Unit Group',
'Name'], // Location might be empty/"Unknown", but Name can be something like "PSU 2"
- ['Manufacturer', 'Product Name', 'Model Part Number', 'Revision', 'Max Power Capacity'],
+ ['Manufacturer', 'Product Name', 'Model Part Number', 'Revision', 'Max Power Capacity'], // Global props, don't change
['Serial Number', 'Asset Tag', 'Status', 'Plugged', 'Hot Replaceable']
);
// On some more recent systems this contains quite some useful information
self::updateHwTypeFromDmi($uuid, $data, 4, HardwareInfo::CPU, ['Version'],
['Socket Designation'],
- ['Type', 'Family', 'Manufacturer', 'Signature', 'Version', 'Core Count', 'Thread Count'],
+ ['Type', 'Family', 'Manufacturer', 'Signature', 'Version', 'Core Count', 'Thread Count'], // Global props, don't change
['Voltage', 'Current Speed', 'Upgrade', 'Core Enabled']);
// Information about system slots
self::updateHwTypeFromDmi($uuid, $data, 9, HardwareInfo::SYSTEM_SLOT,
@@ -436,13 +439,14 @@ class HardwareParser
return true;
},
['Designation', 'ID', 'Bus Address'],
- ['Type', 'PCIe Bus Width', 'PCIe Gen', 'PCIe Slot Width'],
+ ['Type', 'PCIe Bus Width', 'PCIe Gen', 'PCIe Slot Width'], // Global props, don't change
['Current Usage', 'Designation']
);
// dmidecode end
// ---- lspci ------------------------------------
$pciHwIds = [];
foreach (($data['lspci'] ?? []) as $dev) {
+ // $props is global props, don't change or the ID will change
$props = self::propsFromArray($dev, 'vendor', 'device', 'rev', 'class');
if (!isset($props['vendor']) || !isset($props['device']))
continue;
@@ -477,6 +481,7 @@ class HardwareParser
$smart['rotation_rate'] = 0;
}
$size = $lsblk['size'] ?? $smart['user_capacity']['bytes'] ?? 'unknown';
+ // Don't change the global props, it would change the HW ID
$hwid = self::writeGlobalHardwareData(HardwareInfo::HDD, [
// Try to use the model name as the unique identifier
'model' => $smart['model_name'] ?? $lsblk['model'] ?? 'unknown',
@@ -545,7 +550,11 @@ class HardwareParser
}
}
$used += $part['size'] * $fac;
- $id = 'part_' . $i . '_';
+ if (isset($part['node']) && preg_match('/-part(\d+)$/', $part['node'], $out)) {
+ $id = 'part_' . $out[1] . '_';
+ } else {
+ $id = 'part_' . ($i + 1) . '_';
+ }
foreach (['start', 'size', 'type', 'uuid', 'name'] as $item) {
if (!isset($part[$item]))
continue;
@@ -702,6 +711,11 @@ class HardwareParser
): int
{
$sections = self::getDmiHandles($data, $type);
+ if (empty($sections) && !empty($globalExtra) || !empty($localExtra)) {
+ // Section not found, but as we want to store additional artificial columms,
+ // just create one empty fake section so the loop will be executed
+ $sections = [[]];
+ }
$thisMachineHwIds = [];
foreach ($sections as $section) {
$flat = self::prepareDmiProperties($section);
@@ -717,7 +731,7 @@ class HardwareParser
}
// Global
$props = self::propsFromArray($flat, ...$globalProps);
- $hwid = self::writeGlobalHardwareData($dbType, $props + $globalExtra);
+ $hwid = self::writeGlobalHardwareData($dbType, $props, $globalExtra);
// Local
$pathId = md5(self::idFromArray($flat, ...$pathFields));
$props = self::propsFromArray($flat, ...$localProps);
diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php
index 9b91e8a4..6368a2b7 100644
--- a/modules-available/statistics/pages/machine.inc.php
+++ b/modules-available/statistics/pages/machine.inc.php
@@ -530,7 +530,7 @@ class SubPage
} elseif (preg_match('/^part_([0-9]+)_(.*)$/', $row['prop'], $out)) {
// Partitions
if (!isset($hdd['partitions'][$out[1]])) {
- $hdd['partitions'][$out[1]] = ['id' => 'dev-' . count($hdds) . '-' . $out[1], 'index' => $out[1] + 1];
+ $hdd['partitions'][$out[1]] = ['id' => 'dev-' . count($hdds) . '-' . $out[1], 'index' => $out[1]];
}
$hdd['partitions'][$out[1]][$out[2]] = $row['numeric'] ?? $row['value'];
} else {