mirror of https://github.com/openspug/spug
U 优化任务计划页面上可以得到更多错误信息
parent
77669dd5a5
commit
0e98c1553e
|
@ -3,11 +3,12 @@
|
||||||
# Released under the MIT License.
|
# Released under the MIT License.
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from libs.ssh import SSH
|
from libs.ssh import SSH, AuthenticationException
|
||||||
from apps.host.models import Host
|
from apps.host.models import Host
|
||||||
from apps.setting.utils import AppSetting
|
from apps.setting.utils import AppSetting
|
||||||
from django.db import close_old_connections
|
from django.db import close_old_connections
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import socket
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,8 +27,13 @@ def host_executor(q, host, pkey, command):
|
||||||
try:
|
try:
|
||||||
cli = SSH(host.hostname, host.port, host.username, pkey=pkey)
|
cli = SSH(host.hostname, host.port, host.username, pkey=pkey)
|
||||||
exit_code, out = cli.exec_command(command)
|
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:
|
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):
|
def dispatch(command, targets):
|
||||||
|
|
Loading…
Reference in New Issue