Updated _check_drives_health

This commit is contained in:
2025-03-03 17:37:59 -05:00
parent 7b1a683575
commit 7856f9e9bd

View File

@ -301,6 +301,35 @@ class SystemHealthMonitor:
return issues return issues
def _get_all_disks(self) -> List[str]:
"""
Get all physical disks using multiple detection methods.
"""
disks = set()
# Method 1: Use lsblk to get physical disks
try:
result = subprocess.run(
['lsblk', '-d', '-n', '-o', 'NAME'],
stdout=subprocess.PIPE,
text=True
)
disks.update(f"/dev/{disk}" for disk in result.stdout.strip().split('\n'))
logger.debug(f"Disks found via lsblk: {disks}")
except Exception as e:
logger.debug(f"lsblk detection failed: {e}")
# Method 2: Direct device scanning
for pattern in ['/dev/sd*', '/dev/nvme*n*']:
try:
matches = glob.glob(pattern)
disks.update(d for d in matches if not d[-1].isdigit())
logger.debug(f"Disks found via glob {pattern}: {matches}")
except Exception as e:
logger.debug(f"Glob detection failed for {pattern}: {e}")
return list(disks)
def _is_physical_disk(self, device_path): def _is_physical_disk(self, device_path):
""" """
Check if the device is a physical disk, excluding logical volumes and special devices. Check if the device is a physical disk, excluding logical volumes and special devices.
@ -552,6 +581,10 @@ class SystemHealthMonitor:
:return: Combined health report of all drives and their status. :return: Combined health report of all drives and their status.
""" """
drives_health = {'overall_status': 'NORMAL', 'drives': []} drives_health = {'overall_status': 'NORMAL', 'drives': []}
physical_disks = self._get_all_disks()
logger.debug(f"Found physical disks: {physical_disks}")
try: try:
all_partitions = psutil.disk_partitions() all_partitions = psutil.disk_partitions()
logger.debug(f"All disk partitions found: {[p.device for p in all_partitions]}") logger.debug(f"All disk partitions found: {[p.device for p in all_partitions]}")
@ -610,6 +643,29 @@ class SystemHealthMonitor:
drives_health['drives'].append(drive_report) drives_health['drives'].append(drive_report)
# Add non-mounted physical disks
for disk in physical_disks:
if not any(d['device'] == disk for d in drives_health['drives']):
drive_report = {
'device': disk,
'mountpoint': None,
'usage_status': 'UNMOUNTED'
}
# Check SMART health for unmounted disks
smart_health = self._check_smart_health(disk)
drive_report.update({
'smart_status': smart_health['status'],
'smart_issues': smart_health['issues'],
'temperature': smart_health['temp'],
'smart_attributes': smart_health['attributes']
})
if smart_health['status'] == 'UNHEALTHY':
overall_status = 'CRITICAL'
drives_health['drives'].append(drive_report)
drives_health['overall_status'] = overall_status drives_health['overall_status'] = overall_status
except Exception as e: except Exception as e: