summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/inc/hardwareparser.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/statistics/inc/hardwareparser.inc.php')
-rw-r--r--modules-available/statistics/inc/hardwareparser.inc.php36
1 files changed, 27 insertions, 9 deletions
diff --git a/modules-available/statistics/inc/hardwareparser.inc.php b/modules-available/statistics/inc/hardwareparser.inc.php
index 55ebbbcc..15534749 100644
--- a/modules-available/statistics/inc/hardwareparser.inc.php
+++ b/modules-available/statistics/inc/hardwareparser.inc.php
@@ -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
@@ -734,6 +734,7 @@ class HardwareParser
self::markDisconnected($uuid, HardwareInfo::PCI_DEVICE, $pciHwIds);
// ---- Disks ------------------------------------0Y3R3K
$hddHwIds = [];
+ $id44 = $id45 = 0;
foreach (($data['drives'] ?? []) as $dev) {
if (empty($dev['readlink']))
continue;
@@ -750,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,
@@ -792,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') {
@@ -806,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]))
@@ -822,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 '@%'", [
@@ -847,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)),
+ ]);
}
/**