/status/data endpoint fixes.

This commit is contained in:
Kalzu Rekku
2026-04-18 21:41:04 +03:00
parent c91e36b80a
commit c4524f9e15
2 changed files with 18 additions and 4 deletions

View File

@@ -215,12 +215,19 @@ def graph_data():
level = 1 level = 1
anon_ips = [] anon_ips = []
for iface in ifaces: for iface in ifaces:
addr_json = iface.get("addresses_json")
try: try:
addrs = json.loads(iface.get("addresses_json", "[]")) if addr_json is None:
except (json.JSONDecodeError, TypeError): addrs = []
else:
addrs = json.loads(addr_json)
if not isinstance(addrs, list):
addrs = []
except (json.JSONDecodeError, TypeError, AttributeError):
addrs = [] addrs = []
for addr in addrs: for addr in addrs:
ip_bare = addr.split("/")[0] ip_bare = addr.split("/")[0] if isinstance(addr, str) else str(addr)
if is_public_ip(ip_bare): if is_public_ip(ip_bare):
level = 0 level = 0
anon_ips.append(anonymize_ip(addr)) anon_ips.append(anonymize_ip(addr))

View File

@@ -71,7 +71,7 @@ def init_db():
agent_id TEXT NOT NULL, agent_id TEXT NOT NULL,
interface_name TEXT NOT NULL, interface_name TEXT NOT NULL,
mac_address TEXT, mac_address TEXT,
addresses_json TEXT, addresses_json TEXT NOT NULL DEFAULT '[]',
is_virtual INTEGER NOT NULL DEFAULT 0, is_virtual INTEGER NOT NULL DEFAULT 0,
vpn_type TEXT, vpn_type TEXT,
last_seen_at INTEGER NOT NULL, last_seen_at INTEGER NOT NULL,
@@ -92,6 +92,13 @@ def init_db():
CREATE INDEX IF NOT EXISTS idx_alarms_agent_status ON alarms(agent_id, status); CREATE INDEX IF NOT EXISTS idx_alarms_agent_status ON alarms(agent_id, status);
""") """)
conn.commit() conn.commit()
# Migration: backfill any NULL addresses_json from before the NOT NULL default
conn.execute("""
UPDATE agent_interfaces SET addresses_json = '[]'
WHERE addresses_json IS NULL
""")
conn.commit()
logger.info("Database initialized at %s", DB_PATH) logger.info("Database initialized at %s", DB_PATH)