Development
This commit is contained in:
parent
b38c199baf
commit
fd7cc5c11d
9 changed files with 55 additions and 24 deletions
|
|
@ -8,7 +8,7 @@ Called by:
|
|||
- maintenance.py on each timer tick
|
||||
- routlin-dash overview page on each page load (background thread)
|
||||
|
||||
Only VLANs with dnsmasq_log_queries=true are collected.
|
||||
Only VLANs with dnsmasq_log_queries_days > 0 are collected.
|
||||
"""
|
||||
|
||||
import json
|
||||
|
|
@ -84,7 +84,7 @@ def collect(data):
|
|||
"""
|
||||
unit_to_vlan = {}
|
||||
for vlan in data.get('vlans', []):
|
||||
if not vlan.get('dnsmasq_log_queries'):
|
||||
if not vlan.get('dnsmasq_log_queries_days', 0):
|
||||
continue
|
||||
iface = validation.derive_interface(vlan, data)
|
||||
svc = shared.vlan_service_name(vlan, iface)
|
||||
|
|
@ -180,3 +180,26 @@ def collect(data):
|
|||
shared.chown_to_script_dir_owner(DB_FILE)
|
||||
con.close()
|
||||
return len(rows)
|
||||
|
||||
|
||||
def prune(data):
|
||||
"""
|
||||
Delete dns_queries rows older than the retention period configured per VLAN.
|
||||
Uses the maximum retention days across all logging-enabled VLANs.
|
||||
Returns the number of rows deleted.
|
||||
"""
|
||||
days = max(
|
||||
(v.get('dnsmasq_log_queries_days', 0) for v in data.get('vlans', [])),
|
||||
default=0
|
||||
)
|
||||
if not days:
|
||||
return 0
|
||||
if not DB_FILE.exists():
|
||||
return 0
|
||||
cutoff = int(__import__('time').time()) - days * 86400
|
||||
con = open_db()
|
||||
cur = con.execute('DELETE FROM dns_queries WHERE ts < ?', (cutoff,))
|
||||
deleted = cur.rowcount
|
||||
con.commit()
|
||||
con.close()
|
||||
return deleted
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue