コード例 #1
0
 def refresh_if_need(cls, instance):
     cache_field_name = cls.model_cache_field_mapper.get(type(instance))
     if cache_field_name:
         org_cache = OrgResourceStatisticsCache(instance.org)
         org_cache.expire(*cache_field_name)
         OrgResourceStatisticsCache(
             Organization.root()).expire(*cache_field_name)
コード例 #2
0
def refresh_user_amount_on_user_create_or_delete(user_id):
    orgs = Organization.objects.filter(
        m2m_org_members__user_id=user_id).distinct()
    for org in orgs:
        org_cache = OrgResourceStatisticsCache(org)
        org_cache.expire('users_amount')
    OrgResourceStatisticsCache(Organization.root()).expire('users_amount')
コード例 #3
0
def _refresh_session_org_resource_statistics_cache(instance: Session):
    cache_field_name = [
        'total_count_online_users', 'total_count_online_sessions'
    ]

    org_cache = OrgResourceStatisticsCache(instance.org)
    org_cache.expire(*cache_field_name)
    OrgResourceStatisticsCache(Organization.root()).expire(*cache_field_name)
コード例 #4
0
 def refresh_if_need(cls, instance):
     cache_field_name = cls.model_cache_field_mapper.get(type(instance))
     if not cache_field_name:
         return
     OrgResourceStatisticsCache(
         Organization.root()).expire(*cache_field_name)
     if instance.org:
         OrgResourceStatisticsCache(instance.org).expire(*cache_field_name)
コード例 #5
0
ファイル: cache.py プロジェクト: zaijiejud/jumpserver
def on_org_user_changed_refresh_cache(sender, action, instance, reverse, pk_set, **kwargs):
    if not action.startswith(POST_PREFIX):
        return

    if reverse:
        orgs = Organization.objects.filter(id__in=pk_set)
    else:
        orgs = [instance]

    for org in orgs:
        org_cache = OrgResourceStatisticsCache(org)
        org_cache.expire('users_amount')
コード例 #6
0
def refresh_cache(name, org):
    names = None
    if isinstance(name, (str, )):
        names = [
            name,
        ]
    if isinstance(names, (list, tuple)):
        for name in names:
            OrgResourceStatisticsCache(org).expire(name)
            OrgResourceStatisticsCache(Organization.root()).expire(name)
    else:
        logger.warning('refresh cache fail: {}'.format(name))
コード例 #7
0
ファイル: api.py プロジェクト: winning1120xx/jumpserver
    def get(self, request, *args, **kwargs):
        data = {}

        query_params = self.request.query_params

        caches = OrgResourceStatisticsCache(current_org)

        _all = query_params.get('all')

        if _all or query_params.get('total_count') or query_params.get(
                'total_count_users'):
            data.update({
                'total_count_users': caches.users_amount,
            })

        if _all or query_params.get('total_count') or query_params.get(
                'total_count_assets'):
            data.update({
                'total_count_assets': caches.assets_amount,
            })

        if _all or query_params.get('total_count') or query_params.get(
                'total_count_online_users'):
            data.update({
                'total_count_online_users':
                caches.total_count_online_users,
            })

        if _all or query_params.get('total_count') or query_params.get(
                'total_count_online_sessions'):
            data.update({
                'total_count_online_sessions':
                caches.total_count_online_sessions,
            })

        if _all or query_params.get('dates_metrics'):
            data.update({
                'dates_metrics_date':
                self.get_dates_metrics_date(),
                'dates_metrics_total_count_login':
                self.get_dates_metrics_total_count_login(),
                'dates_metrics_total_count_active_users':
                self.get_dates_metrics_total_count_active_users(),
                'dates_metrics_total_count_active_assets':
                self.get_dates_metrics_total_count_active_assets(),
            })

        if _all or query_params.get('dates_total_count_users'):
            data.update({
                'dates_total_count_active_users':
                self.dates_total_count_active_users,
                'dates_total_count_inactive_users':
                self.dates_total_count_inactive_users,
                'dates_total_count_disabled_users':
                self.dates_total_count_disabled_users,
            })

        if _all or query_params.get('dates_total_count_assets'):
            data.update({
                'dates_total_count_active_assets':
                self.dates_total_count_active_assets,
                'dates_total_count_inactive_assets':
                self.dates_total_count_inactive_assets,
                'dates_total_count_disabled_assets':
                self.dates_total_count_disabled_assets,
            })

        if _all or query_params.get('dates_total_count'):
            data.update({
                'dates_total_count_login_users':
                self.get_dates_total_count_login_users(),
                'dates_total_count_login_times':
                self.get_dates_total_count_login_times(),
            })

        if _all or query_params.get('dates_login_times_top5_users'):
            data.update({
                'dates_login_times_top5_users':
                self.get_dates_login_times_top5_users(),
            })

        if _all or query_params.get('dates_login_times_top10_assets'):
            data.update({
                'dates_login_times_top10_assets':
                self.get_dates_login_times_top10_assets(),
            })

        if _all or query_params.get('dates_login_times_top10_users'):
            data.update({
                'dates_login_times_top10_users':
                self.get_dates_login_times_top10_users(),
            })

        if _all or query_params.get('dates_login_record_top10_sessions'):
            data.update({
                'dates_login_record_top10_sessions':
                self.get_dates_login_record_top10_sessions()
            })

        return JsonResponse(data, status=200)
コード例 #8
0
def expire_org_resource_statistics_cache():
    orgs = Organization.objects.all()
    for org in orgs:
        cache = OrgResourceStatisticsCache(org)
        cache.expire()