diff --git a/apps/accounts/automations/verify_account/manager.py b/apps/accounts/automations/verify_account/manager.py index 4135d742a..1cb44e5e1 100644 --- a/apps/accounts/automations/verify_account/manager.py +++ b/apps/accounts/automations/verify_account/manager.py @@ -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') diff --git a/apps/assets/automations/ping/manager.py b/apps/assets/automations/ping/manager.py index 6249a40c7..2641d8b6c 100644 --- a/apps/assets/automations/ping/manager.py +++ b/apps/assets/automations/ping/manager.py @@ -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') diff --git a/apps/assets/const/automation.py b/apps/assets/const/automation.py index e70387cfe..2bd3d2334 100644 --- a/apps/assets/const/automation.py +++ b/apps/assets/const/automation.py @@ -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): diff --git a/apps/assets/models/base.py b/apps/assets/models/base.py index 031335b72..670ddfe34 100644 --- a/apps/assets/models/base.py +++ b/apps/assets/models/base.py @@ -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: