mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
refactor redundant joins, bugfix event insert
This commit is contained in:
@@ -549,7 +549,8 @@ class DB():
|
|||||||
cur_SSID STRING(250),
|
cur_SSID STRING(250),
|
||||||
cur_NetworkNodeMAC STRING(250),
|
cur_NetworkNodeMAC STRING(250),
|
||||||
cur_PORT STRING(250),
|
cur_PORT STRING(250),
|
||||||
cur_Type STRING(250)
|
cur_Type STRING(250),
|
||||||
|
UNIQUE(cur_MAC)
|
||||||
);
|
);
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|||||||
@@ -93,10 +93,7 @@ def save_scanned_devices (db):
|
|||||||
|
|
||||||
# Proceed if variable contains valid MAC
|
# Proceed if variable contains valid MAC
|
||||||
if check_mac_or_internet(local_mac):
|
if check_mac_or_internet(local_mac):
|
||||||
# Check if local mac has been detected with other methods
|
sql.execute (f"""INSERT OR IGNORE INTO CurrentScan (cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod) VALUES ( '{local_mac}', '{local_ip}', Null, 'local_MAC') """)
|
||||||
sql.execute (f"SELECT COUNT(*) FROM CurrentScan WHERE cur_MAC = '{local_mac}'")
|
|
||||||
if sql.fetchone()[0] == 0 :
|
|
||||||
sql.execute (f"""INSERT INTO CurrentScan (cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod) VALUES ( '{local_mac}', '{local_ip}', Null, 'local_MAC') """)
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def print_scan_stats(db):
|
def print_scan_stats(db):
|
||||||
|
|||||||
@@ -207,9 +207,8 @@ def insert_events (db):
|
|||||||
'',
|
'',
|
||||||
1
|
1
|
||||||
FROM CurrentScan AS c
|
FROM CurrentScan AS c
|
||||||
LEFT JOIN LatestEventsPerMAC AS d ON d.dev_MAC = c.cur_MAC
|
LEFT JOIN LatestEventsPerMAC AS last_event ON c.cur_MAC = last_event.eve_MAC
|
||||||
LEFT JOIN LatestEventsPerMAC AS last_event ON d.dev_MAC = last_event.eve_MAC
|
WHERE last_event.dev_PresentLastScan = 0 OR last_event.eve_MAC IS NULL
|
||||||
WHERE d.dev_PresentLastScan = 0 OR d.dev_MAC IS NULL
|
|
||||||
""")
|
""")
|
||||||
|
|
||||||
# Check disconnections
|
# Check disconnections
|
||||||
|
|||||||
@@ -747,7 +747,7 @@ def process_plugin_events(db, plugin, pluginsState, plugEventsArr):
|
|||||||
sqlParams.append(tuple(tmpList))
|
sqlParams.append(tuple(tmpList))
|
||||||
|
|
||||||
# Generate the SQL INSERT query using the collected information.
|
# Generate the SQL INSERT query using the collected information.
|
||||||
q = f'INSERT into {dbTable} ({columnsStr}) VALUES ({valuesStr})'
|
q = f'INSERT OR IGNORE INTO {dbTable} ({columnsStr}) VALUES ({valuesStr})'
|
||||||
|
|
||||||
# Log a debug message showing the generated SQL query for mapping.
|
# Log a debug message showing the generated SQL query for mapping.
|
||||||
mylog('debug', ['[Plugins] SQL query for mapping: ', q])
|
mylog('debug', ['[Plugins] SQL query for mapping: ', q])
|
||||||
|
|||||||
Reference in New Issue
Block a user