Three of the four node colours mean "I could not read this"
A topology diagram built from `ip` and `docker` output on one host, where most of the design went into drawing what the tool failed to collect.
A topology diagram built from ip and docker output on one host, where most of the design went into drawing what the tool failed to collect.
What it renders, and from what
The tool is a Python script that runs on one gateway host and emits a single HTML file. No inventory, no API, no database — every fact on the diagram comes from four commands:
subprocess.check_output(["docker", "ps", "--format", "{{.Names}}"])
subprocess.check_output(["docker", "inspect", name])
subprocess.check_output(["docker", "exec", name, "ip", "-4", "a"])
# plus `ip -4 a show` on the host, for GRE tunnels
From docker inspect it takes two fields (HostConfig.NetworkMode, and the keys of NetworkSettings.Networks); from docker exec it takes interface names and addresses inside the container; from the host's ip output it takes GRE tunnels and, via each tunnel's master field, the bridge it is enslaved to.
pyvis (0.2.1, over vis.js) then draws it: the host as a box, bridges as circles, containers as ellipses, GRE tunnels as diamonds outside the box.
This needs drawing because no single command shows it. A gateway host carries a bridge and a VRF per partner, with GRE tunnels enslaved to the bridges (a /31 of link-local space each). docker network ls knows the bridges and nothing of GRE; ip a knows the tunnels and nothing of which container sits where. The join only exists in somebody's head.
The part that matters
A container's addresses are read by running ip inside it — which fails in three distinct ways:
except Exception:
return {"name": name, "ips": ["ERROR"], "network_mode": "inspect-failed", "bridges": []}
if network_mode == "host":
return {"name": name, "ips": ["HOST"], "network_mode": "host", "bridges": []}
except subprocess.CalledProcessError:
return {"name": name, "ips": ["unreachable"], "network_mode": network_mode, "bridges": bridges}
A host-mode container has no namespace of its own, so there is nothing to ask for. A minimal image ships no ip binary, so docker exec exits non-zero (CalledProcessError, never a timeout); docker inspect can fail outright on a container caught mid-restart.
Each gets a colour: red for host mode, orange for unreachable or inspect-failed, green for a container whose addresses were read. So three of the four states a container node can take describe collection, never topology. A diagram that silently omits what it could not read is worse than no diagram — it looks complete.
Note the asymmetry above. The unreachable case keeps bridges — docker inspect had already succeeded, so only the addresses are missing. The inspect-failed case returns an empty list, because nothing is known at all.
What did not work
The first version put presentation in Python (a diamond host node, a palette cycled per bridge, explicit sizes and borders on every add_node). It was replaced the same afternoon: plain box, no palette, 316 lines moved into a Jinja template. Styling inside pyvis calls means re-running collection to change a colour — and collection needs root on a production gateway.
The second failure was quieter. The original address parse was one regex over the whole ip -4 a output:
matches = re.findall(r'\d+:\s+(\S+).*?\n\s+inet\s+(\d+\.\d+\.\d+\.\d+)/\d+', output, re.DOTALL)
With re.DOTALL, the lazy .*? is free to cross interface boundaries. An interface with no v4 address does not break the match — it gets paired with the next interface's address, and the diagram shows a plausible wrong answer. The replacement walks line by line, tracking the current interface, and only attaches an address once one exists:
interface_match = re.match(r'^\d+:\s+(\S+)(?:@\S+)?:\s+', line)
if interface_match:
current_interface = interface_match.group(1)
continue
ip_match = re.match(r'^\s+inet\s+(\d+\.\d+\.\d+\.\d+)/\d+', line)
if ip_match and current_interface:
ip_list.append(f"{current_interface}:{ip}")
That is the same bug as an unaddressed interface crashing a C program (same cause, opposite symptom); a crash at least tells you something is wrong.
How it ran
A systemd unit mounting the Docker socket:
ExecStart=/usr/bin/docker run --name wireless-py-netwiz \
-v /var/run/docker.sock:/var/run/docker.sock \
--net=host \
registry.internal/playground/wireless-py-netviz:red
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/var/run/docker.sock
The hardening is real and beside the point: a process holding the Docker socket can start a privileged container whenever it likes. ProtectSystem=strict constrains the wrapper, never what the wrapper asks Docker to do. The unit is locked down everywhere that costs nothing; the exception is the one capability the tool exists to use.
Inside, a shell loop regenerates at midnight and serves /output over python3 -m http.server (8084, no auth).
Where it stopped
Multi-host aggregation got as far as a per-host JSON dump (network_data.json: hostname, timestamp, container counts) and no further. The code that would have merged those is a stash on a branch; a 786-line rewrite with a config module and a test file sits untracked on a laptop.
So it works, one host at a time, and never across the 49 where it would have mattered. A per-host diagram answers what is on this box; the question people kept asking was where a given tunnel goes.