feat: add disk label and device identification to telemetry collection script
This commit is contained in:
@@ -125,6 +125,37 @@ def send_rocket_chat_notification(title, message, color="#764FA5"):
|
||||
except Exception as e:
|
||||
print(f" -> [!] Failed to send webhook: {e}")
|
||||
|
||||
def get_linux_labels():
|
||||
labels = {}
|
||||
try:
|
||||
if os.path.exists("/dev/disk/by-label"):
|
||||
for label in os.listdir("/dev/disk/by-label"):
|
||||
try:
|
||||
full_path = os.path.join("/dev/disk/by-label", label)
|
||||
real_dev = os.path.realpath(full_path)
|
||||
labels[real_dev] = label
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
return labels
|
||||
|
||||
def get_windows_label(drive):
|
||||
try:
|
||||
import ctypes
|
||||
volumeNameBuffer = ctypes.create_unicode_buffer(260)
|
||||
rc = ctypes.windll.kernel32.GetVolumeInformationW(
|
||||
ctypes.c_wchar_p(drive),
|
||||
volumeNameBuffer,
|
||||
ctypes.sizeof(volumeNameBuffer),
|
||||
None, None, None, None, 0
|
||||
)
|
||||
if rc:
|
||||
return volumeNameBuffer.value
|
||||
except Exception:
|
||||
pass
|
||||
return ""
|
||||
|
||||
def collect_and_send_telemetry():
|
||||
try:
|
||||
gpus = []
|
||||
@@ -151,6 +182,7 @@ def collect_and_send_telemetry():
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
linux_labels = get_linux_labels() if os.name != "nt" else {}
|
||||
disks = []
|
||||
for part in psutil.disk_partitions(all=False):
|
||||
if 'loop' in part.device or 'loop' in part.fstype or part.fstype == '':
|
||||
@@ -161,8 +193,28 @@ def collect_and_send_telemetry():
|
||||
continue
|
||||
try:
|
||||
usage = psutil.disk_usage(part.mountpoint)
|
||||
|
||||
# Resolve label/friendly name
|
||||
label = ""
|
||||
if os.name == "nt":
|
||||
label = get_windows_label(part.mountpoint)
|
||||
if not label:
|
||||
if part.mountpoint == "C:\\":
|
||||
label = "OS"
|
||||
else:
|
||||
label = f"Local Disk ({part.mountpoint.strip('\\')})"
|
||||
else:
|
||||
label = linux_labels.get(part.device, "")
|
||||
if not label:
|
||||
if part.mountpoint == "/":
|
||||
label = "Computer"
|
||||
else:
|
||||
label = os.path.basename(part.mountpoint) or "Volume"
|
||||
|
||||
disks.append({
|
||||
"mount": part.mountpoint,
|
||||
"device": part.device,
|
||||
"label": label,
|
||||
"total_gb": round(usage.total / (1024**3), 2),
|
||||
"free_gb": round(usage.free / (1024**3), 2),
|
||||
"percent": usage.percent
|
||||
|
||||
Reference in New Issue
Block a user