diff --git a/server/plugin.py b/server/plugin.py index 12cea5d7..492f1371 100755 --- a/server/plugin.py +++ b/server/plugin.py @@ -817,13 +817,15 @@ def process_plugin_events(db, plugin, plugEventsArr): 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 if plugObj.idsHash == tmpObjFromEvent.idsHash: + if ( + plugObj.status == "missing-in-last-scan" + or tmpObjFromEvent.status == "watched-changed" + ): + changed_this_cycle.add(tmpObjFromEvent.idsHash) pluginObjects[index] = combine_plugin_objects( plugObj, tmpObjFromEvent ) diff --git a/test/server/test_plugin_history_filtering.py b/test/server/test_plugin_history_filtering.py index d155c70f..d69456ba 100644 --- a/test/server/test_plugin_history_filtering.py +++ b/test/server/test_plugin_history_filtering.py @@ -211,3 +211,26 @@ class TestHistoryOnlyRecordsChanges: objs = plugin_objects_rows(conn, PREFIX) assert len(objs) == 1, "Plugins_Objects should still have the object" + + def test_recovery_from_missing_recorded(self, plugin_db, monkeypatch): + """An object that was missing-in-last-scan and reappears (even with + unchanged watched values) should produce a history row.""" + db, conn = plugin_db + monkeypatch.setattr("plugin.get_setting_value", _no_report_on) + + cur = conn.cursor() + seed_plugin_object(cur, PREFIX, "device_A", watched1="val1", + status="missing-in-last-scan") + conn.commit() + + plugin = make_plugin_dict(PREFIX) + # device_A reappears with the same watched value + events = [make_plugin_event_row(PREFIX, "device_A", watched1="val1")] + + process_plugin_events(db, plugin, events) + + rows = plugin_history_rows(conn, PREFIX) + assert len(rows) == 1, ( + "recovery from missing-in-last-scan should generate a history row" + ) + assert rows[0][2] == "device_A"