Simplify SMART status retrieval

This commit is contained in:
Ely Deckers 2022-02-19 12:25:40 +01:00
parent 723cb10263
commit 6a3f5ad040

View File

@ -902,21 +902,20 @@ class PfzCommands
// Taken from /usr/local/www/widgets/widgets/smart_status.widget.php // Taken from /usr/local/www/widgets/widgets/smart_status.widget.php
public static function smart_status() public static function smart_status()
{ {
foreach (PfEnv::get_smart_drive_list() as $dev) { $dev_states = array_map(
$dev_state = trim(exec("smartctl -H /dev/$dev | awk -F: '/^SMART overall-health self-assessment test result/ {print $2;exit} fn($dev) => trim(exec("smartctl -H /dev/$dev | awk -F: '/^SMART overall-health self-assessment test result/ {print $2;exit}
/^SMART Health Status/ {print $2;exit}'")); ## get SMART state from drive /^SMART Health Status/ {print $2;exit}'")),
$is_known_state = array_key_exists($dev_state, SMART_DEV_STATUS); PfEnv::get_smart_drive_list());
if (!$is_known_state) {
return Util::result(SMART_ERROR, true);
}
$status = SMART_DEV_STATUS[$dev_state]; $maybe_not_ok = Util::array_first($dev_states, function ($dev_state) {
if ($status !== SMART_OK) { $is_ok =
return Util::result($status, true); array_key_exists($dev_state, SMART_DEV_STATUS) &&
} SMART_DEV_STATUS[$dev_state] == SMART_OK;
}
return Util::result(SMART_OK, true); return !$is_ok;
});
return Util::result($maybe_not_ok ?: SMART_OK, true);
} }
public static function cert_date($value_key) public static function cert_date($value_key)