[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: db_auto_cleanup.py
File is not writable. Editing disabled.
""" Automatically cleanups Incidents from db, if they're contains in db more that config.IncidentLogging.NUM_DAYS """ from datetime import timedelta from logging import getLogger from humanize import naturaldelta from defence360agent.contracts.plugins import MessageSink from defence360agent.model.simplification import (remove_old_and_truncate, run_in_executor) from defence360agent.utils import recurring_check from im360.contracts import config as im360config from im360.model.firewall import IPList from im360.model.incident import Incident logger = getLogger(__name__) class DbCleanup(MessageSink): GRAYLIST_EXPIRED_KEEP_NUM_DAYS = 3 GRAYLIST_CLEANUP_EXPIRED_PERIOD = int(timedelta(hours=1).total_seconds()) AUTO_WHITELIST_CHECK_DELAY = int(timedelta(hours=1).total_seconds()) async def create_sink(self, loop): self._loop = loop self._taskpool = ( self._loop.create_task(self._recurring_incidents_cleanup()), self._loop.create_task(self._recurring_whitelist_delete_expired()), self._loop.create_task(self._recurring_graylist_cleanup()) ) async def shutdown(self): for task in self._taskpool: task.cancel() await task @recurring_check(im360config.IncidentLogging.FREQUENCY) async def _recurring_incidents_cleanup(self): await self._events_cleanup(Incident, im360config.IncidentLogging.NUM_DAYS, im360config.IncidentLogging.LIMIT) async def _events_cleanup(self, table, num_days, limit): items_deleted = await run_in_executor( self._loop, lambda: remove_old_and_truncate( table=table, num_days=num_days, max_count=limit ) ) logger.info("Deleted %s records from table '%s' during auto cleanup", items_deleted, table._meta.table_name) @recurring_check(AUTO_WHITELIST_CHECK_DELAY) async def _recurring_whitelist_delete_expired(self): await self._whitelist_delete_expired() async def _whitelist_delete_expired(self): deleted = await run_in_executor( self._loop, lambda: IPList.delete_expired(IPList.WHITE)) logger.info('Deleted %s expired records from whitelist', deleted) @recurring_check(GRAYLIST_CLEANUP_EXPIRED_PERIOD) async def _recurring_graylist_cleanup(self): await self._bglist_cleanup() async def _bglist_cleanup(self): items_deleted = await run_in_executor( self._loop, lambda: IPList.cleanup_expired_from_bglist( num_days=self.GRAYLIST_EXPIRED_KEEP_NUM_DAYS) ) logger.info("Deleted %s expired graylisted/blacklisted IPs " "(older than %s) during auto cleanup", items_deleted, naturaldelta(timedelta( days=self.GRAYLIST_EXPIRED_KEEP_NUM_DAYS)))
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server05.hostinghome.co.in
Server IP: 192.168.74.40
PHP Version: 7.4.33
Server Software: Apache
System: Linux server05.hostinghome.co.in 3.10.0-962.3.2.lve1.5.81.el7.x86_64 #1 SMP Wed May 31 10:36:47 UTC 2023 x86_64
HDD Total: 1.95 TB
HDD Free: 691.14 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Disabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: itsweb
User ID (UID): 1619
Group ID (GID): 1621
Script Owner UID: 1619
Current Dir Owner: N/A