#!/usr/bin/env python3
import paramiko

HOST = "192.168.20.100"
USER = "root"
PASSWORD = "Zcloud@zcloud100"

cmds = [
    "kubectl get pods -n jjb-dragon -l app=jjb-saas-system-pod --field-selector=status.phase=Running -o wide",
    "kubectl get pods -n jjb-dragon -l app=jjb-saas-message-pod --field-selector=status.phase=Running -o wide",
    "bash /opt/dubbo-dev-proxy/dubbo-proxy-refresh.sh",
    "bash /opt/dubbo-dev-proxy/dubbo-proxy-status.sh",
    "ss -lntp | awk '/3208|32100/'",
    "ls -la /var/log/dubbo-dev-proxy/ | head -5",
    "tail -3 /var/log/dubbo-dev-proxy/32080.log 2>/dev/null || echo no_log",
]

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(HOST, username=USER, password=PASSWORD, timeout=20)
for cmd in cmds:
    print(f"\n>>> {cmd}")
    stdin, stdout, stderr = client.exec_command(cmd, timeout=120)
    print(stdout.read().decode())
    err = stderr.read().decode()
    if err:
        print("STDERR:", err)
client.close()
