From 1c5344f51bd487baaafac144617748300bbc3b77 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 3 Mar 2025 22:29:37 -0500 Subject: [PATCH] fixed smart_health undefined --- hwmonDaemon.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 5f00740..11c33d2 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -396,8 +396,18 @@ class SystemHealthMonitor: if "Drive" in issue: device = re.search(r'/dev/[a-zA-Z0-9]+', issue).group(0) - drive_details = self._get_drive_details(device) drive_info = next((d for d in health_report['drives_health']['drives'] if d['device'] == device), None) + drive_details = self._get_drive_details(device) + + smart_data = { + 'attributes': drive_info.get('smart_attributes', {}), + 'performance_metrics': drive_info.get('performance_metrics', {}), + 'last_test_date': drive_info.get('last_test_date', 'N/A') + } + + power_on_hours = smart_data['attributes'].get('Power_On_Hours', 'N/A') + last_test_date = smart_data.get('last_test_date', 'N/A') + age = f"{int(power_on_hours/24/365) if isinstance(power_on_hours, (int, float)) else 'N/A'} years" if power_on_hours != 'N/A' else 'N/A' description += """ ┏━ DRIVE SPECIFICATIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ @@ -433,9 +443,6 @@ class SystemHealthMonitor: ┃ IOPS │ {perf_metrics['iops']}{' ' * 52}┃ ┗{'━' * 71}┛ """ - power_on_hours = smart_health['attributes'].get('Power_On_Hours', 'N/A') - last_test_date = smart_health.get('last_test_date', 'N/A') - age = f"{int(power_on_hours/24/365) if isinstance(power_on_hours, (int, float)) else 'N/A'} years" if power_on_hours != 'N/A' else 'N/A' description += """ ┏━ DRIVE TIMELINE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓