mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-12 05:01:27 -07:00
PLG: Centralize SQL condition to skip forced-online devices in event inserts
This commit is contained in:
@@ -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
|
||||
) """)
|
||||
|
||||
Reference in New Issue
Block a user