diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 3f30d6b..a804a14 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -303,25 +303,40 @@ 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)) + # 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]: """ Check disk firmware version against known problematic versions. @@ -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 = {