From 332d307fa855bf01779765e1f974c6524c26f592 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 31 Oct 2022 12:51:13 +0100 Subject: [statistics] Deal with broken HDDs that lead to incomplete data We had a machine with a broken HDD that showed up as /dev/sda but didn't do much else, confusing tools like lsblk and fdisk, and ultimately leading to incomplete data in our DB that would make PHP freak out too much about missing array indices and wrong types. --- modules-available/statistics/inc/hardwareparser.inc.php | 2 +- modules-available/statistics/pages/machine.inc.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'modules-available/statistics') diff --git a/modules-available/statistics/inc/hardwareparser.inc.php b/modules-available/statistics/inc/hardwareparser.inc.php index 565c9a54..bfb603ce 100644 --- a/modules-available/statistics/inc/hardwareparser.inc.php +++ b/modules-available/statistics/inc/hardwareparser.inc.php @@ -480,7 +480,7 @@ class HardwareParser // smartctl didn't report on it, lsblk says it's non-rotational $smart['rotation_rate'] = 0; } - $size = $lsblk['size'] ?? $smart['user_capacity']['bytes'] ?? 'unknown'; + $size = $lsblk['size'] ?? $smart['user_capacity']['bytes'] ?? -1; // 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 diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php index b6c1f53c..1e00b8f2 100644 --- a/modules-available/statistics/pages/machine.inc.php +++ b/modules-available/statistics/pages/machine.inc.php @@ -551,6 +551,9 @@ class SubPage private static function mangleHdd(array &$hdd) { static $hddidx = 0; + if (!isset($hdd['size']) || !is_numeric($hdd['size'])) { + $hdd['size'] = 0; + } $hdd['hddidx'] = $hddidx++; $hours = $hdd['power_on_time//hours'] ?? $hdd['attr_9']['raw'] ?? $hdd['power_on_hours'] ?? $hdd['power_on_time']['hours'] ?? null; -- cgit v1.2.3-55-g7522