diff --git a/spug_api/apps/schedule/executors.py b/spug_api/apps/schedule/executors.py index 6e4efaa..82affc0 100644 --- a/spug_api/apps/schedule/executors.py +++ b/spug_api/apps/schedule/executors.py @@ -3,11 +3,12 @@ # Released under the MIT License. from queue import Queue from threading import Thread -from libs.ssh import SSH +from libs.ssh import SSH, AuthenticationException from apps.host.models import Host from apps.setting.utils import AppSetting from django.db import close_old_connections import subprocess +import socket import time @@ -26,8 +27,13 @@ def host_executor(q, host, pkey, command): try: cli = SSH(host.hostname, host.port, host.username, pkey=pkey) exit_code, out = cli.exec_command(command) + out = out.decode() if out else None + except AuthenticationException: + out = 'ssh authentication fail' + except socket.error as e: + out = f'network error {e}' finally: - q.put((host.id, exit_code, round(time.time() - now, 3), out.decode() if out else None)) + q.put((host.id, exit_code, round(time.time() - now, 3), out)) def dispatch(command, targets):