diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..c349505 Binary files /dev/null and b/.DS_Store differ diff --git a/sijapi.15s.py b/sijapi.15s.py old mode 100644 new mode 100755 index 3103726..7856e8f --- a/sijapi.15s.py +++ b/sijapi.15s.py @@ -45,7 +45,26 @@ def run_ssh_command(server, command): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 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) result = stdout.read().decode().strip() error = stderr.read().decode().strip() @@ -58,6 +77,7 @@ def run_ssh_command(server, command): finally: ssh.close() + def check_health(ip, port): try: response = requests.get(f"http://{ip}:{port}/health", timeout=5, verify=False)