Files
SnarfCode/scripts/query_nas_from_swarm.py

53 lines
2.4 KiB
Python

import paramiko, json
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('140.44.4.71', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
def query_nas(ip, name):
print(f"\n=== Querying {name} ({ip}) from Swm01 ===")
for user in ['snarf', 'admin']:
login_cmd = f"curl -k -s 'https://{ip}:5001/webapi/auth.cgi?api=SYNO.API.Auth&version=3&method=login&account={user}&passwd=Katzir476!&session=Storage&format=sid'"
_, o, _ = c.exec_command(login_cmd)
resp_str = o.read().decode().strip()
try:
res = json.loads(resp_str)
if res.get('success'):
sid = res['data']['sid']
print(f"Logged in as {user}!")
st_cmd = f"curl -k -s 'https://{ip}:5001/webapi/entry.cgi?api=SYNO.Storage.CGI.Storage&version=1&method=load_info&_sid={sid}'"
_, o2, _ = c.exec_command(st_cmd)
st_data = json.loads(o2.read().decode())
data = st_data.get('data', {})
vols = data.get('volumes', [])
disks = data.get('disks', [])
print(f"Disks count: {len(disks)}")
tot_raw = 0
for d in disks:
sz = int(d.get('size_total', 0)) / (1024**4)
tot_raw += sz
print(f" Drive {d.get('name')}: {d.get('model', 'Unknown')}, Size: {sz:.2f} TiB, Status: {d.get('status')}")
print(f"Total Raw Drive Capacity: {tot_raw:.2f} TiB")
print(f"Volumes count: {len(vols)}")
tot_vol = 0
tot_used = 0
for v in vols:
v_tot = int(v.get('size_total', 0)) / (1024**4)
v_usd = int(v.get('size_used', 0)) / (1024**4)
tot_vol += v_tot
tot_used += v_usd
print(f" Volume {v.get('name')}: Usable: {v_tot:.2f} TiB, Used: {v_usd:.2f} TiB, FS: {v.get('fs_type')}")
print(f"Total Usable Volume: {tot_vol:.2f} TiB (Used: {tot_used:.2f} TiB)")
break
else:
print(f"Login failed as {user}: {res}")
except Exception as e:
print(f"Error parse: {e}, raw: {resp_str[:150]}")
query_nas('14.10.10.71', 'SN-NAS (RS810+)')
query_nas('14.10.10.72', 'SnarfNAS (DS416play)')
c.close()