Updated SMART value parser

This commit is contained in:
2025-03-03 18:42:38 -05:00
parent b969f8c0e4
commit 11b80b514c

View File

@ -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':