mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
NEWDEV MAC filter #539 🆕
This commit is contained in:
@@ -3,7 +3,7 @@ import subprocess
|
||||
|
||||
import conf
|
||||
import re
|
||||
from helper import timeNowTZ, get_setting, get_setting_value,resolve_device_name_dig, resolve_device_name_pholus, get_device_name_nslookup, check_IP_format
|
||||
from helper import timeNowTZ, get_setting, get_setting_value, list_to_where, resolve_device_name_dig, resolve_device_name_pholus, get_device_name_nslookup, check_IP_format
|
||||
from logger import mylog, print_log
|
||||
from const import vendorsPath
|
||||
|
||||
@@ -126,21 +126,32 @@ def create_new_devices (db):
|
||||
|
||||
# Insert events for new devices from CurrentScan
|
||||
mylog('debug','[New Devices] New devices - 1 Events')
|
||||
sql.execute (f"""INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime,
|
||||
|
||||
query = f"""INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime,
|
||||
eve_EventType, eve_AdditionalInfo,
|
||||
eve_PendingAlertEmail)
|
||||
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) """ )
|
||||
WHERE dev_MAC = cur_MAC)
|
||||
{list_to_where('OR', 'cur_MAC', 'NOT LIKE', get_setting_value('NEWDEV_ignored_MACs'))}
|
||||
"""
|
||||
|
||||
mylog('debug','[New Devices] Insert Connection into session table')
|
||||
|
||||
mylog('debug',f'[New Devices] Query: {query}')
|
||||
|
||||
sql.execute(query)
|
||||
|
||||
mylog('debug',f'[New Devices] Insert Connection into session table')
|
||||
|
||||
sql.execute (f"""INSERT INTO Sessions (ses_MAC, ses_IP, ses_EventTypeConnection, ses_DateTimeConnection,
|
||||
ses_EventTypeDisconnection, ses_DateTimeDisconnection, ses_StillConnected, ses_AdditionalInfo)
|
||||
SELECT cur_MAC, cur_IP,'Connected','{startTime}', NULL , NULL ,1, cur_Vendor
|
||||
FROM CurrentScan
|
||||
WHERE NOT EXISTS (SELECT 1 FROM Sessions
|
||||
WHERE ses_MAC = cur_MAC) """)
|
||||
WHERE ses_MAC = cur_MAC)
|
||||
{list_to_where('OR', 'cur_MAC', 'NOT LIKE', get_setting_value('NEWDEV_ignored_MACs'))}
|
||||
""")
|
||||
|
||||
# Create new devices from CurrentScan
|
||||
mylog('debug','[New Devices] 2 Create devices')
|
||||
@@ -189,7 +200,10 @@ def create_new_devices (db):
|
||||
ELSE '(unknown)' END,
|
||||
cur_Vendor, cur_IP, ?, ?,
|
||||
{newDevDefaults}
|
||||
FROM CurrentScan"""
|
||||
FROM CurrentScan
|
||||
WHERE 1=1
|
||||
{list_to_where('OR', 'cur_MAC', 'NOT LIKE', get_setting_value('NEWDEV_ignored_MACs'))}
|
||||
"""
|
||||
|
||||
|
||||
mylog('debug',f'[New Devices] Create devices SQL: {sqlQuery}')
|
||||
|
||||
Reference in New Issue
Block a user