Auto-update: Wed Nov 13 15:54:14 PST 2024

This commit is contained in:
sanj 2024-11-13 15:54:14 -08:00
parent 4bfeed7e3d
commit a65e8eed6a
2 changed files with 21 additions and 1 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

22
sijapi.15s.py Normal file → Executable file
View file

@ -45,7 +45,26 @@ def run_ssh_command(server, command):
ssh = paramiko.SSHClient() ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try: try:
ssh.connect(server['ts_ip'], port=server['ssh_port'], username=server['ssh_user'], password=server['ssh_pass']) # Determine authentication method
if 'ssh_key' in server:
# Use SSH key authentication
ssh.connect(
server['ts_ip'],
port=server['ssh_port'],
username=server['ssh_user'],
key_filename=server['ssh_key']
)
elif 'ssh_pass' in server:
# Use password authentication
ssh.connect(
server['ts_ip'],
port=server['ssh_port'],
username=server['ssh_user'],
password=server['ssh_pass']
)
else:
raise ValueError("Neither ssh_key nor ssh_pass provided in server configuration")
stdin, stdout, stderr = ssh.exec_command(command) stdin, stdout, stderr = ssh.exec_command(command)
result = stdout.read().decode().strip() result = stdout.read().decode().strip()
error = stderr.read().decode().strip() error = stderr.read().decode().strip()
@ -58,6 +77,7 @@ def run_ssh_command(server, command):
finally: finally:
ssh.close() ssh.close()
def check_health(ip, port): def check_health(ip, port):
try: try:
response = requests.get(f"http://{ip}:{port}/health", timeout=5, verify=False) response = requests.get(f"http://{ip}:{port}/health", timeout=5, verify=False)