mirror of https://github.com/jumpserver/jumpserver
				
				
				
			perf: dashboard
							parent
							
								
									96dc7db027
								
							
						
					
					
						commit
						a911b50df0
					
				|  | @ -4,7 +4,10 @@ from django.db.models import Count, F, Q | |||
| from django.http.response import JsonResponse | ||||
| from rest_framework.views import APIView | ||||
| 
 | ||||
| from accounts.models import Account, RiskChoice | ||||
| from accounts.models import ( | ||||
|     Account, RiskChoice, GatherAccountsAutomation, | ||||
|     PushAccountAutomation, BackupAccountAutomation, AccountRisk, IntegrationApplication | ||||
| ) | ||||
| from assets.const import AllTypes | ||||
| from common.utils.timezone import local_monday | ||||
| 
 | ||||
|  | @ -85,9 +88,34 @@ class PamDashboardApi(APIView): | |||
|             data['total_long_time_change_password_accounts'] = Account.get_risks( | ||||
|                 risk_type=RiskChoice.long_time_password).count() | ||||
| 
 | ||||
|         if _all or query_params.get('total_count_type_to_accounts_amount'): | ||||
|         if _all or query_params.get('total_count_type_to_accounts'): | ||||
|             data.update({ | ||||
|                 'total_count_type_to_accounts_amount': self.get_type_to_accounts(), | ||||
|                 'total_count_type_to_accounts': self.get_type_to_accounts(), | ||||
|             }) | ||||
| 
 | ||||
|         if _all or query_params.get('total_count_gathered_account_automation'): | ||||
|             data.update({ | ||||
|                 'total_count_gathered_account_automation': GatherAccountsAutomation.objects.count() | ||||
|             }) | ||||
| 
 | ||||
|         if _all or query_params.get('total_count_push_account_automation'): | ||||
|             data.update({ | ||||
|                 'total_count_push_account_automation': PushAccountAutomation.objects.count() | ||||
|             }) | ||||
| 
 | ||||
|         if _all or query_params.get('total_count_backup_account_automation'): | ||||
|             data.update({ | ||||
|                 'total_count_backup_account_automation': BackupAccountAutomation.objects.count() | ||||
|             }) | ||||
| 
 | ||||
|         if _all or query_params.get('total_count_risk_account'): | ||||
|             data.update({ | ||||
|                 'total_count_risk_account': AccountRisk.objects.count() | ||||
|             }) | ||||
|              | ||||
|         if _all or query_params.get('total_count_integration_application'): | ||||
|             data.update({ | ||||
|                 'total_count_integration_application': IntegrationApplication.objects.count() | ||||
|             }) | ||||
| 
 | ||||
|         return JsonResponse(data, status=200) | ||||
|  |  | |||
|  | @ -117,28 +117,26 @@ class ChangeSecretDashboardApi(APIView): | |||
|         query_params = self.request.query_params | ||||
|         data = {} | ||||
| 
 | ||||
|         if query_params.get('total_count_change_secrets'): | ||||
|         _all = query_params.get('all') | ||||
| 
 | ||||
|         if _all or query_params.get('total_count_change_secrets'): | ||||
|             data['total_count_change_secrets'] = self.get_filtered_counts( | ||||
|                 self.change_secrets_queryset, 'date_updated' | ||||
|             ) | ||||
| 
 | ||||
|         if query_params.get('total_count_periodic_change_secrets'): | ||||
|         if _all or query_params.get('total_count_periodic_change_secrets'): | ||||
|             data['total_count_periodic_change_secrets'] = self.get_filtered_counts( | ||||
|                 self.change_secrets_queryset.filter(is_periodic=True), 'date_updated' | ||||
|             ) | ||||
| 
 | ||||
|         if query_params.get('total_count_change_secret_assets'): | ||||
|         if _all or query_params.get('total_count_change_secret_assets'): | ||||
|             data['total_count_change_secret_assets'] = self.get_change_secret_asset_queryset().count() | ||||
| 
 | ||||
|         if query_params.get('total_count_change_secret_status'): | ||||
|         if _all or query_params.get('total_count_change_secret_status'): | ||||
|             records = self.get_queryset_date_filter(self.change_secret_records_queryset, 'date_finished') | ||||
|             data.update(self.get_status_counts(records)) | ||||
| 
 | ||||
|         if query_params.get('total_count_change_secret_status'): | ||||
|             records = self.get_queryset_date_filter(self.change_secret_records_queryset, 'date_finished') | ||||
|             data.update(self.get_status_counts(records)) | ||||
| 
 | ||||
|         if query_params.get('daily_success_and_failure_metrics'): | ||||
|         if _all or query_params.get('daily_success_and_failure_metrics'): | ||||
|             success, failed = self.get_daily_success_and_failure_metrics() | ||||
|             data.update({ | ||||
|                 'dates_metrics_date': [date.strftime('%m-%d') for date in self.date_range_list] or ['0'], | ||||
|  | @ -146,17 +144,18 @@ class ChangeSecretDashboardApi(APIView): | |||
|                 'dates_metrics_total_count_failed': failed, | ||||
|             }) | ||||
| 
 | ||||
|         if query_params.get('total_count_ongoing_change_secret'): | ||||
|         if _all or query_params.get('total_count_ongoing_change_secret'): | ||||
|             execution_ids = [] | ||||
|             inspect = app.control.inspect() | ||||
|             active_tasks = inspect.active() | ||||
|             for tasks in active_tasks.values(): | ||||
|                 for task in tasks: | ||||
|                     _id = task.get('id') | ||||
|                     name = task.get('name') | ||||
|                     tp = task.kwargs.get('tp') | ||||
|                     if name == self.task_name and tp == self.tp: | ||||
|                         execution_ids.append(_id) | ||||
|             if active_tasks: | ||||
|                 for tasks in active_tasks.values(): | ||||
|                     for task in tasks: | ||||
|                         _id = task.get('id') | ||||
|                         name = task.get('name') | ||||
|                         tp = task.kwargs.get('tp') | ||||
|                         if name == self.task_name and tp == self.tp: | ||||
|                             execution_ids.append(_id) | ||||
| 
 | ||||
|             snapshots = self.change_secret_executions_queryset.filter( | ||||
|                 id__in=execution_ids).values_list('id', 'snapshot') | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 feng
						feng