mirror of https://github.com/jumpserver/jumpserver
perf: Display asset/account connectivity error message
parent
e992c44e11
commit
d06d26ac54
|
@ -85,6 +85,7 @@ class VerifyAccountManager(AccountBasePlaybookManager):
|
|||
def on_host_error(self, host, error, result):
|
||||
account = self.host_account_mapper.get(host)
|
||||
try:
|
||||
account.set_connectivity(Connectivity.ERR)
|
||||
error_tp = account.get_err_connectivity(error)
|
||||
account.set_connectivity(error_tp)
|
||||
except Exception as e:
|
||||
print(f'\033[31m Update account {account.name} connectivity failed: {e} \033[0m\n')
|
||||
|
|
|
@ -37,10 +37,11 @@ class PingManager(BasePlaybookManager):
|
|||
def on_host_error(self, host, error, result):
|
||||
asset, account = self.host_asset_and_account_mapper.get(host)
|
||||
try:
|
||||
asset.set_connectivity(Connectivity.ERR)
|
||||
error_tp = asset.get_err_connectivity(error)
|
||||
asset.set_connectivity(error_tp)
|
||||
if not account:
|
||||
return
|
||||
account.set_connectivity(Connectivity.ERR)
|
||||
account.set_connectivity(error_tp)
|
||||
except Exception as e:
|
||||
print(f'\033[31m Update account {account.name} or '
|
||||
f'update asset {asset.name} connectivity failed: {e} \033[0m\n')
|
||||
|
|
|
@ -7,6 +7,12 @@ class Connectivity(TextChoices):
|
|||
NA = 'na', _('N/A')
|
||||
OK = 'ok', _('OK')
|
||||
ERR = 'err', _('Error')
|
||||
AUTH_ERR = 'auth_err', _('Authentication error')
|
||||
SUDO_ERR = 'sudo_err', _('Sudo permission error')
|
||||
PASSWORD_ERR = 'password_err', _('Invalid password error')
|
||||
OPENSSH_KEY_ERR = 'openssh_key_err', _('OpenSSH key error')
|
||||
NTLM_ERR = 'ntlm__err', _('NTLM credentials rejected error')
|
||||
CREATE_DIR_ERR = 'create_dir_err', _('Create directory error')
|
||||
|
||||
|
||||
class AutomationTypes(TextChoices):
|
||||
|
|
|
@ -23,6 +23,28 @@ class AbsConnectivity(models.Model):
|
|||
self.date_verified = timezone.now()
|
||||
self.save(update_fields=['connectivity', 'date_verified'])
|
||||
|
||||
@staticmethod
|
||||
def get_err_connectivity(msg=None):
|
||||
msg = (msg or '').strip().lower()
|
||||
|
||||
error_map = {
|
||||
'permission denied': Connectivity.AUTH_ERR,
|
||||
'authentication failed': Connectivity.AUTH_ERR,
|
||||
'authentication failure': Connectivity.AUTH_ERR,
|
||||
'is not in the sudoers file': Connectivity.SUDO_ERR,
|
||||
'expected openssh key': Connectivity.OPENSSH_KEY_ERR,
|
||||
'invalid/incorrect password': Connectivity.PASSWORD_ERR,
|
||||
'failed to create directory': Connectivity.CREATE_DIR_ERR,
|
||||
'ntlm: the specified credentials were rejected by the server': Connectivity.NTLM_ERR,
|
||||
|
||||
}
|
||||
|
||||
for key, value in error_map.items():
|
||||
if key in msg:
|
||||
return value
|
||||
|
||||
return Connectivity.ERR
|
||||
|
||||
@property
|
||||
def is_connective(self):
|
||||
if self.connectivity == Connectivity.OK:
|
||||
|
|
Loading…
Reference in New Issue