diff --git a/manager/app.py b/manager/app.py index 2d8ae1e..61f31f9 100644 --- a/manager/app.py +++ b/manager/app.py @@ -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)) diff --git a/manager/db.py b/manager/db.py index 5ca777e..c34bf4f 100644 --- a/manager/db.py +++ b/manager/db.py @@ -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)