feat: add various infrastructure check and automation scripts
This commit is contained in:
57
scripts/investigate_issues.py
Normal file
57
scripts/investigate_issues.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import paramiko
|
||||
import json
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
SSH_KEY = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
|
||||
|
||||
def run_ssh(host, user, password, cmd, sudo=False):
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
try:
|
||||
if password and not SSH_KEY:
|
||||
client.connect(host, username=user, password=password, timeout=10)
|
||||
else:
|
||||
client.connect(host, username=user, key_filename=SSH_KEY, password=password, timeout=10)
|
||||
if sudo:
|
||||
full_cmd = f"echo {password} | sudo -S sh -c '{cmd}'"
|
||||
else:
|
||||
full_cmd = cmd
|
||||
stdin, stdout, stderr = client.exec_command(full_cmd)
|
||||
out = stdout.read().decode('utf-8', errors='ignore').strip()
|
||||
err = stderr.read().decode('utf-8', errors='ignore').strip()
|
||||
client.close()
|
||||
return out, err
|
||||
except Exception as e:
|
||||
return "", str(e)
|
||||
|
||||
print("=== 1. HARVESTER LONGHORN VOLUMES & VMS ===")
|
||||
k8s_env = "export KUBECONFIG=/etc/rancher/rke2/rke2.yaml; PATH=$PATH:/var/lib/rancher/rke2/bin; "
|
||||
out, err = run_ssh("140.44.4.90", "rancher", "Katzir476!", k8s_env + "kubectl get virtualmachines.kubevirt.io -A -o wide", sudo=True)
|
||||
print("VMs:")
|
||||
print(out)
|
||||
out, err = run_ssh("140.44.4.90", "rancher", "Katzir476!", k8s_env + "kubectl get pvc -A", sudo=True)
|
||||
print("\nPVCs:")
|
||||
print(out)
|
||||
out, err = run_ssh("140.44.4.90", "rancher", "Katzir476!", k8s_env + "kubectl get nodes.longhorn.io -n longhorn-system", sudo=True)
|
||||
print("\nLonghorn Nodes:")
|
||||
print(out)
|
||||
out, err = run_ssh("140.44.4.90", "rancher", "Katzir476!", k8s_env + "kubectl get volumes.longhorn.io -n longhorn-system -o custom-columns=NAME:.metadata.name,STATE:.status.state,ROBUSTNESS:.status.robustness,FRONTEND:.spec.frontend,REPLICAS:.status.currentReplicas", sudo=True)
|
||||
print("\nLonghorn Volumes Detail:")
|
||||
print(out)
|
||||
|
||||
print("\n=== 2. HEIMDALL CONTAINER & SQLITE DATABASE ===")
|
||||
# Check Shipyard swarm leader (140.44.4.71)
|
||||
out, err = run_ssh("140.44.4.71", "snarf", "Katzir476!", "docker service ls | grep -i heimdall || docker ps | grep -i heimdall", sudo=True)
|
||||
print("Heimdall Swarm / Docker process on 140.44.4.71:")
|
||||
print(out)
|
||||
# If not on 71, check docker service inspect or swarm tasks
|
||||
out, err = run_ssh("140.44.4.71", "snarf", "Katzir476!", "docker service ps $(docker service ls -q -f name=heimdall) --no-trunc 2>/dev/null", sudo=True)
|
||||
print("Heimdall Service Task:")
|
||||
print(out)
|
||||
|
||||
# Also check Spaceport K3s (140.44.4.41) just in case heimdall is on k8s
|
||||
out, err = run_ssh("140.44.4.41", "snarf", "Katzir476!", "kubectl get pods -A | grep -i heimdall", sudo=True)
|
||||
print("Heimdall on Spaceport K3s (if any):")
|
||||
print(out)
|
||||
|
||||
Reference in New Issue
Block a user