specified sata and nvme as the only devices to be monitored

This commit is contained in:
2024-12-05 20:53:15 -05:00
parent ca28cddfd0
commit 81d723f2a4

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3
import os, sys, json, requests, psutil, socket, subprocess, logging, argparse, urllib.request
import os, sys, json, requests, psutil, socket, subprocess, logging, argparse, urllib.request, re
from typing import Dict, Any, List
# Create a logger
@ -236,15 +236,24 @@ class SystemHealthMonitor:
return issues
def _is_physical_disk(self, device_path):
"""
Check if the device is a physical SATA or NVMe disk.
:param device_path: Path to the device
:return: Boolean indicating if it's a physical disk
"""
return bool(re.match(r'/dev/(sd[a-z]|nvme\d+n\d+)', device_path))
def _check_drives_health(self) -> Dict[str, Any]:
"""
Check overall health of drives including disk usage and SMART status.
Check overall health of physical SATA and NVMe drives including disk usage and SMART status.
:return: Combined health report of all drives and their status.
"""
drives_health = {'overall_status': 'NORMAL', 'drives': []}
try:
partitions = psutil.disk_partitions()
partitions = [p for p in psutil.disk_partitions() if self._is_physical_disk(p.device)]
overall_status = 'NORMAL'
for partition in partitions:
drive_report = {