import paramiko import time 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) with open(r'c:\Users\Snarf\OneDrive\Desktop\code\SnarfCode\homelab-gitops-repo\manifests\aerodrome\prometheus\prometheus.yaml', 'r') as f: prom_yaml = f.read() stdin, stdout, stderr = c.exec_command("cat > /tmp/prometheus.yaml") stdin.write(prom_yaml) stdin.close() stdout.channel.recv_exit_status() _, o, e = c.exec_command("kubectl apply -f /tmp/prometheus.yaml") print("Kubectl apply:\n", o.read().decode().strip()) err = e.read().decode().strip() if err: print("Err:", err) # Find prometheus pod _, o, _ = c.exec_command("kubectl get pod -l app.kubernetes.io/name=prometheus -o jsonpath='{.items[0].metadata.name}'") pod = o.read().decode().strip() print("Prometheus pod:", pod) # Reload config _, o, _ = c.exec_command(f"kubectl exec {pod} -- wget -qO- --post-action='' http://localhost:9090/-/reload || kubectl exec {pod} -- curl -X POST http://localhost:9090/-/reload") print("Reload result:", o.read().decode().strip()) time.sleep(5) # Check targets for shipyard _, o, _ = c.exec_command(f"""kubectl exec {pod} -- wget -qO- 'http://localhost:9090/api/v1/targets' | grep -o '"cluster":"shipyard"[^}}]*' | head -10""") print("Shipyard targets found in Prometheus:\n", o.read().decode().strip()) c.close()