perf: 日志保存时间不少于6个月 (#11742)

Co-authored-by: feng <1304903146@qq.com>
pull/11748/head
fit2bot 2023-10-07 17:41:45 +08:00 committed by GitHub
parent 60399fae29
commit 68707085fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 6 deletions

View File

@ -124,6 +124,8 @@ TASK_LOG_KEEP_DAYS = CONFIG.TASK_LOG_KEEP_DAYS
OPERATE_LOG_KEEP_DAYS = CONFIG.OPERATE_LOG_KEEP_DAYS
ACTIVITY_LOG_KEEP_DAYS = CONFIG.ACTIVITY_LOG_KEEP_DAYS
FTP_LOG_KEEP_DAYS = CONFIG.FTP_LOG_KEEP_DAYS
CLOUD_SYNC_TASK_EXECUTION_KEEP_DAYS = CONFIG.CLOUD_SYNC_TASK_EXECUTION_KEEP_DAYS
ORG_CHANGE_TO_URL = CONFIG.ORG_CHANGE_TO_URL
WINDOWS_SKIP_ALL_MANUAL_PASSWORD = CONFIG.WINDOWS_SKIP_ALL_MANUAL_PASSWORD
@ -159,8 +161,6 @@ SECURITY_SESSION_SHARE = CONFIG.SECURITY_SESSION_SHARE
LOGIN_REDIRECT_TO_BACKEND = CONFIG.LOGIN_REDIRECT_TO_BACKEND
LOGIN_REDIRECT_MSG_ENABLED = CONFIG.LOGIN_REDIRECT_MSG_ENABLED
CLOUD_SYNC_TASK_EXECUTION_KEEP_DAYS = CONFIG.CLOUD_SYNC_TASK_EXECUTION_KEEP_DAYS
TERMINAL_RAZOR_ENABLED = CONFIG.TERMINAL_RAZOR_ENABLED
TERMINAL_OMNIDB_ENABLED = CONFIG.TERMINAL_OMNIDB_ENABLED
TERMINAL_MAGNUS_ENABLED = CONFIG.TERMINAL_MAGNUS_ENABLED
@ -204,3 +204,14 @@ MAX_LIMIT_PER_PAGE = CONFIG.MAX_LIMIT_PER_PAGE
# Magnus DB Port
MAGNUS_ORACLE_PORTS = CONFIG.MAGNUS_ORACLE_PORTS
LIMIT_SUPER_PRIV = CONFIG.LIMIT_SUPER_PRIV
LOG_NAMES = [
'LOGIN_LOG_KEEP_DAYS', 'TASK_LOG_KEEP_DAYS',
'OPERATE_LOG_KEEP_DAYS', 'FTP_LOG_KEEP_DAYS',
'CLOUD_SYNC_TASK_EXECUTION_KEEP_DAYS',
'ACTIVITY_LOG_KEEP_DAYS', 'TERMINAL_SESSION_KEEP_DURATION'
]
if LIMIT_SUPER_PRIV:
for name in LOG_NAMES:
if globals()[name] < 180:
globals()[name] = 180

View File

@ -1,5 +1,7 @@
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
from rest_framework.serializers import ValidationError
__all__ = ['CleaningSerializer']
@ -27,12 +29,27 @@ class CleaningSerializer(serializers.Serializer):
min_value=1, max_value=9999,
label=_("Cloud sync record keep days (day)"),
)
ACTIVITY_LOG_KEEP_DAYS = serializers.IntegerField(
min_value=1, max_value=9999,
label=_("Activity log keep days (day)"),
)
TERMINAL_SESSION_KEEP_DURATION = serializers.IntegerField(
min_value=1, max_value=99999, required=True, label=_('Session keep duration (day)'),
help_text=_(
'Session, record, command will be delete if more than duration, only in database, OSS will not be affected.')
)
ACTIVITY_LOG_KEEP_DAYS = serializers.IntegerField(
min_value=1, max_value=9999,
label=_("Activity log keep days (day)"),
)
MIN_DAYS_THRESHOLD = 180
def validate(self, attrs):
attrs = super().validate(attrs)
if not settings.LIMIT_SUPER_PRIV:
return attrs
error_names = [
name for name in settings.LOG_NAMES
if attrs.get(name, 0) < self.MIN_DAYS_THRESHOLD
]
if error_names:
error_message = _('must be greater than {} days.').format(self.MIN_DAYS_THRESHOLD)
raise ValidationError({name: error_message for name in error_names})
return attrs