PLG: Implement selective recording for Plugins_History to prevent unbounded growth
Some checks failed
🐳 ⚠ docker-unsafe from next_release branch / docker_dev_unsafe (push) Has been cancelled

This commit is contained in:
Jokob @NetAlertX
2026-04-12 23:09:34 +00:00
parent b0c687a171
commit 8abecb7a0d
3 changed files with 424 additions and 2 deletions

View File

@@ -786,6 +786,10 @@ def process_plugin_events(db, plugin, plugEventsArr):
pluginEvents[index].status = "watched-not-changed"
index += 1
# Track objects whose state actually changed this cycle
# (only these will be recorded in Plugins_History)
changed_this_cycle = set()
# Loop thru events and check if previously available objects are missing
for tmpObj in pluginObjects:
isMissing = True
@@ -799,6 +803,7 @@ def process_plugin_events(db, plugin, plugEventsArr):
if tmpObj.status != "missing-in-last-scan":
tmpObj.changed = timeNowUTC()
tmpObj.status = "missing-in-last-scan"
changed_this_cycle.add(tmpObj.idsHash)
# mylog('debug', [f'[Plugins] Missing from last scan (PrimaryID | SecondaryID): {tmpObj.primaryId} | {tmpObj.secondaryId}'])
# Merge existing plugin objects with newly discovered ones and update existing ones with new values
@@ -807,10 +812,14 @@ def process_plugin_events(db, plugin, plugEventsArr):
if tmpObjFromEvent.status == "not-processed":
# This is a new object as it was not discovered as "exists" previously
tmpObjFromEvent.status = "new"
changed_this_cycle.add(tmpObjFromEvent.idsHash)
pluginObjects.append(tmpObjFromEvent)
# update data of existing objects
else:
if tmpObjFromEvent.status == "watched-changed":
changed_this_cycle.add(tmpObjFromEvent.idsHash)
index = 0
for plugObj in pluginObjects:
# find corresponding object for the event and merge
@@ -871,8 +880,9 @@ def process_plugin_events(db, plugin, plugEventsArr):
if plugObj.status in statuses_to_report_on:
events_to_insert.append(values)
# combine all DB insert and update events into one for history
history_to_insert.append(values)
# Only record history for objects that actually changed this cycle
if plugObj.idsHash in changed_this_cycle:
history_to_insert.append(values)
mylog("debug", f"[Plugins] pluginEvents count: {len(pluginEvents)}")
mylog("debug", f"[Plugins] pluginObjects count: {len(pluginObjects)}")