From 742cf01e86c8311a41c2cee4639bdd7fe636c21c Mon Sep 17 00:00:00 2001 From: Stefan Midjich Date: Thu, 16 Nov 2017 21:10:25 +0100 Subject: [PATCH] try to do a purge as well for old clients with no traffic. --- tools/manage_client.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/manage_client.py b/tools/manage_client.py index e05e4fb..8618ad7 100644 --- a/tools/manage_client.py +++ b/tools/manage_client.py @@ -107,6 +107,8 @@ if args.refresh: timeout=600 ) + current_date = datetime.now() + for _line in proc.stdout.splitlines(): # Convert from bytestring first line = _line.decode('utf-8') @@ -142,10 +144,17 @@ if args.refresh: client.commit() if int(packets_val) != client.last_packets: - client.last_activity = datetime.now() + client.last_activity = current_date client.last_packets = packets_val client.commit() + # Also do a purge of clients that have no traffic for 24 hrs + if client.last_activity: + time_diff = client.last_activity-client.created + if client.last_packets >= packets_val and time_diff.days >= 1: + client.enabled = False + client.commit() + for src_ip in args.src_ip: # Get client by IP or create a new one. client = Client(