mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Ignored IPs not applied #836
This commit is contained in:
@@ -41,6 +41,39 @@ class Device_obj:
|
||||
return result[column_name] if result else None
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Removing devices from the CurrentScan DB table which the user chose to ignore by MAC or IP
|
||||
def exclude_ignored_devices(db):
|
||||
sql = db.sql # Database interface for executing queries
|
||||
|
||||
mac_condition = list_to_where('OR', 'cur_MAC', 'LIKE', get_setting_value('NEWDEV_ignored_MACs'))
|
||||
ip_condition = list_to_where('OR', 'cur_IP', 'LIKE', get_setting_value('NEWDEV_ignored_IPs'))
|
||||
|
||||
# Only delete if either the MAC or IP matches an ignored condition
|
||||
conditions = []
|
||||
if mac_condition:
|
||||
conditions.append(mac_condition)
|
||||
if ip_condition:
|
||||
conditions.append(ip_condition)
|
||||
|
||||
# Join conditions and prepare the query
|
||||
conditions_str = " OR ".join(conditions)
|
||||
if conditions_str:
|
||||
query = f"""DELETE FROM CurrentScan WHERE
|
||||
1=1
|
||||
AND (
|
||||
{conditions_str}
|
||||
)
|
||||
"""
|
||||
else:
|
||||
query = "DELETE FROM CurrentScan WHERE 1=1 AND 1=0" # No valid conditions, prevent deletion
|
||||
|
||||
mylog('debug', f'[New Devices] Excluding Ignored Devices Query: {query}')
|
||||
|
||||
sql.execute(query)
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def save_scanned_devices (db):
|
||||
sql = db.sql #TO-DO
|
||||
@@ -145,13 +178,11 @@ def create_new_devices (db):
|
||||
SELECT cur_MAC, cur_IP, '{startTime}', 'New Device', cur_Vendor, 1
|
||||
FROM CurrentScan
|
||||
WHERE NOT EXISTS (SELECT 1 FROM Devices
|
||||
WHERE dev_MAC = cur_MAC)
|
||||
{list_to_where('OR', 'cur_MAC', 'NOT LIKE', get_setting_value('NEWDEV_ignored_MACs'))}
|
||||
{list_to_where('OR', 'cur_IP', 'NOT LIKE', get_setting_value('NEWDEV_ignored_IPs'))}
|
||||
WHERE dev_MAC = cur_MAC)
|
||||
"""
|
||||
|
||||
|
||||
mylog('debug',f'[New Devices] Query: {query}')
|
||||
mylog('debug',f'[New Devices] Log Events Query: {query}')
|
||||
|
||||
sql.execute(query)
|
||||
|
||||
@@ -163,27 +194,25 @@ def create_new_devices (db):
|
||||
FROM CurrentScan
|
||||
WHERE NOT EXISTS (SELECT 1 FROM Sessions
|
||||
WHERE ses_MAC = cur_MAC)
|
||||
{list_to_where('OR', 'cur_MAC', 'NOT LIKE', get_setting_value('NEWDEV_ignored_MACs'))}
|
||||
{list_to_where('OR', 'cur_IP', 'NOT LIKE', get_setting_value('NEWDEV_ignored_IPs'))}
|
||||
""")
|
||||
|
||||
# Create new devices from CurrentScan
|
||||
mylog('debug','[New Devices] 2 Create devices')
|
||||
|
||||
# default New Device values preparation
|
||||
newDevColumns = """dev_AlertEvents,
|
||||
dev_AlertDeviceDown,
|
||||
dev_PresentLastScan,
|
||||
dev_Archived,
|
||||
dev_NewDevice,
|
||||
dev_SkipRepeated,
|
||||
dev_ScanCycle,
|
||||
dev_Owner,
|
||||
dev_Favorite,
|
||||
dev_Group,
|
||||
dev_Comments,
|
||||
dev_LogEvents,
|
||||
dev_Location"""
|
||||
newDevColumns = """dev_AlertEvents,
|
||||
dev_AlertDeviceDown,
|
||||
dev_PresentLastScan,
|
||||
dev_Archived,
|
||||
dev_NewDevice,
|
||||
dev_SkipRepeated,
|
||||
dev_ScanCycle,
|
||||
dev_Owner,
|
||||
dev_Favorite,
|
||||
dev_Group,
|
||||
dev_Comments,
|
||||
dev_LogEvents,
|
||||
dev_Location"""
|
||||
|
||||
newDevDefaults = f"""{get_setting_value('NEWDEV_dev_AlertEvents')},
|
||||
{get_setting_value('NEWDEV_dev_AlertDeviceDown')},
|
||||
@@ -199,8 +228,13 @@ def create_new_devices (db):
|
||||
{get_setting_value('NEWDEV_dev_LogEvents')},
|
||||
'{sanitize_SQL_input(get_setting_value('NEWDEV_dev_Location'))}'"""
|
||||
|
||||
# Fetch data from CurrentScan
|
||||
current_scan_data = sql.execute("SELECT cur_MAC, cur_Name, cur_Vendor, cur_IP, cur_SyncHubNodeName, cur_NetworkNodeMAC, cur_PORT, cur_NetworkSite, cur_SSID, cur_Type FROM CurrentScan").fetchall()
|
||||
# Fetch data from CurrentScan skipping ignored devices by IP and MAC
|
||||
query = f"""SELECT cur_MAC, cur_Name, cur_Vendor, cur_IP, cur_SyncHubNodeName, cur_NetworkNodeMAC, cur_PORT, cur_NetworkSite, cur_SSID, cur_Type
|
||||
FROM CurrentScan """
|
||||
|
||||
|
||||
mylog('debug',f'[New Devices] Collecting New Devices Query: {query}')
|
||||
current_scan_data = sql.execute(query).fetchall()
|
||||
|
||||
for row in current_scan_data:
|
||||
cur_MAC, cur_Name, cur_Vendor, cur_IP, cur_SyncHubNodeName, cur_NetworkNodeMAC, cur_PORT, cur_NetworkSite, cur_SSID, cur_Type = row
|
||||
|
||||
Reference in New Issue
Block a user