From d24411fa53ed9e2851c7050c1f4721db2f007d06 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sun, 25 Jan 2026 16:38:45 +1100 Subject: [PATCH] BE: CurrentScan table leanup - column rename Signed-off-by: jokob-sk --- back/app.sql | 34 ++-- docs/DEBUG_PLUGINS.md | 2 +- docs/PLUGINS_DEV.md | 4 +- docs/PLUGINS_DEV_UI_COMPONENTS.md | 14 +- front/css/app.css | 2 +- front/plugins/__template/config.json | 12 +- front/plugins/__template/rename_me.py | 4 +- front/plugins/adguard_import/config.json | 10 +- front/plugins/arp_scan/config.json | 8 +- front/plugins/asuswrt_import/config.json | 10 +- front/plugins/dhcp_leases/config.json | 10 +- front/plugins/freebox/config.json | 12 +- front/plugins/icmp_scan/config.json | 8 +- front/plugins/internet_ip/config.json | 10 +- front/plugins/ipneigh/config.json | 12 +- front/plugins/luci_import/config.json | 6 +- front/plugins/mikrotik_scan/config.json | 8 +- front/plugins/nmap_dev_scan/config.json | 12 +- front/plugins/omada_sdn_imp/config.json | 16 +- front/plugins/omada_sdn_imp/omada_sdn.py | 4 +- front/plugins/omada_sdn_openapi/config.json | 18 +- front/plugins/pihole_api_scan/config.json | 10 +- front/plugins/pihole_scan/config.json | 12 +- front/plugins/snmp_discovery/config.json | 10 +- front/plugins/sync/config.json | 12 +- front/plugins/unifi_api_import/config.json | 12 +- front/plugins/unifi_import/config.json | 18 +- front/plugins/vendor_update/config.json | 12 +- .../entrypoint.d/25-first-run-db.sh | 32 ++-- scripts/db_cleanup/db_cleanup.py | 8 +- scripts/db_cleanup/regenerate-database.sh | 124 ++++++------- server/db/db_upgrade.py | 36 ++-- server/scan/device_handling.py | 170 +++++++++--------- server/scan/session_events.py | 22 +-- .../test_field_lock_scan_integration.py | 96 +++++----- .../test_ip_format_and_locking.py | 68 +++---- .../test_ip_update_logic.py | 42 ++--- 37 files changed, 450 insertions(+), 450 deletions(-) diff --git a/back/app.sql b/back/app.sql index 3cee67d4..ce49d3fc 100755 --- a/back/app.sql +++ b/back/app.sql @@ -150,21 +150,21 @@ CREATE TABLE Plugins_Language_Strings( PRIMARY KEY("Index" AUTOINCREMENT) ); CREATE TABLE CurrentScan ( - cur_MAC STRING(50) NOT NULL COLLATE NOCASE, - cur_IP STRING(50) NOT NULL COLLATE NOCASE, - cur_Vendor STRING(250), - cur_ScanMethod STRING(10), - cur_Name STRING(250), - cur_LastQuery STRING(250), - cur_DateTime STRING(250), - cur_SyncHubNodeName STRING(50), - cur_NetworkSite STRING(250), - cur_SSID STRING(250), - cur_devVlan STRING(250), - cur_NetworkNodeMAC STRING(250), - cur_PORT STRING(250), - cur_Type STRING(250), - UNIQUE(cur_MAC) + scanMac STRING(50) NOT NULL COLLATE NOCASE, + scanLastIP STRING(50) NOT NULL COLLATE NOCASE, + scanVendor STRING(250), + scanSourcePlugin STRING(10), + scanName STRING(250), + scanLastQuery STRING(250), + scanLastConnection STRING(250), + scanSyncHubNode STRING(50), + scanSite STRING(250), + scanSSID STRING(250), + scanVlan STRING(250), + scanParentMAC STRING(250), + scanParentPort STRING(250), + scanType STRING(250), + UNIQUE(scanMac) ); CREATE TABLE IF NOT EXISTS "AppEvents" ( "Index" INTEGER PRIMARY KEY AUTOINCREMENT, @@ -237,9 +237,9 @@ CREATE VIEW LatestEventsPerMAC AS c.* FROM RankedEvents AS e LEFT JOIN Devices AS d ON e.eve_MAC = d.devMac - INNER JOIN CurrentScan AS c ON e.eve_MAC = c.cur_MAC + INNER JOIN CurrentScan AS c ON e.eve_MAC = c.scanMac WHERE e.row_num = 1 -/* LatestEventsPerMAC(eve_MAC,eve_IP,eve_DateTime,eve_EventType,eve_AdditionalInfo,eve_PendingAlertEmail,eve_PairEventRowid,row_num,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps,cur_MAC,cur_IP,cur_Vendor,cur_ScanMethod,cur_Name,cur_LastQuery,cur_DateTime,cur_SyncHubNodeName,cur_NetworkSite,cur_SSID,cur_NetworkNodeMAC,cur_PORT,cur_Type) */; +/* LatestEventsPerMAC(eve_MAC,eve_IP,eve_DateTime,eve_EventType,eve_AdditionalInfo,eve_PendingAlertEmail,eve_PairEventRowid,row_num,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps,scanMac,scanLastIP,scanVendor,scanSourcePlugin,scanName,scanLastQuery,scanLastConnection,scanSyncHubNode,scanSite,scanSSID,scanParentMAC,scanParentPort,scanType) */; CREATE VIEW Sessions_Devices AS SELECT * FROM Sessions LEFT JOIN "Devices" ON ses_MAC = devMac /* Sessions_Devices(ses_MAC,ses_IP,ses_EventTypeConnection,ses_DateTimeConnection,ses_EventTypeDisconnection,ses_DateTimeDisconnection,ses_StillConnected,ses_AdditionalInfo,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps) */; CREATE VIEW Convert_Events_to_Sessions AS SELECT EVE1.eve_MAC, diff --git a/docs/DEBUG_PLUGINS.md b/docs/DEBUG_PLUGINS.md index 96af4cb0..cd134841 100755 --- a/docs/DEBUG_PLUGINS.md +++ b/docs/DEBUG_PLUGINS.md @@ -54,7 +54,7 @@ Input data from the plugin might cause mapping issues in specific edge cases. Lo 17:31:05 [Plugin utils] In pluginObjects there are 2 events with the status "missing-in-last-scan" 17:31:05 [Plugin utils] In pluginObjects there are 2 events with the status "watched-not-changed" 17:31:05 [Plugins] Mapping objects to database table: CurrentScan -17:31:05 [Plugins] SQL query for mapping: INSERT into CurrentScan ( "cur_MAC", "cur_IP", "cur_LastQuery", "cur_Name", "cur_Vendor", "cur_ScanMethod") VALUES ( ?, ?, ?, ?, ?, ?) +17:31:05 [Plugins] SQL query for mapping: INSERT into CurrentScan ( "scanMac", "scanLastIP", "scanLastQuery", "scanName", "scanVendor", "scanSourcePlugin") VALUES ( ?, ?, ?, ?, ?, ?) 17:31:05 [Plugins] SQL sqlParams for mapping: [('01:01:01:01:01:01', '172.30.0.1', 0, 'aaaa', 'vvvvvvvvv', 'PIHOLE'), ('02:42:ac:1e:00:02', '172.30.0.2', 0, 'dddd', 'vvvvv2222', 'PIHOLE')] 🔺 17:31:05 [API] Update API starting diff --git a/docs/PLUGINS_DEV.md b/docs/PLUGINS_DEV.md index 3fbd8bff..5176131f 100755 --- a/docs/PLUGINS_DEV.md +++ b/docs/PLUGINS_DEV.md @@ -268,7 +268,7 @@ To import plugin data into NetAlertX tables for device discovery or notification "database_column_definitions": [ { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "show": true, "type": "device_mac", "localized": ["name"], @@ -287,7 +287,7 @@ To always map a static value (not read from plugin output): ```json { "column": "NameDoesntMatter", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "MYPLN" } diff --git a/docs/PLUGINS_DEV_UI_COMPONENTS.md b/docs/PLUGINS_DEV_UI_COMPONENTS.md index 5f8ebb11..776bd40e 100644 --- a/docs/PLUGINS_DEV_UI_COMPONENTS.md +++ b/docs/PLUGINS_DEV_UI_COMPONENTS.md @@ -440,7 +440,7 @@ To import plugin data into the device scan pipeline (for notifications, heuristi "database_column_definitions": [ { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "show": true, "type": "device_mac", "localized": ["name"], @@ -448,7 +448,7 @@ To import plugin data into the device scan pipeline (for notifications, heuristi }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "show": true, "type": "device_ip", "localized": ["name"], @@ -456,7 +456,7 @@ To import plugin data into the device scan pipeline (for notifications, heuristi }, { "column": "NameDoesntMatter", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "MYSCAN" }, @@ -478,7 +478,7 @@ Use `mapped_to_column_data` to map a static value instead of reading from a colu ```json { "column": "NameDoesntMatter", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "MYSCAN" }, @@ -489,7 +489,7 @@ Use `mapped_to_column_data` to map a static value instead of reading from a colu } ``` -This always sets `cur_ScanMethod` to `"MYSCAN"` regardless of column data. +This always sets `scanSourcePlugin` to `"MYSCAN"` regardless of column data. --- @@ -546,7 +546,7 @@ When viewing a device detail page, the `txtMacFilter` field is populated with th "database_column_definitions": [ { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-2", "show": true, "type": "device_mac", @@ -556,7 +556,7 @@ When viewing a device detail page, the `txtMacFilter` field is populated with th }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", diff --git a/front/css/app.css b/front/css/app.css index 988618ad..ecafc508 100755 --- a/front/css/app.css +++ b/front/css/app.css @@ -105,7 +105,7 @@ a[target="_blank"] { background-color: black !important; font-family: 'Courier New', monospace; font-size: .85em; - cursor: pointer; + cursor: pointer !important; } .logs-row textarea { diff --git a/front/plugins/__template/config.json b/front/plugins/__template/config.json index f2dfd28a..12617d70 100755 --- a/front/plugins/__template/config.json +++ b/front/plugins/__template/config.json @@ -419,7 +419,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -435,7 +435,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -451,7 +451,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -467,7 +467,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -483,7 +483,7 @@ }, { "column": "Watched_Value3", - "mapped_to_column": "cur_Type", + "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -514,7 +514,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "Example Plugin" }, diff --git a/front/plugins/__template/rename_me.py b/front/plugins/__template/rename_me.py index 18c2d072..b9f43e56 100755 --- a/front/plugins/__template/rename_me.py +++ b/front/plugins/__template/rename_me.py @@ -51,8 +51,8 @@ def main(): # "database_column_definitions": [ # { # "column": "Object_PrimaryID", <--------- the value I save into primaryId - # "mapped_to_column": "cur_MAC", <--------- gets inserted into the CurrentScan DB - # table column cur_MAC + # "mapped_to_column": "scanMac", <--------- gets inserted into the CurrentScan DB + # table column scanMac # for device in device_data: plugin_objects.add_object( diff --git a/front/plugins/adguard_import/config.json b/front/plugins/adguard_import/config.json index 5fb46a88..b3edf897 100644 --- a/front/plugins/adguard_import/config.json +++ b/front/plugins/adguard_import/config.json @@ -392,7 +392,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -408,7 +408,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -424,7 +424,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -440,7 +440,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Type", + "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -486,7 +486,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "Example Plugin" }, diff --git a/front/plugins/arp_scan/config.json b/front/plugins/arp_scan/config.json index 2c342e5e..98beb02e 100755 --- a/front/plugins/arp_scan/config.json +++ b/front/plugins/arp_scan/config.json @@ -500,7 +500,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -516,7 +516,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -532,7 +532,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -556,7 +556,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "ARPSCAN" }, diff --git a/front/plugins/asuswrt_import/config.json b/front/plugins/asuswrt_import/config.json index bd165e32..cbcf0271 100755 --- a/front/plugins/asuswrt_import/config.json +++ b/front/plugins/asuswrt_import/config.json @@ -451,7 +451,7 @@ "localized": [ "name" ], - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "name": [ { "language_code": "en_us", @@ -477,7 +477,7 @@ "localized": [ "name" ], - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "name": [ { "language_code": "en_us", @@ -503,7 +503,7 @@ "localized": [ "name" ], - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "name": [ { "language_code": "en_us", @@ -524,7 +524,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "default_value": "", "localized": [ @@ -550,7 +550,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "ASUSWRT" }, diff --git a/front/plugins/dhcp_leases/config.json b/front/plugins/dhcp_leases/config.json index 8735c46e..70adb612 100755 --- a/front/plugins/dhcp_leases/config.json +++ b/front/plugins/dhcp_leases/config.json @@ -103,7 +103,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-2", "show": true, "type": "device_mac", @@ -127,7 +127,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -174,7 +174,7 @@ }, { "column": "DateTimeChanged", - "mapped_to_column": "cur_DateTime", + "mapped_to_column": "scanLastConnection", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -221,7 +221,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -337,7 +337,7 @@ }, { "column": "ScanMethod", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "DHCPLSS" }, diff --git a/front/plugins/freebox/config.json b/front/plugins/freebox/config.json index bb63a858..c2164571 100755 --- a/front/plugins/freebox/config.json +++ b/front/plugins/freebox/config.json @@ -391,7 +391,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -409,7 +409,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -427,7 +427,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -445,7 +445,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -463,7 +463,7 @@ }, { "column": "Watched_Value3", - "mapped_to_column": "cur_Type", + "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -498,7 +498,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "Freebox" }, diff --git a/front/plugins/icmp_scan/config.json b/front/plugins/icmp_scan/config.json index 59692172..ee4b12fa 100755 --- a/front/plugins/icmp_scan/config.json +++ b/front/plugins/icmp_scan/config.json @@ -382,7 +382,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -400,7 +400,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -418,7 +418,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -487,7 +487,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "ICMP" }, diff --git a/front/plugins/internet_ip/config.json b/front/plugins/internet_ip/config.json index ba8ade02..446f30d1 100755 --- a/front/plugins/internet_ip/config.json +++ b/front/plugins/internet_ip/config.json @@ -494,7 +494,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -518,7 +518,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -591,7 +591,7 @@ }, { "column": "Watched_Value4", - "mapped_to_column": "cur_Type", + "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -607,7 +607,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "INTRNT" }, @@ -657,7 +657,7 @@ }, { "column": "DateTimeChanged", - "mapped_to_column": "cur_DateTime", + "mapped_to_column": "scanLastConnection", "css_classes": "col-sm-2", "show": true, "type": "label", diff --git a/front/plugins/ipneigh/config.json b/front/plugins/ipneigh/config.json index 4bc1ab50..c6b9dec9 100755 --- a/front/plugins/ipneigh/config.json +++ b/front/plugins/ipneigh/config.json @@ -287,7 +287,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -305,7 +305,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -323,7 +323,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -341,7 +341,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -359,7 +359,7 @@ }, { "column": "Watched_Value3", - "mapped_to_column": "cur_Type", + "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -394,7 +394,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "IPNEIGH" }, diff --git a/front/plugins/luci_import/config.json b/front/plugins/luci_import/config.json index 2eac488c..8b25c24d 100755 --- a/front/plugins/luci_import/config.json +++ b/front/plugins/luci_import/config.json @@ -470,7 +470,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -490,7 +490,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -549,7 +549,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "LUCIRPC" }, diff --git a/front/plugins/mikrotik_scan/config.json b/front/plugins/mikrotik_scan/config.json index 03d1832d..9d203384 100755 --- a/front/plugins/mikrotik_scan/config.json +++ b/front/plugins/mikrotik_scan/config.json @@ -351,7 +351,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -382,7 +382,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -413,7 +413,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -474,7 +474,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "MTSCAN" }, diff --git a/front/plugins/nmap_dev_scan/config.json b/front/plugins/nmap_dev_scan/config.json index 81fcf114..98baaaac 100755 --- a/front/plugins/nmap_dev_scan/config.json +++ b/front/plugins/nmap_dev_scan/config.json @@ -538,7 +538,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -556,7 +556,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -574,7 +574,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -592,7 +592,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -618,7 +618,7 @@ }, { "column": "Watched_Value3", - "mapped_to_column": "cur_LastQuery", + "mapped_to_column": "scanLastQuery", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -640,7 +640,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "NMAPDEV" }, diff --git a/front/plugins/omada_sdn_imp/config.json b/front/plugins/omada_sdn_imp/config.json index 22203782..b40e1ff6 100755 --- a/front/plugins/omada_sdn_imp/config.json +++ b/front/plugins/omada_sdn_imp/config.json @@ -554,7 +554,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -578,7 +578,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -602,7 +602,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -618,7 +618,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_NetworkNodeMAC", + "mapped_to_column": "scanParentMAC", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -634,7 +634,7 @@ }, { "column": "Watched_Value3", - "mapped_to_column": "cur_PORT", + "mapped_to_column": "scanParentPort", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -650,7 +650,7 @@ }, { "column": "Watched_Value4", - "mapped_to_column": "cur_SSID", + "mapped_to_column": "scanSSID", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -666,7 +666,7 @@ }, { "column": "Extra", - "mapped_to_column": "cur_Type", + "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -682,7 +682,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "OMDSDN" }, diff --git a/front/plugins/omada_sdn_imp/omada_sdn.py b/front/plugins/omada_sdn_imp/omada_sdn.py index 8ee3ffea..b00ce3f9 100755 --- a/front/plugins/omada_sdn_imp/omada_sdn.py +++ b/front/plugins/omada_sdn_imp/omada_sdn.py @@ -320,7 +320,7 @@ def main(): # "database_column_definitions": [ # { # "column": "Object_PrimaryID", <--------- the value I save into primaryId - # "mapped_to_column": "cur_MAC", <--------- gets unserted into the CurrentScan DB table column cur_MAC + # "mapped_to_column": "scanMac", <--------- gets unserted into the CurrentScan DB table column scanMac # watched1 = 'null' , # figure a way to run my udpate script delayed @@ -342,7 +342,7 @@ def main(): watched3=myport, # PORT watched4=myssid, # SSID extra=device[TYPE], - # omada_site, # SITENAME (cur_NetworkSite) or VENDOR (cur_Vendor) (PICK one and adjust config.json -> "column": "Extra") + # omada_site, # SITENAME (scanSite) or VENDOR (scanVendor) (PICK one and adjust config.json -> "column": "Extra") foreignKey=device[MAC].lower().replace("-", ":"), ) # usually MAC diff --git a/front/plugins/omada_sdn_openapi/config.json b/front/plugins/omada_sdn_openapi/config.json index a9df0317..8ee40dd8 100755 --- a/front/plugins/omada_sdn_openapi/config.json +++ b/front/plugins/omada_sdn_openapi/config.json @@ -528,7 +528,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -544,7 +544,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -560,7 +560,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -576,7 +576,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_NetworkNodeMAC", + "mapped_to_column": "scanParentMAC", "css_classes": "col-sm-2", "show": true, "type": "device_name_mac", @@ -592,7 +592,7 @@ }, { "column": "Watched_Value3", - "mapped_to_column": "cur_PORT", + "mapped_to_column": "scanParentPort", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -608,7 +608,7 @@ }, { "column": "Watched_Value4", - "mapped_to_column": "cur_SSID", + "mapped_to_column": "scanSSID", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -624,7 +624,7 @@ }, { "column": "Extra", - "mapped_to_column": "cur_Type", + "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -640,7 +640,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "OMDSDNOPENAPI" }, @@ -704,7 +704,7 @@ }, { "column": "HelpVal2", - "mapped_to_column": "cur_NetworkSite", + "mapped_to_column": "scanSite", "css_classes": "col-sm-2", "show": true, "type": "label", diff --git a/front/plugins/pihole_api_scan/config.json b/front/plugins/pihole_api_scan/config.json index 7af0e002..d9a708f6 100644 --- a/front/plugins/pihole_api_scan/config.json +++ b/front/plugins/pihole_api_scan/config.json @@ -428,7 +428,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -444,7 +444,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -460,7 +460,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -476,7 +476,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -522,7 +522,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "PIHOLEAPI" }, diff --git a/front/plugins/pihole_scan/config.json b/front/plugins/pihole_scan/config.json index 1fbb936b..6d96f111 100755 --- a/front/plugins/pihole_scan/config.json +++ b/front/plugins/pihole_scan/config.json @@ -385,7 +385,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-2", "show": true, "type": "device_mac", @@ -420,7 +420,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -440,7 +440,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_LastQuery", + "mapped_to_column": "scanLastQuery", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -456,7 +456,7 @@ }, { "column": "Watched_Value3", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -472,7 +472,7 @@ }, { "column": "Watched_Value4", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -488,7 +488,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "PIHOLE" }, diff --git a/front/plugins/snmp_discovery/config.json b/front/plugins/snmp_discovery/config.json index 62fc7760..5d838d89 100755 --- a/front/plugins/snmp_discovery/config.json +++ b/front/plugins/snmp_discovery/config.json @@ -100,7 +100,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-2", "show": true, "type": "device_mac", @@ -120,7 +120,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -140,7 +140,7 @@ }, { "column": "DateTimeCreated", - "mapped_to_column": "cur_DateTime", + "mapped_to_column": "scanLastConnection", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -160,7 +160,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -275,7 +275,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "SNMPDSC" }, diff --git a/front/plugins/sync/config.json b/front/plugins/sync/config.json index 9ef665fa..0298a112 100755 --- a/front/plugins/sync/config.json +++ b/front/plugins/sync/config.json @@ -684,7 +684,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -710,7 +710,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -736,7 +736,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -754,7 +754,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -772,7 +772,7 @@ }, { "column": "Watched_Value3", - "mapped_to_column": "cur_SyncHubNodeName", + "mapped_to_column": "scanSyncHubNode", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -807,7 +807,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "sync" }, diff --git a/front/plugins/unifi_api_import/config.json b/front/plugins/unifi_api_import/config.json index ab8080b4..8ee8fba7 100755 --- a/front/plugins/unifi_api_import/config.json +++ b/front/plugins/unifi_api_import/config.json @@ -587,7 +587,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -605,7 +605,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -623,7 +623,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -641,7 +641,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Type", + "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -676,7 +676,7 @@ }, { "column": "Watched_Value4", - "mapped_to_column": "cur_NetworkNodeMAC", + "mapped_to_column": "scanParentMAC", "css_classes": "col-sm-2", "show": true, "type": "device_mac", @@ -694,7 +694,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "UNIFIAPI" }, diff --git a/front/plugins/unifi_import/config.json b/front/plugins/unifi_import/config.json index 111e3521..526eed05 100755 --- a/front/plugins/unifi_import/config.json +++ b/front/plugins/unifi_import/config.json @@ -123,7 +123,7 @@ "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "name": [ { "language_code": "en_us", @@ -147,7 +147,7 @@ "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "name": [ { "language_code": "en_us", @@ -194,7 +194,7 @@ "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], - "mapped_to_column": "cur_DateTime", + "mapped_to_column": "scanLastConnection", "name": [ { "language_code": "en_us", @@ -218,7 +218,7 @@ "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "name": [ { "language_code": "en_us", @@ -239,7 +239,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -263,7 +263,7 @@ }, { "column": "Watched_Value3", - "mapped_to_column": "cur_Type", + "mapped_to_column": "scanType", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -336,7 +336,7 @@ "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "UNFIMP" }, @@ -383,7 +383,7 @@ }, { "column": "HelpVal1", - "mapped_to_column": "cur_NetworkNodeMAC", + "mapped_to_column": "scanParentMAC", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -399,7 +399,7 @@ }, { "column": "HelpVal2", - "mapped_to_column": "cur_PORT", + "mapped_to_column": "scanParentPort", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], diff --git a/front/plugins/vendor_update/config.json b/front/plugins/vendor_update/config.json index d487dab2..79f29f93 100755 --- a/front/plugins/vendor_update/config.json +++ b/front/plugins/vendor_update/config.json @@ -428,7 +428,7 @@ }, { "column": "Object_PrimaryID", - "mapped_to_column": "cur_MAC", + "mapped_to_column": "scanMac", "css_classes": "col-sm-2", "show": true, "type": "device_mac", @@ -452,7 +452,7 @@ }, { "column": "Object_SecondaryID", - "mapped_to_column": "cur_IP", + "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -499,7 +499,7 @@ }, { "column": "DateTimeChanged", - "mapped_to_column": "cur_DateTime", + "mapped_to_column": "scanLastConnection", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -523,7 +523,7 @@ }, { "column": "Dummy", - "mapped_to_column": "cur_ScanMethod", + "mapped_to_column": "scanSourcePlugin", "mapped_to_column_data": { "value": "VNDRPDT" }, @@ -550,7 +550,7 @@ }, { "column": "Watched_Value1", - "mapped_to_column": "cur_Vendor", + "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -570,7 +570,7 @@ }, { "column": "Watched_Value2", - "mapped_to_column": "cur_Name", + "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, "type": "label", diff --git a/install/production-filesystem/entrypoint.d/25-first-run-db.sh b/install/production-filesystem/entrypoint.d/25-first-run-db.sh index 2f601030..c463f308 100755 --- a/install/production-filesystem/entrypoint.d/25-first-run-db.sh +++ b/install/production-filesystem/entrypoint.d/25-first-run-db.sh @@ -196,20 +196,20 @@ CREATE TABLE Plugins_Language_Strings( PRIMARY KEY("Index" AUTOINCREMENT) ); CREATE TABLE CurrentScan ( - cur_MAC STRING(50) NOT NULL COLLATE NOCASE, - cur_IP STRING(50) NOT NULL COLLATE NOCASE, - cur_Vendor STRING(250), - cur_ScanMethod STRING(10), - cur_Name STRING(250), - cur_LastQuery STRING(250), - cur_DateTime STRING(250), - cur_SyncHubNodeName STRING(50), - cur_NetworkSite STRING(250), - cur_SSID STRING(250), - cur_NetworkNodeMAC STRING(250), - cur_PORT STRING(250), - cur_Type STRING(250), - UNIQUE(cur_MAC) + scanMac STRING(50) NOT NULL COLLATE NOCASE, + scanLastIP STRING(50) NOT NULL COLLATE NOCASE, + scanVendor STRING(250), + scanSourcePlugin STRING(10), + scanName STRING(250), + scanLastQuery STRING(250), + scanLastConnection STRING(250), + scanSyncHubNode STRING(50), + scanSite STRING(250), + scanSSID STRING(250), + scanParentMAC STRING(250), + scanParentPort STRING(250), + scanType STRING(250), + UNIQUE(scanMac) ); CREATE TABLE IF NOT EXISTS "AppEvents" ( "Index" INTEGER PRIMARY KEY AUTOINCREMENT, @@ -282,9 +282,9 @@ CREATE VIEW LatestEventsPerMAC AS c.* FROM RankedEvents AS e LEFT JOIN Devices AS d ON e.eve_MAC = d.devMac - INNER JOIN CurrentScan AS c ON e.eve_MAC = c.cur_MAC + INNER JOIN CurrentScan AS c ON e.eve_MAC = c.scanMac WHERE e.row_num = 1 -/* LatestEventsPerMAC(eve_MAC,eve_IP,eve_DateTime,eve_EventType,eve_AdditionalInfo,eve_PendingAlertEmail,eve_PairEventRowid,row_num,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps,cur_MAC,cur_IP,cur_Vendor,cur_ScanMethod,cur_Name,cur_LastQuery,cur_DateTime,cur_SyncHubNodeName,cur_NetworkSite,cur_SSID,cur_NetworkNodeMAC,cur_PORT,cur_Type) */; +/* LatestEventsPerMAC(eve_MAC,eve_IP,eve_DateTime,eve_EventType,eve_AdditionalInfo,eve_PendingAlertEmail,eve_PairEventRowid,row_num,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps,scanMac,scanLastIP,scanVendor,scanSourcePlugin,scanName,scanLastQuery,scanLastConnection,scanSyncHubNode,scanSite,scanSSID,scanParentMAC,scanParentPort,scanType) */; CREATE VIEW Sessions_Devices AS SELECT * FROM Sessions LEFT JOIN "Devices" ON ses_MAC = devMac /* Sessions_Devices(ses_MAC,ses_IP,ses_EventTypeConnection,ses_DateTimeConnection,ses_EventTypeDisconnection,ses_DateTimeDisconnection,ses_StillConnected,ses_AdditionalInfo,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps) */; CREATE VIEW Convert_Events_to_Sessions AS SELECT EVE1.eve_MAC, diff --git a/scripts/db_cleanup/db_cleanup.py b/scripts/db_cleanup/db_cleanup.py index 9fabf0e5..e55ee5e6 100755 --- a/scripts/db_cleanup/db_cleanup.py +++ b/scripts/db_cleanup/db_cleanup.py @@ -36,7 +36,7 @@ def check_and_clean_device(): tables_checks = [ f"SELECT 'Events' as source, * FROM Events WHERE eve_MAC='{mac}'", f"SELECT 'Devices' as source, * FROM Devices WHERE dev_MAC='{mac}'", - f"SELECT 'CurrentScan' as source, * FROM CurrentScan WHERE cur_MAC='{mac}'", + f"SELECT 'CurrentScan' as source, * FROM CurrentScan WHERE scanMac='{mac}'", f"SELECT 'Notifications' as source, * FROM Notifications WHERE JSON LIKE '%{mac}%'", f"SELECT 'AppEvents' as source, * FROM AppEvents WHERE ObjectPrimaryID LIKE '%{mac}%' OR ObjectSecondaryID LIKE '%{mac}%'", f"SELECT 'Plugins_Objects' as source, * FROM Plugins_Objects WHERE Object_PrimaryID LIKE '%{mac}%'" @@ -56,7 +56,7 @@ def check_and_clean_device(): deletes = [ f"DELETE FROM Events WHERE eve_MAC='{mac}'", f"DELETE FROM Devices WHERE dev_MAC='{mac}'", - f"DELETE FROM CurrentScan WHERE cur_MAC='{mac}'", + f"DELETE FROM CurrentScan WHERE scanMac='{mac}'", f"DELETE FROM Notifications WHERE JSON LIKE '%{mac}%'", f"DELETE FROM AppEvents WHERE ObjectPrimaryID LIKE '%{mac}%' OR ObjectSecondaryID LIKE '%{mac}%'", f"DELETE FROM Plugins_Objects WHERE Object_PrimaryID LIKE '%{mac}%'" @@ -75,7 +75,7 @@ def check_and_clean_device(): tables_checks = [ f"SELECT 'Events' as source, * FROM Events WHERE eve_IP='{ip}'", f"SELECT 'Devices' as source, * FROM Devices WHERE dev_LastIP='{ip}'", - f"SELECT 'CurrentScan' as source, * FROM CurrentScan WHERE cur_IP='{ip}'", + f"SELECT 'CurrentScan' as source, * FROM CurrentScan WHERE scanLastIP='{ip}'", f"SELECT 'Notifications' as source, * FROM Notifications WHERE JSON LIKE '%{ip}%'", f"SELECT 'AppEvents' as source, * FROM AppEvents WHERE ObjectSecondaryID LIKE '%{ip}%'", f"SELECT 'Plugins_Objects' as source, * FROM Plugins_Objects WHERE Object_SecondaryID LIKE '%{ip}%'" @@ -95,7 +95,7 @@ def check_and_clean_device(): deletes = [ f"DELETE FROM Events WHERE eve_IP='{ip}'", f"DELETE FROM Devices WHERE dev_LastIP='{ip}'", - f"DELETE FROM CurrentScan WHERE cur_IP='{ip}'", + f"DELETE FROM CurrentScan WHERE scanLastIP='{ip}'", f"DELETE FROM Notifications WHERE JSON LIKE '%{ip}%'", f"DELETE FROM AppEvents WHERE ObjectSecondaryID LIKE '%{ip}%'", f"DELETE FROM Plugins_Objects WHERE Object_SecondaryID LIKE '%{ip}%'" diff --git a/scripts/db_cleanup/regenerate-database.sh b/scripts/db_cleanup/regenerate-database.sh index b690148c..fffed972 100755 --- a/scripts/db_cleanup/regenerate-database.sh +++ b/scripts/db_cleanup/regenerate-database.sh @@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS "Parameters" ( ); CREATE TABLE Plugins_Objects( "Index" INTEGER, - Plugin TEXT NOT NULL, + Plugin TEXT NOT NULL, Object_PrimaryID TEXT NOT NULL, Object_SecondaryID TEXT NOT NULL, DateTimeCreated TEXT NOT NULL, @@ -143,21 +143,21 @@ CREATE TABLE Plugins_Language_Strings( Extra TEXT NOT NULL, PRIMARY KEY("Index" AUTOINCREMENT) ); -CREATE TABLE CurrentScan ( - cur_MAC STRING(50) NOT NULL COLLATE NOCASE, - cur_IP STRING(50) NOT NULL COLLATE NOCASE, - cur_Vendor STRING(250), - cur_ScanMethod STRING(10), - cur_Name STRING(250), - cur_LastQuery STRING(250), - cur_DateTime STRING(250), - cur_SyncHubNodeName STRING(50), - cur_NetworkSite STRING(250), - cur_SSID STRING(250), - cur_NetworkNodeMAC STRING(250), - cur_PORT STRING(250), - cur_Type STRING(250), - UNIQUE(cur_MAC) +CREATE TABLE CurrentScan ( + scanMac STRING(50) NOT NULL COLLATE NOCASE, + scanLastIP STRING(50) NOT NULL COLLATE NOCASE, + scanVendor STRING(250), + scanSourcePlugin STRING(10), + scanName STRING(250), + scanLastQuery STRING(250), + scanLastConnection STRING(250), + scanSyncHubNode STRING(50), + scanSite STRING(250), + scanSSID STRING(250), + scanParentMAC STRING(250), + scanParentPort STRING(250), + scanType STRING(250), + UNIQUE(scanMac) ); CREATE TABLE IF NOT EXISTS "AppEvents" ( "Index" INTEGER PRIMARY KEY AUTOINCREMENT, @@ -170,11 +170,11 @@ CREATE TABLE IF NOT EXISTS "AppEvents" ( "ObjectPrimaryID" TEXT, "ObjectSecondaryID" TEXT, "ObjectForeignKey" TEXT, - "ObjectIndex" TEXT, - "ObjectIsNew" BOOLEAN, - "ObjectIsArchived" BOOLEAN, + "ObjectIndex" TEXT, + "ObjectIsNew" BOOLEAN, + "ObjectIsArchived" BOOLEAN, "ObjectStatusColumn" TEXT, - "ObjectStatus" TEXT, + "ObjectStatus" TEXT, "AppEventType" TEXT, "Helper1" TEXT, "Helper2" TEXT, @@ -212,27 +212,27 @@ CREATE INDEX IDX_dev_Favorite ON Devices (devFavorite); CREATE INDEX IDX_dev_LastIP ON Devices (devLastIP); CREATE INDEX IDX_dev_NewDevice ON Devices (devIsNew); CREATE INDEX IDX_dev_Archived ON Devices (devIsArchived); -CREATE VIEW Events_Devices AS - SELECT * - FROM Events +CREATE VIEW Events_Devices AS + SELECT * + FROM Events LEFT JOIN Devices ON eve_MAC = devMac /* Events_Devices(eve_MAC,eve_IP,eve_DateTime,eve_EventType,eve_AdditionalInfo,eve_PendingAlertEmail,eve_PairEventRowid,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps) */; CREATE VIEW LatestEventsPerMAC AS WITH RankedEvents AS ( - SELECT + SELECT e.*, ROW_NUMBER() OVER (PARTITION BY e.eve_MAC ORDER BY e.eve_DateTime DESC) AS row_num FROM Events AS e ) - SELECT - e.*, - d.*, + SELECT + e.*, + d.*, c.* FROM RankedEvents AS e LEFT JOIN Devices AS d ON e.eve_MAC = d.devMac - INNER JOIN CurrentScan AS c ON e.eve_MAC = c.cur_MAC + INNER JOIN CurrentScan AS c ON e.eve_MAC = c.scanMac WHERE e.row_num = 1 -/* LatestEventsPerMAC(eve_MAC,eve_IP,eve_DateTime,eve_EventType,eve_AdditionalInfo,eve_PendingAlertEmail,eve_PairEventRowid,row_num,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps,cur_MAC,cur_IP,cur_Vendor,cur_ScanMethod,cur_Name,cur_LastQuery,cur_DateTime,cur_SyncHubNodeName,cur_NetworkSite,cur_SSID,cur_NetworkNodeMAC,cur_PORT,cur_Type) */; +/* LatestEventsPerMAC(eve_MAC,eve_IP,eve_DateTime,eve_EventType,eve_AdditionalInfo,eve_PendingAlertEmail,eve_PairEventRowid,row_num,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps,scanMac,scanLastIP,scanVendor,scanSourcePlugin,scanName,scanLastQuery,scanLastConnection,scanSyncHubNode,scanSite,scanSSID,scanParentMAC,scanParentPort,scanType) */; CREATE VIEW Sessions_Devices AS SELECT * FROM Sessions LEFT JOIN "Devices" ON ses_MAC = devMac /* Sessions_Devices(ses_MAC,ses_IP,ses_EventTypeConnection,ses_DateTimeConnection,ses_EventTypeDisconnection,ses_DateTimeDisconnection,ses_StillConnected,ses_AdditionalInfo,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps) */; CREATE VIEW Convert_Events_to_Sessions AS SELECT EVE1.eve_MAC, @@ -265,11 +265,11 @@ CREATE VIEW Convert_Events_to_Sessions AS SELECT EVE1.eve_MAC, CREATE TRIGGER "trg_insert_devices" AFTER INSERT ON "Devices" WHEN NOT EXISTS ( - SELECT 1 FROM AppEvents - WHERE AppEventProcessed = 0 + SELECT 1 FROM AppEvents + WHERE AppEventProcessed = 0 AND ObjectType = 'Devices' AND ObjectGUID = NEW.devGUID - AND ObjectStatus = CASE WHEN NEW.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END + AND ObjectStatus = CASE WHEN NEW.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END AND AppEventType = 'insert' ) BEGIN @@ -290,18 +290,18 @@ CREATE TRIGGER "trg_insert_devices" "AppEventType" ) VALUES ( - + lower( - hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' || - substr(hex( randomblob(2)), 2) || '-' || + hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' || + substr(hex( randomblob(2)), 2) || '-' || substr('AB89', 1 + (abs(random()) % 4) , 1) || - substr(hex(randomblob(2)), 2) || '-' || + substr(hex(randomblob(2)), 2) || '-' || hex(randomblob(6)) ) - , - DATETIME('now'), - FALSE, - 'Devices', + , + DATETIME('now'), + FALSE, + 'Devices', NEW.devGUID, -- ObjectGUID NEW.devMac, -- ObjectPrimaryID NEW.devLastIP, -- ObjectSecondaryID @@ -317,11 +317,11 @@ CREATE TRIGGER "trg_insert_devices" CREATE TRIGGER "trg_update_devices" AFTER UPDATE ON "Devices" WHEN NOT EXISTS ( - SELECT 1 FROM AppEvents - WHERE AppEventProcessed = 0 + SELECT 1 FROM AppEvents + WHERE AppEventProcessed = 0 AND ObjectType = 'Devices' AND ObjectGUID = NEW.devGUID - AND ObjectStatus = CASE WHEN NEW.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END + AND ObjectStatus = CASE WHEN NEW.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END AND AppEventType = 'update' ) BEGIN @@ -342,18 +342,18 @@ CREATE TRIGGER "trg_update_devices" "AppEventType" ) VALUES ( - + lower( - hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' || - substr(hex( randomblob(2)), 2) || '-' || + hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' || + substr(hex( randomblob(2)), 2) || '-' || substr('AB89', 1 + (abs(random()) % 4) , 1) || - substr(hex(randomblob(2)), 2) || '-' || + substr(hex(randomblob(2)), 2) || '-' || hex(randomblob(6)) ) - , - DATETIME('now'), - FALSE, - 'Devices', + , + DATETIME('now'), + FALSE, + 'Devices', NEW.devGUID, -- ObjectGUID NEW.devMac, -- ObjectPrimaryID NEW.devLastIP, -- ObjectSecondaryID @@ -369,11 +369,11 @@ CREATE TRIGGER "trg_update_devices" CREATE TRIGGER "trg_delete_devices" AFTER DELETE ON "Devices" WHEN NOT EXISTS ( - SELECT 1 FROM AppEvents - WHERE AppEventProcessed = 0 + SELECT 1 FROM AppEvents + WHERE AppEventProcessed = 0 AND ObjectType = 'Devices' AND ObjectGUID = OLD.devGUID - AND ObjectStatus = CASE WHEN OLD.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END + AND ObjectStatus = CASE WHEN OLD.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END AND AppEventType = 'delete' ) BEGIN @@ -394,18 +394,18 @@ CREATE TRIGGER "trg_delete_devices" "AppEventType" ) VALUES ( - + lower( - hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' || - substr(hex( randomblob(2)), 2) || '-' || + hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' || + substr(hex( randomblob(2)), 2) || '-' || substr('AB89', 1 + (abs(random()) % 4) , 1) || - substr(hex(randomblob(2)), 2) || '-' || + substr(hex(randomblob(2)), 2) || '-' || hex(randomblob(6)) ) - , - DATETIME('now'), - FALSE, - 'Devices', + , + DATETIME('now'), + FALSE, + 'Devices', OLD.devGUID, -- ObjectGUID OLD.devMac, -- ObjectPrimaryID OLD.devLastIP, -- ObjectSecondaryID diff --git a/server/db/db_upgrade.py b/server/db/db_upgrade.py index 3d6132c2..994e7f2f 100755 --- a/server/db/db_upgrade.py +++ b/server/db/db_upgrade.py @@ -133,7 +133,7 @@ def ensure_views(sql) -> bool: c.* FROM RankedEvents AS e LEFT JOIN Devices AS d ON e.eve_MAC = d.devMac - INNER JOIN CurrentScan AS c ON e.eve_MAC = c.cur_MAC + INNER JOIN CurrentScan AS c ON e.eve_MAC = c.scanMac WHERE e.row_num = 1;""") sql.execute(""" DROP VIEW IF EXISTS Sessions_Devices;""") @@ -177,8 +177,8 @@ def ensure_views(sql) -> bool: SELECT c.*, ROW_NUMBER() OVER ( - PARTITION BY c.cur_MAC, c.cur_ScanMethod - ORDER BY c.cur_DateTime DESC + PARTITION BY c.scanMac, c.scanSourcePlugin + ORDER BY c.scanLastConnection DESC ) AS rn FROM CurrentScan c ) @@ -187,7 +187,7 @@ def ensure_views(sql) -> bool: r.* -- all CurrentScan fields (cur_*) FROM Devices d LEFT JOIN RankedScans r - ON d.devMac = r.cur_MAC + ON d.devMac = r.scanMac WHERE r.rn = 1; """) @@ -282,20 +282,20 @@ def ensure_CurrentScan(sql) -> bool: # 🐛 CurrentScan DEBUG: comment out below when debugging to keep the CurrentScan table after restarts/scan finishes sql.execute("DROP TABLE IF EXISTS CurrentScan;") sql.execute(""" CREATE TABLE IF NOT EXISTS CurrentScan ( - cur_MAC STRING(50) NOT NULL COLLATE NOCASE, - cur_IP STRING(50) NOT NULL COLLATE NOCASE, - cur_Vendor STRING(250), - cur_ScanMethod STRING(10), - cur_Name STRING(250), - cur_LastQuery STRING(250), - cur_DateTime STRING(250), - cur_SyncHubNodeName STRING(50), - cur_NetworkSite STRING(250), - cur_SSID STRING(250), - cur_devVlan STRING(250), - cur_NetworkNodeMAC STRING(250), - cur_PORT STRING(250), - cur_Type STRING(250) + scanMac STRING(50) NOT NULL COLLATE NOCASE, + scanLastIP STRING(50) NOT NULL COLLATE NOCASE, + scanVendor STRING(250), + scanSourcePlugin STRING(10), + scanName STRING(250), + scanLastQuery STRING(250), + scanLastConnection STRING(250), + scanSyncHubNode STRING(50), + scanSite STRING(250), + scanSSID STRING(250), + scanVlan STRING(250), + scanParentMAC STRING(250), + scanParentPort STRING(250), + scanType STRING(250) ); """) diff --git a/server/scan/device_handling.py b/server/scan/device_handling.py index 49251d03..1321fd9e 100755 --- a/server/scan/device_handling.py +++ b/server/scan/device_handling.py @@ -56,10 +56,10 @@ 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") + "OR", "scanMac", "LIKE", get_setting_value("NEWDEV_ignored_MACs") ) ip_condition = list_to_where( - "OR", "cur_IP", "LIKE", get_setting_value("NEWDEV_ignored_IPs") + "OR", "scanLastIP", "LIKE", get_setting_value("NEWDEV_ignored_IPs") ) # Only delete if either the MAC or IP matches an ignored condition @@ -93,7 +93,7 @@ FIELD_SPECS = { # DEVICE NAME # ========================================================== "devName": { - "scan_col": "cur_Name", + "scan_col": "scanName", "source_col": "devNameSource", "empty_values": ["", "null", "(unknown)", "(name not found)"], "default_value": "(unknown)", @@ -104,7 +104,7 @@ FIELD_SPECS = { # DEVICE FQDN # ========================================================== "devFQDN": { - "scan_col": "cur_Name", + "scan_col": "scanName", "source_col": "devNameSource", "empty_values": ["", "null", "(unknown)", "(name not found)"], "priority": ["NSLOOKUP", "AVAHISCAN", "NBTSCAN", "DIGSCAN", "ARPSCAN", "DHCPLSS", "NEWDEV", "N/A"], @@ -114,7 +114,7 @@ FIELD_SPECS = { # IP ADDRESS (last seen) # ========================================================== "devLastIP": { - "scan_col": "cur_IP", + "scan_col": "scanLastIP", "source_col": "devLastIPSource", "empty_values": ["", "null", "(unknown)", "(Unknown)"], "priority": ["ARPSCAN", "NEWDEV", "N/A"], @@ -125,7 +125,7 @@ FIELD_SPECS = { # VENDOR # ========================================================== "devVendor": { - "scan_col": "cur_Vendor", + "scan_col": "scanVendor", "source_col": "devVendorSource", "empty_values": ["", "null", "(unknown)", "(Unknown)"], "priority": ["VNDRPDT", "ARPSCAN", "NEWDEV", "N/A"], @@ -136,7 +136,7 @@ FIELD_SPECS = { # SYNC HUB NODE NAME # ========================================================== "devSyncHubNode": { - "scan_col": "cur_SyncHubNodeName", + "scan_col": "scanSyncHubNode", "source_col": None, "empty_values": ["", "null"], "priority": None, @@ -146,7 +146,7 @@ FIELD_SPECS = { # Network Site # ========================================================== "devSite": { - "scan_col": "cur_NetworkSite", + "scan_col": "scanSite", "source_col": None, "empty_values": ["", "null"], "priority": None, @@ -156,7 +156,7 @@ FIELD_SPECS = { # VLAN # ========================================================== "devVlan": { - "scan_col": "cur_devVlan", + "scan_col": "scanVlan", "source_col": "devVlanSource", "empty_values": ["", "null"], "priority": None, @@ -166,7 +166,7 @@ FIELD_SPECS = { # devType # ========================================================== "devType": { - "scan_col": "cur_Type", + "scan_col": "scanType", "source_col": None, "empty_values": ["", "null"], "priority": None, @@ -176,14 +176,14 @@ FIELD_SPECS = { # TOPOLOGY (PARENT NODE) # ========================================================== "devParentMAC": { - "scan_col": "cur_NetworkNodeMAC", + "scan_col": "scanParentMAC", "source_col": "devParentMACSource", "empty_values": ["", "null"], "priority": ["SNMPDSC", "UNIFIAPI", "UNFIMP", "NEWDEV", "N/A"], }, "devParentPort": { - "scan_col": "cur_PORT", + "scan_col": "scanParentPort", "source_col": None, "empty_values": ["", "null"], "priority": ["SNMPDSC", "UNIFIAPI", "UNFIMP", "NEWDEV", "N/A"], @@ -193,7 +193,7 @@ FIELD_SPECS = { # WIFI SSID # ========================================================== "devSSID": { - "scan_col": "cur_SSID", + "scan_col": "scanSSID", "source_col": None, "empty_values": ["", "null"], "priority": ["SNMPDSC", "UNIFIAPI", "UNFIMP", "NEWDEV", "N/A"], @@ -214,7 +214,7 @@ def update_presence_from_CurrentScan(db): SET devPresentLastScan = 1 WHERE EXISTS ( SELECT 1 FROM CurrentScan - WHERE devMac = cur_MAC + WHERE devMac = scanMac ) """) @@ -224,7 +224,7 @@ def update_presence_from_CurrentScan(db): SET devPresentLastScan = 0 WHERE NOT EXISTS ( SELECT 1 FROM CurrentScan - WHERE devMac = cur_MAC + WHERE devMac = scanMac ) """) @@ -242,7 +242,7 @@ def update_devLastConnection_from_CurrentScan(db): SET devLastConnection = '{startTime}' WHERE EXISTS ( SELECT 1 FROM CurrentScan - WHERE devMac = cur_MAC + WHERE devMac = scanMac ) """) @@ -253,7 +253,7 @@ def update_devices_data_from_scan(db): # ---------------------------------------------------------------- # 1️⃣ Get plugin scan methods # ---------------------------------------------------------------- - plugin_rows = sql.execute("SELECT DISTINCT cur_ScanMethod FROM CurrentScan").fetchall() + plugin_rows = sql.execute("SELECT DISTINCT scanSourcePlugin FROM CurrentScan").fetchall() plugin_prefixes = [row[0] for row in plugin_rows if row[0]] or [None] plugin_settings_cache = {} @@ -275,7 +275,7 @@ def update_devices_data_from_scan(db): sql_tmp = f""" SELECT * FROM LatestDeviceScan - {"WHERE cur_ScanMethod = ?" if filter_by_scan_method else ""} + {"WHERE scanSourcePlugin = ?" if filter_by_scan_method else ""} """ rows = sql.execute(sql_tmp, (source_prefix,) if filter_by_scan_method else ()).fetchall() col_names = [desc[0] for desc in sql.description] @@ -444,8 +444,8 @@ def update_vendors_from_mac(db): # Build mapping: devMac -> vendor (skip unknown or invalid) vendor_map = {} - for row in sql.execute("SELECT DISTINCT cur_MAC FROM CurrentScan"): - mac = row["cur_MAC"] + for row in sql.execute("SELECT DISTINCT scanMac FROM CurrentScan"): + mac = row["scanMac"] vendor = query_MAC_vendor(mac) if vendor not in (-1, -2): vendor_map[mac] = vendor @@ -518,7 +518,7 @@ def save_scanned_devices(db): # Proceed if variable contains valid MAC if check_mac_or_internet(local_mac): sql.execute( - f"""INSERT OR IGNORE INTO CurrentScan (cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod) VALUES ( '{local_mac}', '{local_ip}', Null, 'local_MAC') """ + f"""INSERT OR IGNORE INTO CurrentScan (scanMac, scanLastIP, scanVendor, scanSourcePlugin) VALUES ( '{local_mac}', '{local_ip}', Null, 'local_MAC') """ ) @@ -529,23 +529,23 @@ def print_scan_stats(db): query = """ SELECT (SELECT COUNT(*) FROM CurrentScan) AS devices_detected, - (SELECT COUNT(*) FROM CurrentScan WHERE NOT EXISTS (SELECT 1 FROM Devices WHERE devMac = cur_MAC)) AS new_devices, - (SELECT COUNT(*) FROM Devices WHERE devAlertDown != 0 AND NOT EXISTS (SELECT 1 FROM CurrentScan WHERE devMac = cur_MAC)) AS down_alerts, - (SELECT COUNT(*) FROM Devices WHERE devAlertDown != 0 AND devPresentLastScan = 1 AND NOT EXISTS (SELECT 1 FROM CurrentScan WHERE devMac = cur_MAC)) AS new_down_alerts, + (SELECT COUNT(*) FROM CurrentScan WHERE NOT EXISTS (SELECT 1 FROM Devices WHERE devMac = scanMac)) AS new_devices, + (SELECT COUNT(*) FROM Devices WHERE devAlertDown != 0 AND NOT EXISTS (SELECT 1 FROM CurrentScan WHERE devMac = scanMac)) AS down_alerts, + (SELECT COUNT(*) FROM Devices WHERE devAlertDown != 0 AND devPresentLastScan = 1 AND NOT EXISTS (SELECT 1 FROM CurrentScan WHERE devMac = scanMac)) AS new_down_alerts, (SELECT COUNT(*) FROM Devices WHERE devPresentLastScan = 0) AS new_connections, - (SELECT COUNT(*) FROM Devices WHERE devPresentLastScan = 1 AND NOT EXISTS (SELECT 1 FROM CurrentScan WHERE devMac = cur_MAC)) AS disconnections, + (SELECT COUNT(*) FROM Devices WHERE devPresentLastScan = 1 AND NOT EXISTS (SELECT 1 FROM CurrentScan WHERE devMac = scanMac)) AS disconnections, (SELECT COUNT(*) FROM Devices, CurrentScan - WHERE devMac = cur_MAC - AND cur_IP IS NOT NULL - AND cur_IP NOT IN ('', 'null', '(unknown)', '(Unknown)') - AND cur_IP <> COALESCE(devPrimaryIPv4, '') - AND cur_IP <> COALESCE(devPrimaryIPv6, '') - AND cur_IP <> COALESCE(devLastIP, '') + WHERE devMac = scanMac + AND scanLastIP IS NOT NULL + AND scanLastIP NOT IN ('', 'null', '(unknown)', '(Unknown)') + AND scanLastIP <> COALESCE(devPrimaryIPv4, '') + AND scanLastIP <> COALESCE(devPrimaryIPv6, '') + AND scanLastIP <> COALESCE(devLastIP, '') ) AS ip_changes, - cur_ScanMethod, + scanSourcePlugin, COUNT(*) AS scan_method_count FROM CurrentScan - GROUP BY cur_ScanMethod + GROUP BY scanSourcePlugin """ sql.execute(query) @@ -590,8 +590,8 @@ def print_scan_stats(db): mylog("verbose", "[Scan Stats] Scan Method Statistics:") for row in stats: - if row["cur_ScanMethod"] is not None: - mylog("verbose", f" {row['cur_ScanMethod']}: {row['scan_method_count']}") + if row["scanSourcePlugin"] is not None: + mylog("verbose", f" {row['scanSourcePlugin']}: {row['scan_method_count']}") # ------------------------------------------------------------------------------- @@ -608,11 +608,11 @@ def create_new_devices(db): eve_EventType, eve_AdditionalInfo, eve_PendingAlertEmail ) - SELECT DISTINCT cur_MAC, cur_IP, '{startTime}', 'New Device', cur_Vendor, 1 + SELECT DISTINCT scanMac, scanLastIP, '{startTime}', 'New Device', scanVendor, 1 FROM CurrentScan WHERE NOT EXISTS ( SELECT 1 FROM Devices - WHERE devMac = cur_MAC + WHERE devMac = scanMac ) """ @@ -627,15 +627,15 @@ def create_new_devices(db): ses_EventTypeDisconnection, ses_DateTimeDisconnection, ses_StillConnected, ses_AdditionalInfo ) - SELECT cur_MAC, cur_IP, 'Connected', '{startTime}', NULL, NULL, 1, cur_Vendor + SELECT scanMac, scanLastIP, 'Connected', '{startTime}', NULL, NULL, 1, scanVendor FROM CurrentScan WHERE EXISTS ( SELECT 1 FROM Devices - WHERE devMac = cur_MAC + WHERE devMac = scanMac ) AND NOT EXISTS ( SELECT 1 FROM Sessions - WHERE ses_MAC = cur_MAC AND ses_StillConnected = 1 + WHERE ses_MAC = scanMac AND ses_StillConnected = 1 ) """) @@ -680,7 +680,7 @@ def create_new_devices(db): """ # Fetch data from CurrentScan skipping ignored devices by IP and MAC - query = """SELECT cur_MAC, cur_Name, cur_Vendor, cur_ScanMethod, cur_IP, cur_SyncHubNodeName, cur_NetworkNodeMAC, cur_PORT, cur_NetworkSite, cur_SSID, cur_Type + query = """SELECT scanMac, scanName, scanVendor, scanSourcePlugin, scanLastIP, scanSyncHubNode, scanParentMAC, scanParentPort, scanSite, scanSSID, scanType FROM CurrentScan """ mylog("debug", f"[New Devices] Collecting New Devices Query: {query}") @@ -688,61 +688,61 @@ def create_new_devices(db): for row in current_scan_data: ( - cur_MAC, - cur_Name, - cur_Vendor, - cur_ScanMethod, - cur_IP, - cur_SyncHubNodeName, - cur_NetworkNodeMAC, - cur_PORT, - cur_NetworkSite, - cur_SSID, - cur_Type, + scanMac, + scanName, + scanVendor, + scanSourcePlugin, + scanLastIP, + scanSyncHubNode, + scanParentMAC, + scanParentPort, + scanSite, + scanSSID, + scanType, ) = row # Preserve raw values to determine source attribution - raw_name = str(cur_Name).strip() if cur_Name else "" - raw_vendor = str(cur_Vendor).strip() if cur_Vendor else "" - raw_ip = str(cur_IP).strip() if cur_IP else "" + raw_name = str(scanName).strip() if scanName else "" + raw_vendor = str(scanVendor).strip() if scanVendor else "" + raw_ip = str(scanLastIP).strip() if scanLastIP else "" if raw_ip.lower() in ("null", "(unknown)"): raw_ip = "" - raw_ssid = str(cur_SSID).strip() if cur_SSID else "" + raw_ssid = str(scanSSID).strip() if scanSSID else "" if raw_ssid.lower() in ("null", "(unknown)"): raw_ssid = "" - raw_parent_mac = str(cur_NetworkNodeMAC).strip() if cur_NetworkNodeMAC else "" + raw_parent_mac = str(scanParentMAC).strip() if scanParentMAC else "" if raw_parent_mac.lower() in ("null", "(unknown)"): raw_parent_mac = "" - raw_parent_port = str(cur_PORT).strip() if cur_PORT else "" + raw_parent_port = str(scanParentPort).strip() if scanParentPort else "" if raw_parent_port.lower() in ("null", "(unknown)"): raw_parent_port = "" # Handle NoneType - cur_Name = raw_name if raw_name else "(unknown)" - cur_Type = ( - str(cur_Type).strip() if cur_Type else get_setting_value("NEWDEV_devType") + scanName = raw_name if raw_name else "(unknown)" + scanType = ( + str(scanType).strip() if scanType else get_setting_value("NEWDEV_devType") ) - cur_NetworkNodeMAC = raw_parent_mac - cur_NetworkNodeMAC = ( - cur_NetworkNodeMAC - if cur_NetworkNodeMAC and cur_MAC != "Internet" + scanParentMAC = raw_parent_mac + scanParentMAC = ( + scanParentMAC + if scanParentMAC and scanMac != "Internet" else ( get_setting_value("NEWDEV_devParentMAC") - if cur_MAC != "Internet" + if scanMac != "Internet" else "null" ) ) - cur_SyncHubNodeName = ( - cur_SyncHubNodeName - if cur_SyncHubNodeName and cur_SyncHubNodeName != "null" + scanSyncHubNode = ( + scanSyncHubNode + if scanSyncHubNode and scanSyncHubNode != "null" else (get_setting_value("SYNC_node_name")) ) # Derive primary IP family values - cur_IP = raw_ip - cur_SSID = raw_ssid - cur_PORT = raw_parent_port - cur_IP_normalized = check_IP_format(cur_IP) if ":" not in cur_IP else cur_IP + scanLastIP = raw_ip + scanSSID = raw_ssid + scanParentPort = raw_parent_port + cur_IP_normalized = check_IP_format(scanLastIP) if ":" not in scanLastIP else scanLastIP # Validate IPv6 addresses using format_ip_long for consistency (do not store integer result) if cur_IP_normalized and ":" in cur_IP_normalized: @@ -753,10 +753,10 @@ def create_new_devices(db): primary_ipv4 = cur_IP_normalized if cur_IP_normalized and ":" not in cur_IP_normalized else "" primary_ipv6 = cur_IP_normalized if cur_IP_normalized and ":" in cur_IP_normalized else "" - plugin_prefix = str(cur_ScanMethod).strip() if cur_ScanMethod else "NEWDEV" + plugin_prefix = str(scanSourcePlugin).strip() if scanSourcePlugin else "NEWDEV" dev_mac_source = get_source_for_field_update_with_value( - "devMac", plugin_prefix, cur_MAC, is_user_override=False + "devMac", plugin_prefix, scanMac, is_user_override=False ) dev_name_source = get_source_for_field_update_with_value( "devName", plugin_prefix, raw_name, is_user_override=False @@ -813,22 +813,22 @@ def create_new_devices(db): ) VALUES ( - '{sanitize_SQL_input(cur_MAC)}', - '{sanitize_SQL_input(cur_Name)}', - '{sanitize_SQL_input(cur_Vendor)}', + '{sanitize_SQL_input(scanMac)}', + '{sanitize_SQL_input(scanName)}', + '{sanitize_SQL_input(scanVendor)}', '{sanitize_SQL_input(cur_IP_normalized)}', '{sanitize_SQL_input(primary_ipv4)}', '{sanitize_SQL_input(primary_ipv6)}', ?, ?, - '{sanitize_SQL_input(cur_SyncHubNodeName)}', + '{sanitize_SQL_input(scanSyncHubNode)}', {sql_generateGuid}, - '{sanitize_SQL_input(cur_NetworkNodeMAC)}', - '{sanitize_SQL_input(cur_PORT)}', - '{sanitize_SQL_input(cur_NetworkSite)}', - '{sanitize_SQL_input(cur_SSID)}', - '{sanitize_SQL_input(cur_Type)}', - '{sanitize_SQL_input(cur_ScanMethod)}', + '{sanitize_SQL_input(scanParentMAC)}', + '{sanitize_SQL_input(scanParentPort)}', + '{sanitize_SQL_input(scanSite)}', + '{sanitize_SQL_input(scanSSID)}', + '{sanitize_SQL_input(scanType)}', + '{sanitize_SQL_input(scanSourcePlugin)}', '{sanitize_SQL_input(dev_mac_source)}', '{sanitize_SQL_input(dev_name_source)}', '{sanitize_SQL_input(dev_fqdn_source)}', diff --git a/server/scan/session_events.py b/server/scan/session_events.py index 43b9eb47..049ed591 100755 --- a/server/scan/session_events.py +++ b/server/scan/session_events.py @@ -174,7 +174,7 @@ def insert_events(db): WHERE devAlertDown != 0 AND devPresentLastScan = 1 AND NOT EXISTS (SELECT 1 FROM CurrentScan - WHERE devMac = cur_MAC + WHERE devMac = scanMac ) """) # Check new Connections or Down Reconnections @@ -182,7 +182,7 @@ def insert_events(db): sql.execute(f""" INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime, eve_EventType, eve_AdditionalInfo, eve_PendingAlertEmail) - SELECT DISTINCT c.cur_MAC, c.cur_IP, '{startTime}', + SELECT DISTINCT c.scanMac, c.scanLastIP, '{startTime}', CASE WHEN last_event.eve_EventType = 'Device Down' and last_event.eve_PendingAlertEmail = 0 THEN 'Down Reconnected' ELSE 'Connected' @@ -190,7 +190,7 @@ def insert_events(db): '', 1 FROM CurrentScan AS c - LEFT JOIN LatestEventsPerMAC AS last_event ON c.cur_MAC = last_event.eve_MAC + LEFT JOIN LatestEventsPerMAC AS last_event ON c.scanMac = last_event.eve_MAC WHERE last_event.devPresentLastScan = 0 OR last_event.eve_MAC IS NULL """) @@ -205,7 +205,7 @@ def insert_events(db): WHERE devAlertDown = 0 AND devPresentLastScan = 1 AND NOT EXISTS (SELECT 1 FROM CurrentScan - WHERE devMac = cur_MAC + WHERE devMac = scanMac ) """) # Check IP Changed @@ -213,15 +213,15 @@ def insert_events(db): sql.execute(f"""INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime, eve_EventType, eve_AdditionalInfo, eve_PendingAlertEmail) - SELECT cur_MAC, cur_IP, '{startTime}', 'IP Changed', + SELECT scanMac, scanLastIP, '{startTime}', 'IP Changed', 'Previous IP: '|| devLastIP, devAlertEvents FROM Devices, CurrentScan - WHERE devMac = cur_MAC - AND cur_IP IS NOT NULL - AND cur_IP NOT IN ('', 'null', '(unknown)', '(Unknown)') - AND cur_IP <> COALESCE(devPrimaryIPv4, '') - AND cur_IP <> COALESCE(devPrimaryIPv6, '') - AND cur_IP <> COALESCE(devLastIP, '') """) + WHERE devMac = scanMac + AND scanLastIP IS NOT NULL + AND scanLastIP NOT IN ('', 'null', '(unknown)', '(Unknown)') + AND scanLastIP <> COALESCE(devPrimaryIPv4, '') + AND scanLastIP <> COALESCE(devPrimaryIPv6, '') + AND scanLastIP <> COALESCE(devLastIP, '') """) mylog("debug", "[Events] - Events end") diff --git a/test/authoritative_fields/test_field_lock_scan_integration.py b/test/authoritative_fields/test_field_lock_scan_integration.py index 23de16fd..25fa57b5 100644 --- a/test/authoritative_fields/test_field_lock_scan_integration.py +++ b/test/authoritative_fields/test_field_lock_scan_integration.py @@ -66,19 +66,19 @@ def scan_db(): cur.execute( """ CREATE TABLE CurrentScan ( - cur_MAC TEXT, - cur_IP TEXT, - cur_Vendor TEXT, - cur_ScanMethod TEXT, - cur_Name TEXT, - cur_LastQuery TEXT, - cur_DateTime TEXT, - cur_SyncHubNodeName TEXT, - cur_NetworkSite TEXT, - cur_SSID TEXT, - cur_NetworkNodeMAC TEXT, - cur_PORT TEXT, - cur_Type TEXT + scanMac TEXT, + scanLastIP TEXT, + scanVendor TEXT, + scanSourcePlugin TEXT, + scanName TEXT, + scanLastQuery TEXT, + scanLastConnection TEXT, + scanSyncHubNode TEXT, + scanSite TEXT, + scanSSID TEXT, + scanParentMAC TEXT, + scanParentPort TEXT, + scanType TEXT ) """ ) @@ -196,17 +196,17 @@ def scan_db_for_new_devices(): cur.execute( """ CREATE TABLE CurrentScan ( - cur_MAC TEXT, - cur_Name TEXT, - cur_Vendor TEXT, - cur_ScanMethod TEXT, - cur_IP TEXT, - cur_SyncHubNodeName TEXT, - cur_NetworkNodeMAC TEXT, - cur_PORT TEXT, - cur_NetworkSite TEXT, - cur_SSID TEXT, - cur_Type TEXT + scanMac TEXT, + scanName TEXT, + scanVendor TEXT, + scanSourcePlugin TEXT, + scanLastIP TEXT, + scanSyncHubNode TEXT, + scanParentMAC TEXT, + scanParentPort TEXT, + scanSite TEXT, + scanSSID TEXT, + scanType TEXT ) """ ) @@ -250,9 +250,9 @@ def test_create_new_devices_sets_sources(scan_db_for_new_devices): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_Name, cur_Vendor, cur_ScanMethod, cur_IP, - cur_SyncHubNodeName, cur_NetworkNodeMAC, cur_PORT, - cur_NetworkSite, cur_SSID, cur_Type + scanMac, scanName, scanVendor, scanSourcePlugin, scanLastIP, + scanSyncHubNode, scanParentMAC, scanParentPort, + scanSite, scanSSID, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -364,9 +364,9 @@ def test_scan_updates_newdev_device_name(scan_db, mock_device_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -439,9 +439,9 @@ def test_scan_does_not_update_user_field_name(scan_db, mock_device_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -514,9 +514,9 @@ def test_scan_does_not_update_locked_field(scan_db, mock_device_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -589,9 +589,9 @@ def test_scan_updates_empty_vendor_field(scan_db, mock_device_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -667,9 +667,9 @@ def test_scan_updates_ip_addresses(scan_db, mock_device_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -747,9 +747,9 @@ def test_scan_updates_ipv6_without_changing_ipv4(scan_db, mock_device_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -890,9 +890,9 @@ def test_scan_multiple_devices_mixed_sources(scan_db, mock_device_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, (mac, ip, vendor, scan_method, name, "", "2025-01-01 01:00:00", "", "", "", "", "", ""), diff --git a/test/authoritative_fields/test_ip_format_and_locking.py b/test/authoritative_fields/test_ip_format_and_locking.py index ad57063d..a428e774 100644 --- a/test/authoritative_fields/test_ip_format_and_locking.py +++ b/test/authoritative_fields/test_ip_format_and_locking.py @@ -51,19 +51,19 @@ def ip_test_db(): cur.execute( """ CREATE TABLE CurrentScan ( - cur_MAC TEXT, - cur_IP TEXT, - cur_Vendor TEXT, - cur_ScanMethod TEXT, - cur_Name TEXT, - cur_LastQuery TEXT, - cur_DateTime TEXT, - cur_SyncHubNodeName TEXT, - cur_NetworkSite TEXT, - cur_SSID TEXT, - cur_NetworkNodeMAC TEXT, - cur_PORT TEXT, - cur_Type TEXT + scanMac TEXT, + scanLastIP TEXT, + scanVendor TEXT, + scanSourcePlugin TEXT, + scanName TEXT, + scanLastQuery TEXT, + scanLastConnection TEXT, + scanSyncHubNode TEXT, + scanSite TEXT, + scanSSID TEXT, + scanParentMAC TEXT, + scanParentPort TEXT, + scanType TEXT ) """ ) @@ -123,9 +123,9 @@ def test_valid_ipv4_format_accepted(ip_test_db, mock_ip_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -197,9 +197,9 @@ def test_valid_ipv6_format_accepted(ip_test_db, mock_ip_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -274,9 +274,9 @@ def test_invalid_ip_values_rejected(ip_test_db, mock_ip_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -348,9 +348,9 @@ def test_ipv4_ipv6_mixed_in_multiple_scans(ip_test_db, mock_ip_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -390,9 +390,9 @@ def test_ipv4_ipv6_mixed_in_multiple_scans(ip_test_db, mock_ip_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -455,9 +455,9 @@ def test_ipv4_address_format_variations(ip_test_db, mock_ip_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, (mac, ipv4, "Vendor", "ARPSCAN", "", "", "2025-01-01 01:00:00", "", "", "", "", "", ""), @@ -509,9 +509,9 @@ def test_ipv6_address_format_variations(ip_test_db, mock_ip_handlers): cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, (mac, ipv6, "Vendor", "ARPSCAN", "", "", "2025-01-01 01:00:00", "", "", "", "", "", ""), diff --git a/test/authoritative_fields/test_ip_update_logic.py b/test/authoritative_fields/test_ip_update_logic.py index ef55a05a..7c512902 100644 --- a/test/authoritative_fields/test_ip_update_logic.py +++ b/test/authoritative_fields/test_ip_update_logic.py @@ -42,19 +42,19 @@ def in_memory_db(): cur.execute( """ CREATE TABLE CurrentScan ( - cur_MAC TEXT, - cur_IP TEXT, - cur_Vendor TEXT, - cur_ScanMethod TEXT, - cur_Name TEXT, - cur_LastQuery TEXT, - cur_DateTime TEXT, - cur_SyncHubNodeName TEXT, - cur_NetworkSite TEXT, - cur_SSID TEXT, - cur_NetworkNodeMAC TEXT, - cur_PORT TEXT, - cur_Type TEXT + scanMac TEXT, + scanLastIP TEXT, + scanVendor TEXT, + scanSourcePlugin TEXT, + scanName TEXT, + scanLastQuery TEXT, + scanLastConnection TEXT, + scanSyncHubNode TEXT, + scanSite TEXT, + scanSSID TEXT, + scanParentMAC TEXT, + scanParentPort TEXT, + scanType TEXT ) """ ) @@ -118,9 +118,9 @@ def test_primary_ipv6_is_set_and_ipv4_preserved(in_memory_db, mock_device_handli cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -145,7 +145,7 @@ def test_primary_ipv6_is_set_and_ipv4_preserved(in_memory_db, mock_device_handli db = Mock() db.sql_connection = in_memory_db db.sql = cur - + device_handling.update_devices_data_from_scan(db) row = cur.execute( @@ -193,9 +193,9 @@ def test_primary_ipv4_is_set_and_ipv6_preserved(in_memory_db, mock_device_handli cur.execute( """ INSERT INTO CurrentScan ( - cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod, cur_Name, - cur_LastQuery, cur_DateTime, cur_SyncHubNodeName, - cur_NetworkSite, cur_SSID, cur_NetworkNodeMAC, cur_PORT, cur_Type + scanMac, scanLastIP, scanVendor, scanSourcePlugin, scanName, + scanLastQuery, scanLastConnection, scanSyncHubNode, + scanSite, scanSSID, scanParentMAC, scanParentPort, scanType ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -220,7 +220,7 @@ def test_primary_ipv4_is_set_and_ipv6_preserved(in_memory_db, mock_device_handli db = Mock() db.sql_connection = in_memory_db db.sql = cur - + device_handling.update_devices_data_from_scan(db) row = cur.execute(