diff --git a/docs/PLUGINS.md b/docs/PLUGINS.md index c4f8bd97..dfa52ac0 100755 --- a/docs/PLUGINS.md +++ b/docs/PLUGINS.md @@ -43,51 +43,50 @@ NetAlertX supports additional plugins to extend its functionality, each with its Device-detecting plugins insert values into the `CurrentScan` database table. The plugins that are not required are safe to ignore, however, it makes sense to have at least some device-detecting plugins enabled, such as `ARPSCAN` or `NMAPDEV`. - -| ID | Type | Description | Features | Required | Data source | Detailed docs | -|---------------|---------|--------------------------------------------|----------|----------|--------------|---------------------------------------------------------------------| -| `APPRISE` | ▶️ | Apprise notification proxy | | | Script | [_publisher_apprise](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_apprise/) | -| `ARPSCAN` | 🔍 | ARP-scan on current network | | | Script | [arp_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/arp_scan/) | -| `AVAHISCAN` | 🆎 | Avahi (mDNS-based) name resolution | | | Script | [avahi_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/avahi_scan/) | -| `ASUSWRT` | 🔍 | Import connected devices from AsusWRT | | | Script | [asuswrt_import](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/asuswrt_import/) | -| `CSVBCKP` | ⚙ | CSV devices backup | | | Script | [csv_backup](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/csv_backup/) | -| `CUSTPROP` | ⚙ | Managing custom device properties values | | Yes | Template | [custom_props](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/custom_props/) | -| `DBCLNP` | ⚙ | Database cleanup | | Yes* | Script | [db_cleanup](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/db_cleanup/) | -| `DDNS` | ⚙ | DDNS update | | | Script | [ddns_update](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/ddns_update/) | -| `DHCPLSS` | 🔍/📥/🆎| Import devices from DHCP leases | | | Script | [dhcp_leases](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/dhcp_leases/) | -| `DHCPSRVS` | ♻ | DHCP servers | | | Script | [dhcp_servers](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/dhcp_servers/) | -| `DIGSCAN` | 🆎 | Dig (DNS) Name resolution | | | Script | [dig_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/dig_scan/) | -| `FREEBOX` | 🔍/♻/🆎| Pull data and names from Freebox/Iliadbox | | | Script | [freebox](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/freebox/) | -| `ICMP` | ♻ | ICMP (ping) status checker | | | Script | [icmp_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/icmp_scan/) | -| `INTRNT` | 🔍 | Internet IP scanner | | | Script | [internet_ip](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/internet_ip/) | -| `INTRSPD` | ♻ | Internet speed test | | | Script | [internet_speedtest](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/internet_speedtest/) | -| `IPNEIGH` | 🔍 | Scan ARP (IPv4) and NDP (IPv6) tables | | | Script | [ipneigh](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/ipneigh/) | -| `LUCIRPC` | 🔍 | Import connected devices from OpenWRT | | | Script | [luci_import](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/luci_import/) | -| `MAINT` | ⚙ | Maintenance of logs, etc. | | | Script | [maintenance](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/maintenance/) | -| `MQTT` | ▶️ | MQTT for synching to Home Assistant | | | Script | [_publisher_mqtt](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_mqtt/) | -| `NBTSCAN` | 🆎 | Nbtscan (NetBIOS-based) name resolution | | | Script | [nbtscan_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/nbtscan_scan/) | -| `NEWDEV` | ⚙ | New device template | | Yes | Template | [newdev_template](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/newdev_template/) | -| `NMAP` | ♻ | Nmap port scanning & discovery | | | Script | [nmap_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/nmap_scan/) | -| `NMAPDEV` | 🔍 | Nmap dev scan on current network | | | Script | [nmap_dev_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/nmap_dev_scan/) | -| `NSLOOKUP` | 🆎 | NSLookup (DNS-based) name resolution | | | Script | [nslookup_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/nslookup_scan/) | -| `NTFPRCS` | ⚙ | Notification processing | | Yes | Template | [notification_processing](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/notification_processing/)| -| `NTFY` | ▶️ | NTFY notifications | | | Script | [_publisher_ntfy](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_ntfy/) | -| `OMDSDN` | 📥/🆎 ❌ | UNMAINTAINED use `OMDSDNOPENAPI` | 🖧 🔄 | | Script | [omada_sdn_imp](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/omada_sdn_imp/) | -| `OMDSDNOPENAPI`| 📥/🆎 | OMADA TP-Link import via OpenAPI | 🖧 | | Script | [omada_sdn_openapi](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/omada_sdn_openapi/) | -| `PIHOLE` | 🔍/🆎/📥| Pi-hole device import & sync | | | SQLite DB | [pihole_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/pihole_scan/) | -| `PUSHSAFER` | ▶️ | Pushsafer notifications | | | Script | [_publisher_pushsafer](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_pushsafer/) | -| `PUSHOVER` | ▶️ | Pushover notifications | | | Script | [_publisher_pushover](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_pushover/) | -| `SETPWD` | ⚙ | Set password | | Yes | Template | [set_password](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/set_password/) | -| `SMTP` | ▶️ | Email notifications | | | Script | [_publisher_email](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_email/) | -| `SNMPDSC` | 🔍/📥 | SNMP device import & sync | | | Script | [snmp_discovery](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/snmp_discovery/) | -| `SYNC` | 🔍/⚙/📥| Sync & import from NetAlertX instances | 🖧 🔄 | Yes | Script | [sync](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/sync/) | -| `TELEGRAM` | ▶️ | Telegram notifications | | | Script | [_publisher_telegram](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_telegram/) | -| `UI` | ♻ | UI specific settings | | Yes | Template | [ui_settings](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/ui_settings/) | -| `UNFIMP` | 🔍/📥/🆎| UniFi device import & sync | 🖧 | | Script | [unifi_import](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/unifi_import/) | -| `VNDRPDT` | ⚙ | Vendor database update | | | Script | [vendor_update](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/vendor_update/) | -| `WEBHOOK` | ▶️ | Webhook notifications | | | Script | [_publisher_webhook](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_webhook/) | -| `WEBMON` | ♻ | Website down monitoring | | | Script | [website_monitor](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/website_monitor/) | -| `WOL` | ♻ | Automatic wake-on-lan | | | Script | [wake_on_lan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/wake_on_lan/) | +| ID | Plugin docs | Type | Description | Features | Required | +| --------------- | ------------------------------------------------------------------------------------------------------------------ | -------- | ----------------------------------------- | -------- | -------- | +| `APPRISE` | [_publisher_apprise](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_apprise/) | ▶️ | Apprise notification proxy | | | +| `ARPSCAN` | [arp_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/arp_scan/) | 🔍 | ARP-scan on current network | | | +| `AVAHISCAN` | [avahi_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/avahi_scan/) | 🆎 | Avahi (mDNS-based) name resolution | | | +| `ASUSWRT` | [asuswrt_import](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/asuswrt_import/) | 🔍 | Import connected devices from AsusWRT | | | +| `CSVBCKP` | [csv_backup](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/csv_backup/) | ⚙ | CSV devices backup | | | +| `CUSTPROP` | [custom_props](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/custom_props/) | ⚙ | Managing custom device properties values | | Yes | +| `DBCLNP` | [db_cleanup](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/db_cleanup/) | ⚙ | Database cleanup | | Yes\* | +| `DDNS` | [ddns_update](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/ddns_update/) | ⚙ | DDNS update | | | +| `DHCPLSS` | [dhcp_leases](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/dhcp_leases/) | 🔍/📥/🆎 | Import devices from DHCP leases | | | +| `DHCPSRVS` | [dhcp_servers](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/dhcp_servers/) | ♻ | DHCP servers | | | +| `DIGSCAN` | [dig_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/dig_scan/) | 🆎 | Dig (DNS) Name resolution | | | +| `FREEBOX` | [freebox](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/freebox/) | 🔍/♻/🆎 | Pull data and names from Freebox/Iliadbox | | | +| `ICMP` | [icmp_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/icmp_scan/) | ♻ | ICMP (ping) status checker | | | +| `INTRNT` | [internet_ip](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/internet_ip/) | 🔍 | Internet IP scanner | | | +| `INTRSPD` | [internet_speedtest](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/internet_speedtest/) | ♻ | Internet speed test | | | +| `IPNEIGH` | [ipneigh](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/ipneigh/) | 🔍 | Scan ARP (IPv4) and NDP (IPv6) tables | | | +| `LUCIRPC` | [luci_import](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/luci_import/) | 🔍 | Import connected devices from OpenWRT | | | +| `MAINT` | [maintenance](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/maintenance/) | ⚙ | Maintenance of logs, etc. | | | +| `MQTT` | [_publisher_mqtt](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_mqtt/) | ▶️ | MQTT for synching to Home Assistant | | | +| `NBTSCAN` | [nbtscan_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/nbtscan_scan/) | 🆎 | Nbtscan (NetBIOS-based) name resolution | | | +| `NEWDEV` | [newdev_template](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/newdev_template/) | ⚙ | New device template | | Yes | +| `NMAP` | [nmap_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/nmap_scan/) | ♻ | Nmap port scanning & discovery | | | +| `NMAPDEV` | [nmap_dev_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/nmap_dev_scan/) | 🔍 | Nmap dev scan on current network | | | +| `NSLOOKUP` | [nslookup_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/nslookup_scan/) | 🆎 | NSLookup (DNS-based) name resolution | | | +| `NTFPRCS` | [notification_processing](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/notification_processing/) | ⚙ | Notification processing | | Yes | +| `NTFY` | [_publisher_ntfy](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_ntfy/) | ▶️ | NTFY notifications | | | +| `OMDSDN` | [omada_sdn_imp](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/omada_sdn_imp/) | 📥/🆎 ❌ | UNMAINTAINED use `OMDSDNOPENAPI` | 🖧 🔄 | | +| `OMDSDNOPENAPI` | [omada_sdn_openapi](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/omada_sdn_openapi/) | 📥/🆎 | OMADA TP-Link import via OpenAPI | 🖧 | | +| `PIHOLE` | [pihole_scan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/pihole_scan/) | 🔍/🆎/📥 | Pi-hole device import & sync | | | +| `PUSHSAFER` | [_publisher_pushsafer](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_pushsafer/) | ▶️ | Pushsafer notifications | | | +| `PUSHOVER` | [_publisher_pushover](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_pushover/) | ▶️ | Pushover notifications | | | +| `SETPWD` | [set_password](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/set_password/) | ⚙ | Set password | | Yes | +| `SMTP` | [_publisher_email](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_email/) | ▶️ | Email notifications | | | +| `SNMPDSC` | [snmp_discovery](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/snmp_discovery/) | 🔍/📥 | SNMP device import & sync | | | +| `SYNC` | [sync](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/sync/) | 🔍/⚙/📥 | Sync & import from NetAlertX instances | 🖧 🔄 | Yes | +| `TELEGRAM` | [_publisher_telegram](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_telegram/) | ▶️ | Telegram notifications | | | +| `UI` | [ui_settings](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/ui_settings/) | ♻ | UI specific settings | | Yes | +| `UNFIMP` | [unifi_import](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/unifi_import/) | 🔍/📥/🆎 | UniFi device import & sync | 🖧 | | +| `VNDRPDT` | [vendor_update](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/vendor_update/) | ⚙ | Vendor database update | | | +| `WEBHOOK` | [_publisher_webhook](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/_publisher_webhook/) | ▶️ | Webhook notifications | | | +| `WEBMON` | [website_monitor](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/website_monitor/) | ♻ | Website down monitoring | | | +| `WOL` | [wake_on_lan](https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/wake_on_lan/) | ♻ | Automatic wake-on-lan | | | > \* The database cleanup plugin (`DBCLNP`) is not _required_ but the app will become unusable after a while if not executed. diff --git a/front/css/app.css b/front/css/app.css index 5fed0d7e..d3d85e97 100755 --- a/front/css/app.css +++ b/front/css/app.css @@ -1704,6 +1704,10 @@ input[readonly] { /* NETWORK page */ /* ----------------------------------------------------------------- */ +.hide-node-names .node-name { + display: none; + } + #toggleFilters { display: block; diff --git a/front/network.php b/front/network.php index 5d2c59aa..77af4110 100755 --- a/front/network.php +++ b/front/network.php @@ -107,6 +107,7 @@ const nodes = JSON.parse(data); renderNetworkTabs(nodes); loadUnassignedDevices(); + checkTabsOverflow(); }); } @@ -187,7 +188,7 @@
- +
${badgeHtml}
@@ -195,7 +196,7 @@
${isRootNode ? '' : ``} - + ${isRootNode ? getString('Network_Root') : getNameByMacAddress(node.parent_mac)} ${isRootNode ? '' : ``} @@ -264,16 +265,17 @@ } }, { - title: getString('Network_Table_State'), + title: getString('Device_TableHead_Status'), data: 'devStatus', width: '15%', render: function (_, type, device) { const badge = getStatusBadgeParts( device.devPresentLastScan, device.devAlertDown, - device.devMac + device.devMac, + device.devStatus ); - return `${badge.iconHtml} ${badge.status}`; + return `${badge.iconHtml} ${badge.text}`; } }, { @@ -287,6 +289,11 @@ data: 'devLastIP', width: '5%' }, + { + title: getString('Device_TableHead_Port'), + data: 'devParentPort', + width: '5%' + }, { title: getString('Device_TableHead_Vendor'), data: 'devVendor', @@ -319,7 +326,7 @@ // ---------------------------------------------------- function loadUnassignedDevices() { const sql = ` - SELECT devMac, devPresentLastScan, devName, devLastIP, devVendor, devAlertDown + SELECT devMac, devPresentLastScan, devName, devLastIP, devVendor, devAlertDown, devParentPort FROM Devices WHERE (devParentMAC IS NULL OR devParentMAC IN ("", " ", "undefined", "null")) AND devMac NOT LIKE "%internet%" @@ -348,14 +355,17 @@ // ---------------------------------------------------- function loadConnectedDevices(node_mac) { const sql = ` - SELECT devName, devMac, devLastIP, devVendor, devPresentLastScan, devAlertDown, - CASE - WHEN devAlertDown != 0 AND devPresentLastScan = 0 THEN "Down" - WHEN devPresentLastScan = 1 THEN "On-line" - ELSE "Off-line" - END as devStatus + SELECT devName, devMac, devLastIP, devVendor, devPresentLastScan, devAlertDown, devParentPort, + CASE + WHEN devIsNew = 1 THEN 'New' + WHEN devPresentLastScan = 1 THEN 'On-line' + WHEN devPresentLastScan = 0 AND devAlertDown != 0 THEN 'Down' + WHEN devIsArchived = 1 THEN 'Archived' + WHEN devPresentLastScan = 0 THEN 'Off-line' + ELSE 'Unknown status' + END AS devStatus FROM Devices - WHERE devIsArchived = 0 AND devParentMac = '${node_mac}'`; + WHERE devParentMac = '${node_mac}'`; const id = node_mac.replace(/:/g, '_'); @@ -895,6 +905,66 @@ function updateLeaf(leafMac, action) { } } +// --------------------------------------------------------------------------- +// showing icons or device names in tabs depending on available screen size +function checkTabsOverflow() { + const $ul = $('.nav-tabs'); + const $lis = $ul.find('li'); + + // First measure widths with current state + let totalWidth = 0; + $lis.each(function () { + totalWidth += $(this).outerWidth(true); + }); + + const ulWidth = $ul.width(); + const isOverflowing = totalWidth > ulWidth; + + if (isOverflowing) { + if (!$ul.hasClass('hide-node-names')) { + $ul.addClass('hide-node-names'); + + // Re-check: did hiding fix it? + requestAnimationFrame(() => { + let newTotal = 0; + $lis.each(function () { + newTotal += $(this).outerWidth(true); + }); + + if (newTotal > $ul.width()) { + // Still overflowing — do nothing, keep class + } + }); + } + } else { + if ($ul.hasClass('hide-node-names')) { + $ul.removeClass('hide-node-names'); + + // Re-check: did un-hiding break it? + requestAnimationFrame(() => { + let newTotal = 0; + $lis.each(function () { + newTotal += $(this).outerWidth(true); + }); + + if (newTotal > $ul.width()) { + // Oops, that broke it — re-hide + $ul.addClass('hide-node-names'); + } + }); + } + } +} + +let resizeTimeout; +$(window).on('resize', function () { + clearTimeout(resizeTimeout); + resizeTimeout = setTimeout(() => { + checkTabsOverflow(); + }, 100); +}); + + // init pop up hover boxes for device details initHoverNodeInfo(); diff --git a/front/php/templates/language/en_us.json b/front/php/templates/language/en_us.json index b27ee045..50b2f765 100755 --- a/front/php/templates/language/en_us.json +++ b/front/php/templates/language/en_us.json @@ -107,7 +107,7 @@ "DevDetail_Network_Node_hover": "Select the parent network device the current device is connected to, to populate the Network tree.", "DevDetail_Network_Port_hover": "The port this device is connected to on the parent network device. If left empty a wifi icon is displayed in the Network tree.", "DevDetail_Nmap_Scans": "Manual Nmap Scans", - "DevDetail_Nmap_Scans_desc": "Here you can execute manual NMAP scans. You can also schedule regular automatic NMAP scans via the Services & Ports (NMAP) plugin. Head to Settings to find out more", + "DevDetail_Nmap_Scans_desc": "Here you can execute manual NMAP scans. You can also schedule regular automatic NMAP scans via the Services & Ports (NMAP) plugin. Head to Docs to find out more", "DevDetail_Nmap_buttonDefault": "Default Scan", "DevDetail_Nmap_buttonDefault_text": "Default Scan: Nmap scans the top 1,000 ports for each scan protocol requested. This catches roughly 93% of the TCP ports and 49% of the UDP ports. (about 5 seconds)", "DevDetail_Nmap_buttonDetail": "Detailed Scan", diff --git a/server/scan/session_events.py b/server/scan/session_events.py index bd0b166a..2ab3c304 100755 --- a/server/scan/session_events.py +++ b/server/scan/session_events.py @@ -131,38 +131,51 @@ def void_ghost_disconnections (db): #------------------------------------------------------------------------------- def pair_sessions_events (db): + # db.commitDB() + sql = db.sql #TO-DO - + mylog('debug', '[Pair Session] - START') - # Pair Connection / New Device events - mylog('debug','[Pair Session] - 1 Connections / New Devices') - sql.execute ("""UPDATE Events - SET eve_PairEventRowid = - (SELECT ROWID - FROM Events AS EVE2 - WHERE EVE2.eve_EventType IN ('New Device', 'Connected', 'Down Reconnected', - 'Device Down', 'Disconnected') - AND EVE2.eve_MAC = Events.eve_MAC - AND EVE2.eve_Datetime > Events.eve_DateTime - ORDER BY EVE2.eve_DateTime ASC LIMIT 1) - WHERE eve_EventType IN ('New Device', 'Connected', 'Down Reconnected') - AND eve_PairEventRowid IS NULL - """ ) + # Step 1: Pair connection-related events with future unpaired disconnections + mylog('debug', '[Pair Session] - 1: Pair Connections → Disconnections') + sql.execute(""" + UPDATE Events + SET eve_PairEventRowid = ( + SELECT E2.ROWID + FROM Events AS E2 + WHERE E2.eve_EventType IN ('Disconnected', 'Device Down') + AND E2.eve_MAC = Events.eve_MAC + AND E2.eve_PairEventRowid IS NULL + AND E2.eve_DateTime > Events.eve_DateTime + ORDER BY E2.eve_DateTime ASC + LIMIT 1 + ) + WHERE eve_EventType IN ('New Device', 'Connected', 'Down Reconnected') + AND eve_PairEventRowid IS NULL + """) - # Pair Disconnection / Device Down - mylog('debug','[Pair Session] - 2 Disconnections') - sql.execute ("""UPDATE Events - SET eve_PairEventRowid = - (SELECT ROWID - FROM Events AS EVE2 - WHERE EVE2.eve_PairEventRowid = Events.ROWID) - WHERE eve_EventType IN ('Device Down', 'Disconnected') - AND eve_PairEventRowid IS NULL - """ ) - mylog('debug','[Pair Session] Pair session end') + # Step 2: Pair disconnection-related events with previous unpaired connections + mylog('debug', '[Pair Session] - 2: Pair Disconnections → Connections') + sql.execute(""" + UPDATE Events + SET eve_PairEventRowid = ( + SELECT E2.ROWID + FROM Events AS E2 + WHERE E2.eve_EventType IN ('New Device', 'Connected', 'Down Reconnected') + AND E2.eve_MAC = Events.eve_MAC + AND E2.eve_PairEventRowid IS NULL + AND E2.eve_DateTime < Events.eve_DateTime + ORDER BY E2.eve_DateTime DESC + LIMIT 1 + ) + WHERE eve_EventType IN ('Disconnected', 'Device Down') + AND eve_PairEventRowid IS NULL + """) + mylog('debug', '[Pair Session] - END') db.commitDB() + #------------------------------------------------------------------------------- def create_sessions_snapshot (db): sql = db.sql #TO-DO