From dffca5e6193e4f74c0071557dabd8e871e13a906 Mon Sep 17 00:00:00 2001 From: leiweibau <105860611+leiweibau@users.noreply.github.com> Date: Wed, 3 Aug 2022 18:48:12 +0200 Subject: [PATCH] Add "cleanup" parameter - a section for future automated cleanup tasks. - add cleanup to the .cron file - add cleaning "Online_History" exept the last 1 day --- back/pialert.py | 24 +++++++++++++++++++++++- install/pialert.cron | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/back/pialert.py b/back/pialert.py index 6bc99bb3..ace836d0 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -71,13 +71,15 @@ def main (): # Check parameters if len(sys.argv) != 2 : - print ('usage pialert [scan_cycle] | internet_IP | update_vendors' ) + print ('usage pialert [scan_cycle] | internet_IP | update_vendors | cleanup' ) return cycle = str(sys.argv[1]) ## Main Commands if cycle == 'internet_IP': res = check_internet_IP() + elif cycle == 'cleanup': + res = cleanup_database() elif cycle == 'update_vendors': res = update_devices_MAC_vendors() elif cycle == 'update_vendors_silent': @@ -253,6 +255,26 @@ def check_IP_format (pIP): return IP.group(0) +#=============================================================================== +# INTERNET IP CHANGE +#=============================================================================== +def cleanup_database (): + # Header + print ('Cleanup Database') + print (' Timestamp:', startTime ) + + openDB() + + # Cleanup Online History + print ('\nCleanup Online_History') + sql.execute ("""DELETE FROM Online_History WHERE Scan_Date <= date('now', '-1 day')""") + + closeDB() + + # OK + return 0 + + #=============================================================================== # UPDATE DEVICE MAC VENDORS #=============================================================================== diff --git a/install/pialert.cron b/install/pialert.cron index 379fe93f..3a333f00 100644 --- a/install/pialert.cron +++ b/install/pialert.cron @@ -11,3 +11,4 @@ */3 * * * * python ~/pialert/back/pialert.py internet_IP >~/pialert/log/pialert.IP.log 2>&1 */5 * * * * python ~/pialert/back/pialert.py 1 >~/pialert/log/pialert.1.log 2>&1 #*/15 * * * * python ~/pialert/back/pialert.py 15 >~/pialert/log/pialert.15.log 2>&1 +0 3 * * 1 python ~/pialert/back/pialert.py cleanup >~/pialert/log/pialert.1.log 2>&1 \ No newline at end of file