mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-14 14:11:26 -07:00
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
Some checks failed
🐳 ⚠ docker-unsafe from next_release branch / docker_dev_unsafe (push) Has been cancelled
This commit is contained in:
@@ -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)}")
|
||||
|
||||
Reference in New Issue
Block a user