Logging drive detection

This commit is contained in:
2025-03-03 17:27:27 -05:00
parent 358baac048
commit 7b1a683575

View File

@ -303,24 +303,39 @@ class SystemHealthMonitor:
def _is_physical_disk(self, device_path):
"""
Check if the device is a physical SATA, NVMe, or MMC disk, excluding system partitions.
Check if the device is a physical disk, excluding logical volumes and special devices.
:param device_path: Path to the device
:return: Boolean indicating if it's a relevant physical disk
"""
logger.debug(f"Checking device: {device_path}")
base_device = re.sub(r'\d+', '', device_path)
logger.debug(f"Base device after stripping numbers: {base_device}")
excluded_mounts = ['/boot', '/boot/efi']
if any(device_path.startswith(mount) for mount in excluded_mounts):
logger.debug(f"Device {device_path} excluded due to mount point")
# Exclude known non-physical or special devices
excluded_patterns = [
r'/dev/mapper/', # LVM devices
r'/dev/dm-', # Device mapper devices
r'/dev/loop', # Loop devices
r'/dev/rbd', # Ceph RBD devices
r'/boot', # Boot partitions
r'/boot/efi' # EFI partitions
]
if any(re.search(pattern, device_path) for pattern in excluded_patterns):
logger.debug(f"Device {device_path} excluded due to pattern match")
return False
is_physical = bool(re.match(r'/dev/(sd[a-z]|nvme\d+n\d+|mmcblk\d+)', base_device))
logger.debug(f"Device {device_path} physical disk check result: {is_physical}")
return is_physical
# Match physical devices
physical_patterns = [
r'/dev/sd[a-z]+$', # SATA/SAS drives
r'/dev/nvme\d+n\d+$', # NVMe drives
r'/dev/mmcblk\d+$', # MMC/SD cards
r'/dev/hd[a-z]+$' # IDE drives (legacy)
]
is_physical = any(re.match(pattern, device_path) for pattern in physical_patterns)
logger.debug(f"Device {device_path} physical disk check result: {is_physical}")
return is_physical
def _check_disk_firmware(self, device: str) -> Dict[str, Any]:
"""
@ -538,7 +553,23 @@ class SystemHealthMonitor:
"""
drives_health = {'overall_status': 'NORMAL', 'drives': []}
try:
partitions = [p for p in psutil.disk_partitions() if self._is_physical_disk(p.device)]
all_partitions = psutil.disk_partitions()
logger.debug(f"All disk partitions found: {[p.device for p in all_partitions]}")
# Log each partition evaluation
partitions = []
for p in all_partitions:
is_physical = self._is_physical_disk(p.device)
logger.debug(f"Evaluating partition: {p.device}")
logger.debug(f" Mountpoint: {p.mountpoint}")
logger.debug(f" FStype: {p.fstype}")
logger.debug(f" Opts: {p.opts}")
logger.debug(f" Is Physical: {is_physical}")
if is_physical:
partitions.append(p)
logger.debug(f"Final physical partitions selected: {[p.device for p in partitions]}")
overall_status = 'NORMAL'
for partition in partitions:
drive_report = {