feat: add diagnostic and traffic policy management scripts for DNS and Pi-hole
This commit is contained in:
34
scripts/check_pihole_queries.py
Normal file
34
scripts/check_pihole_queries.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import sys
|
||||
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. Aerodrome Pi-hole Query Flow ===")
|
||||
ok, out, err = run_ssh_cmd("140.44.4.11", "root", "k3s kubectl exec -n dns deploy/pihole -c pihole -- pihole status")
|
||||
print(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 count(*) FROM queries WHERE timestamp > strftime(\"%s\",\"now\",\"-30 minutes\");'")
|
||||
print(f"Queries in last 30 min: {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\",\"-30 minutes\") GROUP BY client ORDER BY count(*) DESC LIMIT 5;'")
|
||||
print(f"Top clients (last 30m):\n{out.strip()}")
|
||||
|
||||
print("\n=== 2. Spaceport Pi-hole Query Flow ===")
|
||||
ok, out, err = run_ssh_cmd("140.44.4.41", "root", "k3s kubectl exec -n dns deploy/pihole -c pihole -- pihole status")
|
||||
print(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 count(*) FROM queries WHERE timestamp > strftime(\"%s\",\"now\",\"-30 minutes\");'")
|
||||
print(f"Queries in last 30 min: {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\",\"-30 minutes\") GROUP BY client ORDER BY count(*) DESC LIMIT 5;'")
|
||||
print(f"Top clients (last 30m):\n{out.strip()}")
|
||||
|
||||
Reference in New Issue
Block a user