Delete audit logs when they exceed 100 entries

This commit is contained in:
Andrew 2022-01-29 01:36:37 -05:00
parent 8232a630ee
commit 7889ca3153

View File

@ -191,6 +191,14 @@ class helpers_management:
Audit_Log.log_msg: audit_msg,
Audit_Log.source_ip: source_ip
}).execute()
#todo make this user configurable
#deletes records when they're more than 100
ordered = Audit_Log.select().order_by(+Audit_Log.created)
for item in ordered:
if Audit_Log.select().count() > 100:
Audit_Log.delete().where(Audit_Log.audit_id == item.audit_id).execute()
else:
return
@staticmethod
def add_to_audit_log_raw(user_name, user_id, server_id, log_msg, source_ip):
@ -201,7 +209,13 @@ class helpers_management:
Audit_Log.log_msg: log_msg,
Audit_Log.source_ip: source_ip
}).execute()
#deletes records when they're more than 100
ordered = Audit_Log.select().order_by(+Audit_Log.created)
for item in ordered:
if Audit_Log.select().count() > 100:
Audit_Log.delete().where(Audit_Log.audit_id == item.audit_id).execute()
else:
return
#************************************************************************************************
# Schedules Methods
#************************************************************************************************