diff --git a/apps/accounts/api/account/pam_dashboard.py b/apps/accounts/api/account/pam_dashboard.py index fec642961..b857b56ee 100644 --- a/apps/accounts/api/account/pam_dashboard.py +++ b/apps/accounts/api/account/pam_dashboard.py @@ -4,6 +4,7 @@ from django.http.response import JsonResponse from rest_framework.views import APIView from accounts.models import Account, RiskChoice +from common.utils.timezone import local_monday __all__ = ['PamDashboardApi'] @@ -24,6 +25,10 @@ class PamDashboardApi(APIView): if query_params.get('total_accounts'): data['total_accounts'] = account_count + if query_params.get('total_week_add_accounts'): + monday_time = local_monday() + data['total_week_add_accounts'] = Account.objects.filter(date_created__gte=monday_time).count() + if query_params.get('total_privileged_accounts'): data['total_privileged_accounts'] = privileged_account_count @@ -31,15 +36,18 @@ class PamDashboardApi(APIView): data['total_ordinary_accounts'] = account_count - privileged_account_count if query_params.get('total_unmanaged_accounts'): - data['total_unmanaged_accounts'] = Account.get_risks(RiskChoice.new_found).count() + data['total_unmanaged_accounts'] = Account.get_risks(risk_type=RiskChoice.new_found).count() if query_params.get('total_unavailable_accounts'): data['total_unavailable_accounts'] = Account.objects.filter(is_active=False).count() + if query_params.get('total_long_time_no_login_accounts'): + data['total_long_time_no_login_accounts'] = Account.get_risks(risk_type=RiskChoice.long_time_no_login).count() + if query_params.get('total_weak_password_accounts'): - data['total_weak_password_accounts'] = Account.get_risks(RiskChoice.weak_password) + data['total_weak_password_accounts'] = Account.get_risks(risk_type=RiskChoice.weak_password).count() if query_params.get('total_long_time_change_password_accounts'): - data['total_long_time_change_password_accounts'] = Account.get_risks(RiskChoice.long_time_password) + data['total_long_time_change_password_accounts'] = Account.get_risks(risk_type=RiskChoice.long_time_password).count() return JsonResponse(data, status=200) diff --git a/apps/accounts/models/account.py b/apps/accounts/models/account.py index 0fe19a20a..f7c759625 100644 --- a/apps/accounts/models/account.py +++ b/apps/accounts/models/account.py @@ -168,6 +168,7 @@ class Account(AbsConnectivity, LabeledMixin, BaseAccount): @classmethod def get_risks(cls, queryset=None, risk_type=None): + # TODO 数据量大时,子查询性能不佳,考虑用原生sql或者在模型层面做出改动 from accounts.models import AccountRisk subquery = AccountRisk.objects.filter( asset_id=OuterRef('asset_id'),