feat(plugins): Implement /plugins/stats endpoint for per-plugin row counts with optional foreignKey filtering

This commit is contained in:
Jokob @NetAlertX
2026-03-27 21:35:41 +00:00
parent b18cf98266
commit 3f80d2e57f
5 changed files with 180 additions and 34 deletions

View File

@@ -101,3 +101,31 @@ class PluginObjectInstance:
raise ValueError(msg)
self._execute("DELETE FROM Plugins_Objects WHERE objectGuid=?", (ObjectGUID,))
def getStats(self, foreign_key=None):
"""Per-plugin row counts across Objects, Events, and History tables.
Optionally scoped to a specific foreignKey (e.g. MAC address)."""
if foreign_key:
sql = """
SELECT 'objects' AS tableName, plugin, COUNT(*) AS cnt
FROM Plugins_Objects WHERE foreignKey = ? GROUP BY plugin
UNION ALL
SELECT 'events', plugin, COUNT(*)
FROM Plugins_Events WHERE foreignKey = ? GROUP BY plugin
UNION ALL
SELECT 'history', plugin, COUNT(*)
FROM Plugins_History WHERE foreignKey = ? GROUP BY plugin
"""
return self._fetchall(sql, (foreign_key, foreign_key, foreign_key))
else:
sql = """
SELECT 'objects' AS tableName, plugin, COUNT(*) AS cnt
FROM Plugins_Objects GROUP BY plugin
UNION ALL
SELECT 'events', plugin, COUNT(*)
FROM Plugins_Events GROUP BY plugin
UNION ALL
SELECT 'history', plugin, COUNT(*)
FROM Plugins_History GROUP BY plugin
"""
return self._fetchall(sql)