Fix mojibake text and add md RAID checks
This commit is contained in:
@@ -82,6 +82,53 @@ def list_disks() -> list[str]:
|
||||
return disks
|
||||
|
||||
|
||||
def list_md_arrays() -> list[str]:
|
||||
out = _cmd("lsblk -dn -o NAME,TYPE")
|
||||
arrays = []
|
||||
for line in out.splitlines():
|
||||
parts = line.split()
|
||||
if len(parts) != 2:
|
||||
continue
|
||||
name, typ = parts
|
||||
if typ == "raid" and name.startswith("md"):
|
||||
arrays.append(f"/dev/{name}")
|
||||
return arrays
|
||||
|
||||
|
||||
def md_array_status(dev: str) -> str:
|
||||
out = _cmd("cat /proc/mdstat")
|
||||
if not out or "ERROR:" in out:
|
||||
return "⚠️ n/a"
|
||||
|
||||
name = dev.rsplit("/", 1)[-1]
|
||||
lines = out.splitlines()
|
||||
header = None
|
||||
idx = -1
|
||||
for i, line in enumerate(lines):
|
||||
s = line.strip()
|
||||
if s.startswith(f"{name} :"):
|
||||
header = s
|
||||
idx = i
|
||||
break
|
||||
|
||||
if not header:
|
||||
return "⚠️ not found in /proc/mdstat"
|
||||
|
||||
if "inactive" in header:
|
||||
return "🔴 inactive"
|
||||
|
||||
# Typical mdstat health marker: [UU] for healthy mirrors/raid members.
|
||||
block = [header]
|
||||
for line in lines[idx + 1:]:
|
||||
if not line.strip():
|
||||
break
|
||||
block.append(line.strip())
|
||||
block_text = " ".join(block)
|
||||
if "[U_" in block_text or "[_U" in block_text:
|
||||
return "🟡 degraded"
|
||||
return "🟢 active"
|
||||
|
||||
|
||||
def smart_health(dev: str) -> str:
|
||||
out = _cmd(f"smartctl -H {dev}")
|
||||
|
||||
@@ -138,8 +185,9 @@ def smart_last_test(dev: str) -> str:
|
||||
|
||||
def disks() -> str:
|
||||
disks = list_disks()
|
||||
md_arrays = list_md_arrays()
|
||||
|
||||
if not disks:
|
||||
if not disks and not md_arrays:
|
||||
return "💽 Disks\n\n❌ No disks found"
|
||||
|
||||
lines = ["💽 Disks (SMART)\n"]
|
||||
@@ -158,6 +206,12 @@ def disks() -> str:
|
||||
|
||||
lines.append(f"{icon} {d} — {health}, 🌡 {temp}")
|
||||
|
||||
if md_arrays:
|
||||
lines.append("")
|
||||
lines.append("🧱 RAID (md)")
|
||||
for md in md_arrays:
|
||||
lines.append(f"{md} — {md_array_status(md)}")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user