Files
SnarfCode/scripts/test_dns_and_pihole_live.py

39 lines
2.2 KiB
Python

import paramiko
SSH_KEY = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
def run_ssh_cmd(host, user, cmd, timeout=10):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(host, username=user, key_filename=SSH_KEY, timeout=timeout)
stdin, stdout, stderr = client.exec_command(cmd, timeout=timeout)
out = stdout.read().decode('utf-8', errors='replace')
err = stderr.read().decode('utf-8', errors='replace')
client.close()
return True, out, err
except Exception as e:
return False, "", str(e)
print("=== 1. Testing DNS resolution from nutserver (14.4.4.44, VLAN 50) ===")
for vip, name in [("140.44.4.36", "Aerodrome"), ("140.44.4.65", "Spaceport")]:
ok, out, err = run_ssh_cmd("14.4.4.44", "root", f"nslookup snarfhome.snarfnet.net {vip}")
print(f"[{name} - {vip}]:\n{out.strip()}\n")
print("=== 2. Testing NTP Peer status from nutserver (14.4.4.44, VLAN 50) ===")
ok, out, err = run_ssh_cmd("14.4.4.44", "root", "chronyc sources")
print(out.strip())
print("\n=== 3. Checking Pi-hole Live Query Flow (Aerodrome pod) ===")
ok, out, err = run_ssh_cmd("140.44.4.11", "root", "k3s kubectl exec -n dns deploy/pihole -c pihole -- pihole status")
print(f"Aerodrome Pi-hole Status:\n{out.strip()}")
ok, out, err = run_ssh_cmd("140.44.4.11", "root", "k3s kubectl exec -n dns deploy/pihole -c pihole -- sqlite3 /etc/pihole/pihole-FTL.db 'SELECT client, count(*) FROM queries WHERE timestamp > strftime(\"%s\",\"now\",\"-10 minutes\") GROUP BY client ORDER BY count(*) DESC LIMIT 5;'")
print(f"Top recent clients on Aerodrome (last 10m):\n{out.strip()}")
print("\n=== 4. Checking Pi-hole Live Query Flow (Spaceport pod) ===")
ok, out, err = run_ssh_cmd("140.44.4.41", "root", "k3s kubectl exec -n dns deploy/pihole -c pihole -- pihole status")
print(f"Spaceport Pi-hole Status:\n{out.strip()}")
ok, out, err = run_ssh_cmd("140.44.4.41", "root", "k3s kubectl exec -n dns deploy/pihole -c pihole -- sqlite3 /etc/pihole/pihole-FTL.db 'SELECT client, count(*) FROM queries WHERE timestamp > strftime(\"%s\",\"now\",\"-10 minutes\") GROUP BY client ORDER BY count(*) DESC LIMIT 5;'")
print(f"Top recent clients on Spaceport (last 10m):\n{out.strip()}")