From 24d2502bc49c249527fc8e5f6d1f93a79d5af0eb Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Dec 2024 15:36:02 -0500 Subject: [PATCH] Changed async functions --- hwmonDaemon.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 669543a..6d2b9c4 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -292,8 +292,9 @@ class SystemHealthMonitor: drive_report['error'] = str(e) drives_health['drives'].append(drive_report) drives_health['overall_status'] = overall_status - return drives_health - + except Exception as e: + logger.error(f"Error checking drives health: {str(e)}") + return drives_health def _convert_bytes(bytes_value: int, suffix: str = 'B') -> str: """ @@ -336,7 +337,7 @@ class SystemHealthMonitor: 'status': 'OK' if cpu_usage_percent < 90 else 'WARNING' } return cpu_health - async def _check_network_status(self) -> Dict[str, Any]: + def _check_network_status(self) -> Dict[str, Any]: """ Check the status of network interfaces and report any issues. @@ -349,16 +350,14 @@ class SystemHealthMonitor: try: # Check management network connectivity - proc = await asyncio.create_subprocess_shell("ping -c 1 10.10.10.1", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) - await proc.wait() + proc = subprocess.run(["ping", "-c", "1", "10.10.10.1"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) if proc.returncode != 0: network_health['management_network']['issues'].append( "Management network is unreachable." ) # Check Ceph network connectivity - proc = await asyncio.create_subprocess_shell("ping -c 1 10.10.90.1", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) - await proc.wait() + proc = subprocess.run(["ping", "-c", "1", "10.10.90.1"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) if proc.returncode != 0: network_health['ceph_network']['issues'].append( "Ceph network is unreachable." @@ -370,8 +369,6 @@ class SystemHealthMonitor: print(f"Network health check failed: {e}") return {'error': str(e)} - network_health = asyncio.run(_check_network_status()) - def main(): try: # Parse command-line arguments or read from configuration file @@ -384,6 +381,10 @@ def main(): # Run the health checks monitor.run() + # Check network health asynchronously + network_health = asyncio.run(monitor._check_network_status()) + print(f"Network health: {network_health}") + except KeyboardInterrupt: # Handle KeyboardInterrupt gracefully print("Interrupted by user. Exiting...")