621e8895c9
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3.0 KiB
3.0 KiB
name, kind, lang, domain, version, purity, signature, description, tags, params, output, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | params | output | uses_functions | uses_types | returns | returns_optional | error_type | imports | tested | tests | test_file_path | file_path | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wg_status | function | bash | infra | 1.0.0 | impure | wg_status([interface_name]) -> json | Parsea `wg show <iface> dump` a JSON estructurado con peers, handshake age, status (online/stale/never), bytes rx/tx. Resuelve device_id desde comentarios en wg0.conf. Para dashboards (agents_dashboard Mesh panel). |
|
|
JSON con interface info + array de peers. Cada peer incluye public_key, device_id (de comentario # DeviceID:<id> en wg0.conf), endpoint, allowed_ips, latest_handshake_unix, latest_handshake_ago_s, rx_bytes, tx_bytes, persistent_keepalive, status (online/stale/never). | false | error_go_core | true |
|
bash/functions/infra/wg_status_test.sh | bash/functions/infra/wg_status.sh |
Ejemplo
# Estado real de wg0
source bash/functions/infra/wg_status.sh
wg_status | jq .
# Interface distinta
wg_status wg1 | jq .peers[].status
# Sin sudo real (testing / CI)
WG_FAKE_DUMP=bash/functions/infra/wg_status_test_dump.tsv wg_status wg0 | jq .
Salida representativa:
{
"interface": "wg0",
"public_key": "abcXYZ123...",
"listen_port": "51820",
"peers": [
{
"public_key": "peerKey1...",
"device_id": "pc-aurgi",
"endpoint": "1.2.3.4:54321",
"allowed_ips": ["10.42.0.10/32"],
"latest_handshake_unix": 1716000000,
"latest_handshake_ago_s": 42,
"rx_bytes": 12345,
"tx_bytes": 67890,
"persistent_keepalive": 25,
"status": "online"
}
]
}
Cuando usarla
Cuando necesites saber el estado del mesh WireGuard desde un script, dashboard o agente. Usa antes de mostrar el panel Mesh en agents_dashboard. Llama cada N segundos para polling ligero desde shell sin depender de la API de WireGuard.
Gotchas
- Requiere
CAP_NET_ADMIN/ root:wg showfalla sin permisos. En produccion ejecutar viasudo -n wg show wg0 dumpo dar permiso al binario. Para tests sin sudo:WG_FAKE_DUMP=<path>carga el dump desde archivo. listen_portse devuelve como string (tal como lo emitewg show dump). El campo es"0"si wg no esta activo pero la interface existe.device_idqueda""si no hay comentario# DeviceID:<id>antes del[Peer]correspondiente en/etc/wireguard/<iface>.conf.- Status
stalecubre desde 180s hasta cualquier valor mayor. No hay distincion entre "hace 5 min" y "hace 3 dias" — ambos sonstale. Para un threshold mas fino, usarlatest_handshake_ago_sdirectamente. - Si
/etc/wireguard/<iface>.confno existe o no es legible,device_idsera""para todos los peers (la funcion no falla, solo omite el lookup).