Skip to content

Commit d2ebe0d

Browse files
committed
2 parents 4c0d5c7 + 686a713 commit d2ebe0d

6 files changed

Lines changed: 58 additions & 50 deletions

File tree

docs/PLUGINS_DEV.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ NetAlertX comes with a plugin system to feed events from third-party scripts int
3434

3535
### 🐛 Troubleshooting
3636
- **[Debugging Plugins](DEBUG_PLUGINS.md)** - Troubleshoot plugin issues
37-
- **[Plugin Examples](../front/plugins)** - Study existing plugins as reference implementations
37+
- **[Plugin Examples](https://github.com/netalertx/NetAlertX/tree/main/front/plugins)** - Study existing plugins as reference implementations
3838

3939
### 🎥 Video Tutorial
4040

front/js/network-api.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ function loadNetworkNodes() {
1717
const rawSql = `
1818
SELECT
1919
parent.devName AS node_name,
20-
parent.devMac AS node_mac,
20+
LOWER(parent.devMac) AS node_mac,
2121
parent.devPresentLastScan AS online,
2222
parent.devType AS node_type,
23-
parent.devParentMAC AS parent_mac,
23+
LOWER(parent.devParentMAC) AS parent_mac,
2424
parent.devIcon AS node_icon,
2525
parent.devAlertDown AS node_alert,
2626
COUNT(child.devMac) AS node_ports_count
@@ -116,6 +116,7 @@ function loadDeviceTable({ sql, containerSelector, tableId, wrapperHtml = null,
116116
orderable: false,
117117
width: '5%',
118118
render: function (mac) {
119+
// mac = mac.toLowerCase()
119120
const label = assignMode ? 'assign' : 'unassign';
120121
const btnClass = assignMode ? 'btn-primary' : 'btn-primary bg-red';
121122
const btnText = assignMode ? getString('Network_ManageAssign') : getString('Network_ManageUnassign');
@@ -204,7 +205,7 @@ function loadUnassignedDevices() {
204205
SELECT devMac, devPresentLastScan, devName, devLastIP, devVendor, devAlertDown, devParentPort
205206
FROM Devices
206207
WHERE (devParentMAC IS NULL OR devParentMAC IN ("", " ", "undefined", "null"))
207-
AND devMac NOT LIKE "%internet%"
208+
AND LOWER(devMac) NOT LIKE "%internet%"
208209
AND devIsArchived = 0
209210
ORDER BY devName ASC`;
210211

front/js/network-init.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ function initNetworkTopology() {
2121
// Always get all devices
2222
const rawSql = `
2323
SELECT *,
24+
LOWER(devMac) AS devMac,
25+
LOWER(devParentMAC) AS devParentMAC,
2426
CASE
25-
WHEN devAlertDown != 0 AND devPresentLastScan = 0 THEN "Down"
26-
WHEN devPresentLastScan = 1 THEN "On-line"
27-
ELSE "Off-line"
27+
WHEN devAlertDown != 0 AND devPresentLastScan = 0 THEN 'Down'
28+
WHEN devPresentLastScan = 1 THEN 'On-line'
29+
ELSE 'Off-line'
2830
END AS devStatus,
2931
CASE
3032
WHEN devType IN (${networkDeviceTypes}) THEN 1
@@ -33,6 +35,7 @@ function initNetworkTopology() {
3335
FROM Devices a
3436
`;
3537

38+
3639
const { token: apiToken, apiBase, authHeader } = getAuthContext();
3740

3841
// Verify token is available before making API call

front/js/network-tabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function renderNetworkTabContent(nodes) {
4949
$('.tab-content').empty();
5050

5151
nodes.forEach((node, i) => {
52-
const id = node.node_mac.replace(/:/g, '_');
52+
const id = node.node_mac.replace(/:/g, '_').toLowerCase();
5353

5454
const badge = getStatusBadgeParts(
5555
node.online,

front/plugins/website_monitor/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"display_name": [
1010
{
1111
"language_code": "en_us",
12-
"string": "Website monitor"
12+
"string": "Services & Web monitor"
1313
},
1414
{
1515
"language_code": "es_es",

server/models/device_instance.py

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -463,46 +463,49 @@ def getDeviceData(self, mac, period=""):
463463

464464
# Fetch device info + computed fields
465465
sql = f"""
466-
SELECT
467-
d.*,
468-
CASE
469-
WHEN d.devAlertDown != 0 AND d.devPresentLastScan = 0 THEN 'Down'
470-
WHEN d.devPresentLastScan = 1 THEN 'On-line'
471-
ELSE 'Off-line'
472-
END AS devStatus,
473-
474-
(SELECT COUNT(*) FROM Sessions
475-
WHERE ses_MAC = d.devMac AND (
476-
ses_DateTimeConnection >= {period_date_sql} OR
477-
ses_DateTimeDisconnection >= {period_date_sql} OR
478-
ses_StillConnected = 1
479-
)) AS devSessions,
480-
481-
(SELECT COUNT(*) FROM Events
482-
WHERE eve_MAC = d.devMac AND eve_DateTime >= {period_date_sql}
483-
AND eve_EventType NOT IN ('Connected','Disconnected')) AS devEvents,
484-
485-
(SELECT COUNT(*) FROM Events
486-
WHERE eve_MAC = d.devMac AND eve_DateTime >= {period_date_sql}
487-
AND eve_EventType = 'Device Down') AS devDownAlerts,
488-
489-
(SELECT CAST(MAX(0, SUM(
490-
julianday(IFNULL(ses_DateTimeDisconnection,'{now}')) -
491-
julianday(CASE WHEN ses_DateTimeConnection < {period_date_sql}
492-
THEN {period_date_sql} ELSE ses_DateTimeConnection END)
493-
) * 24) AS INT)
494-
FROM Sessions
495-
WHERE ses_MAC = d.devMac
496-
AND ses_DateTimeConnection IS NOT NULL
497-
AND (ses_DateTimeDisconnection IS NOT NULL OR ses_StillConnected = 1)
498-
AND (ses_DateTimeConnection >= {period_date_sql}
499-
OR ses_DateTimeDisconnection >= {period_date_sql} OR ses_StillConnected = 1)
500-
) AS devPresenceHours
501-
502-
FROM Devices d
503-
WHERE d.devMac = ? OR CAST(d.rowid AS TEXT) = ?
466+
SELECT
467+
d.*,
468+
LOWER(d.devMac) AS devMac,
469+
LOWER(d.devParentMAC) AS devParentMAC,
470+
CASE
471+
WHEN d.devAlertDown != 0 AND d.devPresentLastScan = 0 THEN 'Down'
472+
WHEN d.devPresentLastScan = 1 THEN 'On-line'
473+
ELSE 'Off-line'
474+
END AS devStatus,
475+
476+
(SELECT COUNT(*) FROM Sessions
477+
WHERE LOWER(ses_MAC) = LOWER(d.devMac) AND (
478+
ses_DateTimeConnection >= {period_date_sql} OR
479+
ses_DateTimeDisconnection >= {period_date_sql} OR
480+
ses_StillConnected = 1
481+
)) AS devSessions,
482+
483+
(SELECT COUNT(*) FROM Events
484+
WHERE LOWER(eve_MAC) = LOWER(d.devMac) AND eve_DateTime >= {period_date_sql}
485+
AND eve_EventType NOT IN ('Connected','Disconnected')) AS devEvents,
486+
487+
(SELECT COUNT(*) FROM Events
488+
WHERE LOWER(eve_MAC) = LOWER(d.devMac) AND eve_DateTime >= {period_date_sql}
489+
AND eve_EventType = 'Device Down') AS devDownAlerts,
490+
491+
(SELECT CAST(MAX(0, SUM(
492+
julianday(IFNULL(ses_DateTimeDisconnection,'{now}')) -
493+
julianday(CASE WHEN ses_DateTimeConnection < {period_date_sql}
494+
THEN {period_date_sql} ELSE ses_DateTimeConnection END)
495+
) * 24) AS INT)
496+
FROM Sessions
497+
WHERE LOWER(ses_MAC) = LOWER(d.devMac)
498+
AND ses_DateTimeConnection IS NOT NULL
499+
AND (ses_DateTimeDisconnection IS NOT NULL OR ses_StillConnected = 1)
500+
AND (ses_DateTimeConnection >= {period_date_sql}
501+
OR ses_DateTimeDisconnection >= {period_date_sql} OR ses_StillConnected = 1)
502+
) AS devPresenceHours
503+
504+
FROM Devices d
505+
WHERE LOWER(d.devMac) = LOWER(?) OR CAST(d.rowid AS TEXT) = ?
504506
"""
505507

508+
506509
conn = get_temp_db_connection()
507510
cur = conn.cursor()
508511
cur.execute(sql, (mac, mac))
@@ -818,9 +821,9 @@ def updateDeviceColumn(self, mac, column_name, column_value):
818821
conn = get_temp_db_connection()
819822
cur = conn.cursor()
820823

821-
# Build safe SQL with column name
822-
sql = f"UPDATE Devices SET {column_name}=? WHERE devMac=?"
823-
cur.execute(sql, (column_value, mac))
824+
# Convert the MAC to lowercase for comparison
825+
sql = f"UPDATE Devices SET {column_name}=? WHERE LOWER(devMac)=?"
826+
cur.execute(sql, (column_value, mac.lower()))
824827
conn.commit()
825828

826829
if cur.rowcount > 0:
@@ -831,6 +834,7 @@ def updateDeviceColumn(self, mac, column_name, column_value):
831834
conn.close()
832835
return result
833836

837+
834838
def lockDeviceField(self, mac, field_name):
835839
"""Lock a device field so it won't be overwritten by plugins."""
836840
if field_name not in FIELD_SOURCE_MAP:

0 commit comments

Comments
 (0)