From 11b80b514c52a1cde73b004b8e6293d02a4f11ac Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 3 Mar 2025 18:42:38 -0500 Subject: [PATCH] Updated SMART value parser --- hwmonDaemon.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 7e4ec68..e635ec7 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -505,6 +505,23 @@ class SystemHealthMonitor: return firmware_info + def _parse_smart_value(self, raw_value: str) -> int: + """ + Parse SMART values handling different formats + """ + try: + # Handle time format (e.g., '15589h+17m+33.939s') + if 'h+' in raw_value: + return int(raw_value.split('h+')[0]) + # Handle hex values + if '0x' in raw_value: + return int(raw_value, 16) + # Handle basic numbers + return int(raw_value) + except ValueError: + logger.debug(f"Could not parse SMART value: {raw_value}") + return 0 + def _check_smart_health(self, device: str) -> Dict[str, Any]: """ Enhanced SMART health check with detailed failure thresholds. @@ -565,10 +582,9 @@ class SystemHealthMonitor: # Parse SMART attributes with thresholds for line in output.split('\n'): - # Inside the try block where SMART attributes are parsed: if 'Reported_Uncorrect' in line: parts = line.split() - raw_value = int(parts[9]) + raw_value = self._parse_smart_value(parts[9]) logger.debug(f"Found Reported_Uncorrect value: {raw_value}") smart_health['attributes']['Reported_Uncorrect'] = raw_value @@ -580,11 +596,12 @@ class SystemHealthMonitor: if smart_health['severity'] != 'CRITICAL': smart_health['severity'] = 'WARNING' smart_health['issues'].append(f"Warning: uncorrectable errors detected: {raw_value}") + for attr, thresholds in SMART_THRESHOLDS.items(): if attr in line: parts = line.split() if len(parts) >= 10: - raw_value = int(parts[9]) + raw_value = self._parse_smart_value(parts[9]) smart_health['attributes'][attr] = raw_value if attr == 'Temperature_Celsius':