mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-06 10:11:58 -07:00
DevInstance and PluginObjectInstance expansion
This commit is contained in:
@@ -57,6 +57,44 @@ class DeviceInstance:
|
|||||||
result = self.db.sql.fetchone()
|
result = self.db.sql.fetchone()
|
||||||
return result["count"] > 0
|
return result["count"] > 0
|
||||||
|
|
||||||
|
# Get a device by its last IP address
|
||||||
|
def getByIP(self, ip):
|
||||||
|
self.db.sql.execute("SELECT * FROM Devices WHERE devLastIP = ?", (ip,))
|
||||||
|
row = self.db.sql.fetchone()
|
||||||
|
return dict(row) if row else None
|
||||||
|
|
||||||
|
# Search devices by partial mac, name or IP
|
||||||
|
def search(self, query):
|
||||||
|
like = f"%{query}%"
|
||||||
|
self.db.sql.execute(
|
||||||
|
"SELECT * FROM Devices WHERE devMac LIKE ? OR devName LIKE ? OR devLastIP LIKE ?",
|
||||||
|
(like, like, like),
|
||||||
|
)
|
||||||
|
rows = self.db.sql.fetchall()
|
||||||
|
return [dict(r) for r in rows]
|
||||||
|
|
||||||
|
# Get the most recently discovered device
|
||||||
|
def getLatest(self):
|
||||||
|
self.db.sql.execute("SELECT * FROM Devices ORDER BY devFirstConnection DESC LIMIT 1")
|
||||||
|
row = self.db.sql.fetchone()
|
||||||
|
return dict(row) if row else None
|
||||||
|
|
||||||
|
def getNetworkTopology(self):
|
||||||
|
"""Returns nodes and links for the current Devices table.
|
||||||
|
|
||||||
|
Nodes: {id, name, vendor}
|
||||||
|
Links: {source, target, port}
|
||||||
|
"""
|
||||||
|
self.db.sql.execute("SELECT devName, devMac, devParentMAC, devParentPort, devVendor FROM Devices")
|
||||||
|
rows = self.db.sql.fetchall()
|
||||||
|
nodes = []
|
||||||
|
links = []
|
||||||
|
for row in rows:
|
||||||
|
nodes.append({"id": row['devMac'], "name": row['devName'], "vendor": row['devVendor']})
|
||||||
|
if row['devParentMAC']:
|
||||||
|
links.append({"source": row['devParentMAC'], "target": row['devMac'], "port": row['devParentPort']})
|
||||||
|
return {"nodes": nodes, "links": links}
|
||||||
|
|
||||||
# Update a specific field for a device
|
# Update a specific field for a device
|
||||||
def updateField(self, devGUID, field, value):
|
def updateField(self, devGUID, field, value):
|
||||||
if not self.exists(devGUID):
|
if not self.exists(devGUID):
|
||||||
|
|||||||
@@ -37,6 +37,15 @@ class PluginObjectInstance:
|
|||||||
self.db.sql.execute("SELECT * FROM Plugins_Objects WHERE Plugin = ?", (plugin,))
|
self.db.sql.execute("SELECT * FROM Plugins_Objects WHERE Plugin = ?", (plugin,))
|
||||||
return self.db.sql.fetchall()
|
return self.db.sql.fetchall()
|
||||||
|
|
||||||
|
# Get plugin objects by primary ID and plugin name
|
||||||
|
def getByPrimary(self, plugin, primary_id):
|
||||||
|
self.db.sql.execute(
|
||||||
|
"SELECT * FROM Plugins_Objects WHERE Plugin = ? AND Object_PrimaryID = ?",
|
||||||
|
(plugin, primary_id),
|
||||||
|
)
|
||||||
|
rows = self.db.sql.fetchall()
|
||||||
|
return [dict(r) for r in rows]
|
||||||
|
|
||||||
# Get objects by status
|
# Get objects by status
|
||||||
def getByStatus(self, status):
|
def getByStatus(self, status):
|
||||||
self.db.sql.execute("SELECT * FROM Plugins_Objects WHERE Status = ?", (status,))
|
self.db.sql.execute("SELECT * FROM Plugins_Objects WHERE Status = ?", (status,))
|
||||||
|
|||||||
Reference in New Issue
Block a user