mirror of https://github.com/jumpserver/jumpserver
perf: 修改备份
parent
b87fb8bba0
commit
4872dacc58
|
@ -153,7 +153,7 @@ class AccountBackupHandler:
|
|||
wb.close()
|
||||
files.append(filename)
|
||||
timedelta = round((time.time() - time_start), 2)
|
||||
time_cost = _('Time cost')
|
||||
time_cost = _('Duration')
|
||||
file_created = _('Backup file creation completed')
|
||||
print('{}: {} {}s'.format(file_created, time_cost, timedelta))
|
||||
return files
|
||||
|
@ -292,7 +292,7 @@ class AccountBackupHandler:
|
|||
def run(self):
|
||||
plan_start = _('Plan start')
|
||||
plan_end = _('Plan end')
|
||||
time_cost = _('Time cost')
|
||||
time_cost = _('Duration')
|
||||
error = _('An exception occurred during task execution')
|
||||
print('{}: {}'.format(plan_start, local_now_display()))
|
||||
time_start = time.time()
|
||||
|
|
|
@ -32,5 +32,5 @@ class AccountBackupManager(BaseManager):
|
|||
print('\n\n' + '-' * 80)
|
||||
plan_execution_end = _('Plan execution end')
|
||||
print('{} {}\n'.format(plan_execution_end, local_now_display()))
|
||||
time_cost = _('Time cost')
|
||||
time_cost = _('Duration')
|
||||
print('{}: {}s'.format(time_cost, self.duration))
|
||||
|
|
|
@ -224,7 +224,7 @@ class ChangeSecretManager(AccountBasePlaybookManager):
|
|||
print('\n\n' + '-' * 80)
|
||||
plan_execution_end = _('Plan execution end')
|
||||
print('{} {}\n'.format(plan_execution_end, local_now_filename()))
|
||||
time_cost = _('Time cost')
|
||||
time_cost = _('Duration')
|
||||
print('{}: {}s'.format(time_cost, self.duration))
|
||||
print(summary)
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class GatherAccountsFilter:
|
|||
if not line.strip() or ' ' not in line:
|
||||
continue
|
||||
username, login = line.split(' ', 1)
|
||||
user_last_login[username] = login
|
||||
user_last_login[username] = login.split()
|
||||
|
||||
user_authorized = info.pop('user_authorized', [])
|
||||
username_authorized = {}
|
||||
|
@ -78,9 +78,9 @@ class GatherAccountsFilter:
|
|||
|
||||
login = user_last_login.get(username) or ''
|
||||
if login and len(login) == 3:
|
||||
user['address_last_login'] = login[1][:32]
|
||||
user['address_last_login'] = login[0][:32]
|
||||
try:
|
||||
login_date = timezone.datetime.fromisoformat(login[2])
|
||||
login_date = timezone.datetime.fromisoformat(login[1])
|
||||
user['date_last_login'] = login_date
|
||||
except ValueError:
|
||||
pass
|
||||
|
|
|
@ -5,7 +5,6 @@ from django.utils import timezone
|
|||
|
||||
from accounts.const import AutomationTypes
|
||||
from accounts.models import GatheredAccount, Account, AccountRisk
|
||||
from assets.models import Asset
|
||||
from common.const import ConfirmOrIgnore
|
||||
from common.decorators import bulk_create_decorator, bulk_update_decorator
|
||||
from common.utils import get_logger
|
||||
|
@ -13,17 +12,22 @@ from common.utils.strings import get_text_diff
|
|||
from orgs.utils import tmp_to_org
|
||||
from .filter import GatherAccountsFilter
|
||||
from ..base.manager import AccountBasePlaybookManager
|
||||
from ...notifications import GatherAccountChangeMsg
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
diff_items = [
|
||||
risk_items = [
|
||||
"authorized_keys",
|
||||
"sudoers",
|
||||
"groups",
|
||||
]
|
||||
|
||||
diff_items = risk_items + [
|
||||
"address_last_login",
|
||||
"date_last_login",
|
||||
"date_password_change",
|
||||
"date_password_expired",
|
||||
]
|
||||
|
||||
|
||||
def get_items_diff(ori_account, d):
|
||||
if hasattr(ori_account, "_diff"):
|
||||
|
@ -34,14 +38,16 @@ def get_items_diff(ori_account, d):
|
|||
ori = getattr(ori_account, item)
|
||||
new = d.get(item, "")
|
||||
|
||||
if not ori:
|
||||
if not ori and not new:
|
||||
continue
|
||||
|
||||
if isinstance(new, timezone.datetime):
|
||||
new = ori.strftime("%Y-%m-%d %H:%M:%S")
|
||||
if isinstance(ori, timezone.datetime):
|
||||
ori = ori.strftime("%Y-%m-%d %H:%M:%S")
|
||||
if isinstance(new, timezone.datetime):
|
||||
new = new.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
if new != ori:
|
||||
diff[item] = get_text_diff(ori, new)
|
||||
diff[item] = get_text_diff(str(ori), str(new))
|
||||
|
||||
ori_account._diff = diff
|
||||
return diff
|
||||
|
@ -70,12 +76,13 @@ class AnalyseAccountRisk:
|
|||
|
||||
def _analyse_item_changed(self, ori_account, d):
|
||||
diff = get_items_diff(ori_account, d)
|
||||
|
||||
if not diff:
|
||||
return
|
||||
|
||||
risks = []
|
||||
for k, v in diff.items():
|
||||
if k not in risk_items:
|
||||
continue
|
||||
risks.append(
|
||||
dict(
|
||||
asset=ori_account.asset,
|
||||
|
@ -191,7 +198,7 @@ class GatherAccountsManager(AccountBasePlaybookManager):
|
|||
result = self._filter_success_result(asset.type, info)
|
||||
accounts = []
|
||||
for username, info in result.items():
|
||||
self.asset_usernames_mapper[asset].add(username)
|
||||
self.asset_usernames_mapper[str(asset.id)].add(username)
|
||||
|
||||
d = {"asset": asset, "username": username, "remote_present": True, **info}
|
||||
accounts.append(d)
|
||||
|
@ -217,14 +224,14 @@ class GatherAccountsManager(AccountBasePlaybookManager):
|
|||
"asset", "username"
|
||||
)
|
||||
|
||||
for asset, username in accounts:
|
||||
self.ori_asset_usernames[asset].add(username)
|
||||
for asset_id, username in accounts:
|
||||
self.ori_asset_usernames[str(asset_id)].add(username)
|
||||
|
||||
ga_accounts = GatheredAccount.objects.filter(asset__in=assets).prefetch_related(
|
||||
"asset"
|
||||
)
|
||||
for account in ga_accounts:
|
||||
self.ori_gathered_usernames[account.asset].add(account.username)
|
||||
self.ori_gathered_usernames[str(account.asset_id)].add(account.username)
|
||||
key = "{}_{}".format(account.asset_id, account.username)
|
||||
self.ori_gathered_accounts_mapper[key] = account
|
||||
|
||||
|
@ -235,9 +242,9 @@ class GatherAccountsManager(AccountBasePlaybookManager):
|
|||
|
||||
远端账号 -> 收集账号 -> 特权账号
|
||||
"""
|
||||
remote_users = self.asset_usernames_mapper[asset]
|
||||
ori_users = self.ori_asset_usernames[asset]
|
||||
ori_ga_users = self.ori_gathered_usernames[asset]
|
||||
remote_users = self.asset_usernames_mapper[str(asset.id)]
|
||||
ori_users = self.ori_asset_usernames[str(asset.id)]
|
||||
ori_ga_users = self.ori_gathered_usernames[str(asset.id)]
|
||||
|
||||
queryset = GatheredAccount.objects.filter(asset=asset).exclude(
|
||||
status=ConfirmOrIgnore.ignored
|
||||
|
@ -305,8 +312,11 @@ class GatherAccountsManager(AccountBasePlaybookManager):
|
|||
# 资产上没有的,标识为为存在
|
||||
(
|
||||
queryset.exclude(username__in=ori_users)
|
||||
.filter(present=False)
|
||||
.update(present=True)
|
||||
.filter(present=True)
|
||||
.update(present=False)
|
||||
)
|
||||
queryset.filter(username__in=ori_users).filter(present=False).update(
|
||||
present=True
|
||||
)
|
||||
|
||||
@bulk_create_decorator(GatheredAccount)
|
||||
|
|
|
@ -38,7 +38,7 @@ msgstr ""
|
|||
#: accounts/automations/backup_account/handlers.py:295
|
||||
#: accounts/automations/backup_account/manager.py:40 ops/serializers/job.py:76
|
||||
#: settings/templates/ldap/_msg_import_ldap_user.html:7
|
||||
msgid "Time cost"
|
||||
msgid "Duration"
|
||||
msgstr ""
|
||||
|
||||
#: accounts/automations/backup_account/handlers.py:157
|
||||
|
|
|
@ -38,7 +38,7 @@ msgstr "アセットまたはアプリケーション関連のバックアップ
|
|||
#: accounts/automations/backup_account/handlers.py:295
|
||||
#: accounts/automations/backup_account/manager.py:40 ops/serializers/job.py:76
|
||||
#: settings/templates/ldap/_msg_import_ldap_user.html:7
|
||||
msgid "Time cost"
|
||||
msgid "Duration"
|
||||
msgstr "時を過ごす"
|
||||
|
||||
#: accounts/automations/backup_account/handlers.py:157
|
||||
|
|
|
@ -37,7 +37,7 @@ msgstr "生成资产或应用相关备份信息文件"
|
|||
#: accounts/automations/backup_account/handlers.py:295
|
||||
#: accounts/automations/backup_account/manager.py:40 ops/serializers/job.py:76
|
||||
#: settings/templates/ldap/_msg_import_ldap_user.html:7
|
||||
msgid "Time cost"
|
||||
msgid "Duration"
|
||||
msgstr "花费时间"
|
||||
|
||||
#: accounts/automations/backup_account/handlers.py:157
|
||||
|
|
|
@ -39,7 +39,7 @@ msgstr "生成與資產或應用程序相關的備份信息文件"
|
|||
#: accounts/automations/backup_account/handlers.py:295
|
||||
#: accounts/automations/backup_account/manager.py:40 ops/serializers/job.py:76
|
||||
#: settings/templates/ldap/_msg_import_ldap_user.html:7
|
||||
msgid "Time cost"
|
||||
msgid "Duration"
|
||||
msgstr "花費時間"
|
||||
|
||||
#: accounts/automations/backup_account/handlers.py:157
|
||||
|
|
|
@ -1249,7 +1249,7 @@
|
|||
"TicketFlowUpdate": "Update the approval flow",
|
||||
"Tickets": "Tickets",
|
||||
"Time": "Time",
|
||||
"TimeDelta": "Time cost",
|
||||
"TimeDelta": "Duration",
|
||||
"TimeExpression": "Time expression",
|
||||
"Timeout": "Timeout",
|
||||
"TimeoutHelpText": "When this value is -1, no timeout is specified.",
|
||||
|
|
|
@ -73,7 +73,7 @@ class JobExecutionSerializer(BulkOrgResourceModelSerializer):
|
|||
material = serializers.ReadOnlyField(label=_("Command"))
|
||||
is_success = serializers.ReadOnlyField(label=_("Is success"))
|
||||
is_finished = serializers.ReadOnlyField(label=_("Is finished"))
|
||||
time_cost = serializers.ReadOnlyField(label=_("Time cost"))
|
||||
time_cost = serializers.ReadOnlyField(label=_("Duration"))
|
||||
|
||||
class Meta:
|
||||
model = JobExecution
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<ul>
|
||||
<li>{% trans 'Date start' %}: {{ start_time }}</li>
|
||||
<li>{% trans 'Date end' %}: {{ end_time }}</li>
|
||||
<li>{% trans 'Time cost' %}: {{ cost_time| floatformat:0 }}s</li>
|
||||
<li>{% trans 'Duration' %}: {{ cost_time| floatformat:0 }}s</li>
|
||||
</ul>
|
||||
<b>{% trans "Synced Organization" %}:</b>
|
||||
<ul>
|
||||
|
|
Loading…
Reference in New Issue