Files
SnarfCode/scripts/verify_kuma_spacedock_status.py

32 lines
1.1 KiB
Python

import paramiko
import sys
import time
sys.stdout.reconfigure(encoding='utf-8')
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
def run_sql(pod, sql):
cmd = f"kubectl exec -i -n monitoring {pod} -- mariadb --socket=/app/data/run/mariadb.sock -u root"
stdin, stdout, stderr = c.exec_command(cmd)
stdin.write(sql)
stdin.close()
return stdout.read().decode().strip(), stderr.read().decode().strip()
_, o, _ = c.exec_command("kubectl get pod -n monitoring -l app.kubernetes.io/name=uptime-kuma -o jsonpath='{.items[0].metadata.name}'")
pod = o.read().decode().strip()
print("Kuma Pod:", pod)
out, _ = run_sql(pod, "USE kuma; SELECT id, name, type, hostname, active FROM monitor WHERE id >= 98;")
print("Monitors:")
print(out)
# Check recent heartbeats for these monitors
out_hb, _ = run_sql(pod, "USE kuma; SELECT monitor_id, status, msg, time, ping FROM heartbeat WHERE monitor_id >= 98 ORDER BY id DESC LIMIT 10;")
print("\nRecent Heartbeats:")
print(out_hb)
c.close()