Auto-update: Wed Nov 13 15:54:14 PST 2024
This commit is contained in:
parent
4bfeed7e3d
commit
a65e8eed6a
2 changed files with 21 additions and 1 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
22
sijapi.15s.py
Normal file → Executable file
22
sijapi.15s.py
Normal file → Executable file
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue