/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
anon_ips = []
for iface in ifaces:
addr_json = iface.get("addresses_json")
try:
addrs = json.loads(iface.get("addresses_json", "[]"))
except (json.JSONDecodeError, TypeError):
if addr_json is None:
addrs = []
else:
addrs = json.loads(addr_json)
if not isinstance(addrs, list):
addrs = []
except (json.JSONDecodeError, TypeError, AttributeError):
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):
level = 0
anon_ips.append(anonymize_ip(addr))

View File

@@ -71,7 +71,7 @@ def init_db():
agent_id TEXT NOT NULL,
interface_name TEXT NOT NULL,
mac_address TEXT,
addresses_json TEXT,
addresses_json TEXT NOT NULL DEFAULT '[]',
is_virtual INTEGER NOT NULL DEFAULT 0,
vpn_type TEXT,
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);
""")
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)