From d79005eb428bfc3445988a92184518b870064273 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Tue, 10 Feb 2026 12:56:00 -0500 Subject: [PATCH] Centralize hardcoded magic numbers into CONFIG dict Move NEW_DRIVE_HOURS_THRESHOLD (720h) and SMART_ERROR_RECENT_HOURS (168h) from inline literals to configurable CONFIG entries with .env support. Resolves https://code.lotusguild.org/LotusGuild/hwmonDaemon/issues/20 Co-Authored-By: Claude Opus 4.6 --- hwmonDaemon.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index d980c90..3a6ab26 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -124,7 +124,10 @@ class SystemHealthMonitor: # Prometheus metrics settings 'PROMETHEUS_ENABLED': False, # Enable Prometheus metrics export 'PROMETHEUS_PORT': 9101, # Port for Prometheus metrics HTTP server - 'PROMETHEUS_TEXTFILE_PATH': None # Path for textfile collector (alternative to HTTP) + 'PROMETHEUS_TEXTFILE_PATH': None, # Path for textfile collector (alternative to HTTP) + # SMART analysis thresholds + 'NEW_DRIVE_HOURS_THRESHOLD': 720, # Hours to consider a drive "new" (~30 days) + 'SMART_ERROR_RECENT_HOURS': 168 # Hours window for recent SMART errors (~1 week) } @classmethod @@ -182,6 +185,10 @@ class SystemHealthMonitor: elif key == 'CLUSTER_NAME': cls.CONFIG['CLUSTER_NAME'] = value if value else 'proxmox-cluster' logger.info(f"✓ Loaded CLUSTER_NAME: {value}") + elif key == 'NEW_DRIVE_HOURS_THRESHOLD': + cls.CONFIG['NEW_DRIVE_HOURS_THRESHOLD'] = int(value) + elif key == 'SMART_ERROR_RECENT_HOURS': + cls.CONFIG['SMART_ERROR_RECENT_HOURS'] = int(value) except Exception as e: logger.error(f"Failed to load .env file: {e}") @@ -2266,7 +2273,7 @@ class SystemHealthMonitor: def _is_new_drive(self, power_on_hours: int) -> bool: """Determine if a drive is considered "new" based on power-on hours.""" - return power_on_hours < 720 # Less than 1 week of runtime + return power_on_hours < self.CONFIG['NEW_DRIVE_HOURS_THRESHOLD'] def _check_smart_health(self, device: str) -> Dict[str, Any]: """Enhanced SMART health check with better error handling and predictive analysis.""" @@ -2501,7 +2508,7 @@ class SystemHealthMonitor: for match in error_matches: error_hour = int(match.group(1)) current_hours = smart_health['attributes'].get('Power_On_Hours', 0) - if current_hours - error_hour < 168: # Errors within last week + if current_hours - error_hour < self.CONFIG['SMART_ERROR_RECENT_HOURS']: recent_errors.append(match.group(0)) if recent_errors: