From c80dc9c36a9787ffe28f9f2ee2c0212b0484f9fa Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Fri, 10 Apr 2026 22:13:09 +0000 Subject: [PATCH] PLG: Centralize SQL condition to skip forced-online devices in event inserts --- server/scan/session_events.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/scan/session_events.py b/server/scan/session_events.py index 3d1d5181..f39e791f 100755 --- a/server/scan/session_events.py +++ b/server/scan/session_events.py @@ -20,6 +20,10 @@ from messaging.reporting import skip_repeated_notifications from messaging.in_app import update_unread_notifications_count from const import NULL_EQUIVALENTS_SQL +# Predicate used in every negative-event INSERT to skip forced-online devices. +# Centralised here so all three event paths stay in sync. +_SQL_NOT_FORCED_ONLINE = "LOWER(COALESCE(devForceStatus, '')) != 'online'" + # Make sure log level is initialized correctly Logger(get_setting_value("LOG_LEVEL")) @@ -179,7 +183,7 @@ def insert_events(db): WHERE devAlertDown != 0 AND devCanSleep = 0 AND devPresentLastScan = 1 - AND LOWER(COALESCE(devForceStatus, '')) != 'online' + AND {_SQL_NOT_FORCED_ONLINE} AND NOT EXISTS (SELECT 1 FROM CurrentScan WHERE devMac = scanMac ) """) @@ -195,7 +199,7 @@ def insert_events(db): AND devCanSleep = 1 AND devIsSleeping = 0 AND devPresentLastScan = 0 - AND LOWER(COALESCE(devForceStatus, '')) != 'online' + AND {_SQL_NOT_FORCED_ONLINE} AND NOT EXISTS (SELECT 1 FROM CurrentScan WHERE devMac = scanMac) AND NOT EXISTS (SELECT 1 FROM Events @@ -231,7 +235,7 @@ def insert_events(db): FROM Devices WHERE devAlertDown = 0 AND devPresentLastScan = 1 - AND LOWER(COALESCE(devForceStatus, '')) != 'online' + AND {_SQL_NOT_FORCED_ONLINE} AND NOT EXISTS (SELECT 1 FROM CurrentScan WHERE devMac = scanMac ) """)