import asyncio
import httpx
import sys
HUB_URL = "http://0.0.0.0:8000/api/v1"
HEADERS = {"X-User-ID": "585cd6e9-05e5-42ac-83a5-93029c6cb038"}
async def verify():
async with httpx.AsyncClient(headers=HEADERS, timeout=30.0) as client:
# 1. Get Nodes
win_node = "media-windows-server"
# 2. Test Terminal (whoami)
print(f"\n--- Testing Terminal on {win_node} ---")
res = await client.post(f"{HUB_URL}/nodes/{win_node}/dispatch?user_id=585cd6e9-05e5-42ac-83a5-93029c6cb038", json={"command": "whoami", "timeout_ms": 10000})
print(f"Dispatch Result: {res.json()}")
# 3. Test Disk Check (wmic)
print(f"\n--- Testing Disk Check on {win_node} ---")
disk_cmd = "wmic logicaldisk get caption, freespace, size"
res = await client.post(f"{HUB_URL}/nodes/{win_node}/dispatch?user_id=585cd6e9-05e5-42ac-83a5-93029c6cb038", json={"command": disk_cmd, "timeout_ms": 15000})
print(f"Dispatch Result: {res.json()}")
print("\n--- Waiting 5 secs for outputs ---")
await asyncio.sleep(5)
terminal_res = await client.get(f"{HUB_URL}/nodes/{win_node}/terminal", headers={"X-User-ID": "585cd6e9-05e5-42ac-83a5-93029c6cb038"})
data = terminal_res.json()
terminal_history = data.get("terminal", [])
print("\n--- Recent Terminal Output ---")
for line in terminal_history[-20:]: # Print last 20 lines
print(line.strip())
# 4. Test File Explorer
print(f"\n--- Testing File Explorer (C:\\) on {win_node} ---")
res = await client.get(f"{HUB_URL}/nodes/{win_node}/fs/ls?path=C:/")
print(f"LS C:/ Result: {res.json()}")
if __name__ == "__main__":
asyncio.run(verify())