mirror of https://github.com/jumpserver/jumpserver
parent
574639d5e1
commit
ab76745a9f
|
@ -118,9 +118,14 @@ class DateTimeMixin:
|
||||||
return self.get_logs_queryset_filter(qs, 'date_start')
|
return self.get_logs_queryset_filter(qs, 'date_start')
|
||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
def command_queryset(self):
|
def command_type_queryset_tuple(self):
|
||||||
qs = Command.objects.all()
|
type_queryset_tuple = Command.get_all_type_queryset_tuple()
|
||||||
return self.get_logs_queryset_filter(qs, 'timestamp', is_timestamp=True)
|
return (
|
||||||
|
(tp, self.get_logs_queryset_filter(
|
||||||
|
qs, 'timestamp', is_timestamp=True
|
||||||
|
))
|
||||||
|
for tp, qs in type_queryset_tuple
|
||||||
|
)
|
||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
def job_logs_queryset(self):
|
def job_logs_queryset(self):
|
||||||
|
@ -131,7 +136,7 @@ class DateTimeMixin:
|
||||||
class DatesLoginMetricMixin:
|
class DatesLoginMetricMixin:
|
||||||
dates_list: list
|
dates_list: list
|
||||||
date_start_end: tuple
|
date_start_end: tuple
|
||||||
command_queryset: Command.objects
|
command_type_queryset_tuple: tuple
|
||||||
sessions_queryset: Session.objects
|
sessions_queryset: Session.objects
|
||||||
ftp_logs_queryset: FTPLog.objects
|
ftp_logs_queryset: FTPLog.objects
|
||||||
job_logs_queryset: JobLog.objects
|
job_logs_queryset: JobLog.objects
|
||||||
|
@ -229,13 +234,29 @@ class DatesLoginMetricMixin:
|
||||||
def change_password_logs_amount(self):
|
def change_password_logs_amount(self):
|
||||||
return self.password_change_logs_queryset.count()
|
return self.password_change_logs_queryset.count()
|
||||||
|
|
||||||
|
@lazyproperty
|
||||||
|
def command_statistics(self):
|
||||||
|
from terminal.const import CommandStorageType
|
||||||
|
total_amount = 0
|
||||||
|
danger_amount = 0
|
||||||
|
for tp, qs in self.command_type_queryset_tuple:
|
||||||
|
if tp == CommandStorageType.es:
|
||||||
|
total_amount += qs.count(limit_to_max_result_window=False)
|
||||||
|
danger_amount += qs.filter(risk_level=RiskLevelChoices.reject).count(limit_to_max_result_window=False)
|
||||||
|
else:
|
||||||
|
total_amount += qs.count()
|
||||||
|
danger_amount += qs.filter(risk_level=RiskLevelChoices.reject).count()
|
||||||
|
return total_amount, danger_amount
|
||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
def commands_amount(self):
|
def commands_amount(self):
|
||||||
return self.command_queryset.count()
|
total_amount, _ = self.command_statistics
|
||||||
|
return total_amount
|
||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
def commands_danger_amount(self):
|
def commands_danger_amount(self):
|
||||||
return self.command_queryset.filter(risk_level=RiskLevelChoices.reject).count()
|
_, danger_amount = self.command_statistics
|
||||||
|
return danger_amount
|
||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
def job_logs_running_amount(self):
|
def job_logs_running_amount(self):
|
||||||
|
|
|
@ -60,6 +60,16 @@ class Command(AbstractSessionCommand):
|
||||||
commands.append(command)
|
commands.append(command)
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_all_type_queryset_tuple():
|
||||||
|
from terminal.models import CommandStorage
|
||||||
|
storage_qs = CommandStorage.objects.exclude(name='null')
|
||||||
|
return (
|
||||||
|
(storage.type, storage.get_command_queryset())
|
||||||
|
for storage in storage_qs
|
||||||
|
if storage.is_valid()
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "terminal_command"
|
db_table = "terminal_command"
|
||||||
ordering = ('-timestamp',)
|
ordering = ('-timestamp',)
|
||||||
|
|
Loading…
Reference in New Issue