netx/netx_api/biz_state/parsers/common/lldp_neighbors.py
oliver 02b8a7073b Add TextFSM rule tables as dual input to biz-state parsers.
Collectors apply RULE_KEYS (or index stems) into fsm_tables before normalize; parsers prefer FSM or hand-parse.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 22:18:21 +08:00

41 lines
1.1 KiB
Python

"""LLDP neighbor normalize (multi-vendor via lldp_shared / TextFSM)."""
from __future__ import annotations
from typing import Any
from ....lldp_shared import NeighborHit, parse_neighbor_output
RULE_KEYS: tuple[str, ...] = ()
def normalize_lldp_neighbors(
*,
raw_text: str,
fsm_tables=None,
vendor: str = "",
device_type: str = "",
command: str = "",
params: dict[str, str] | None = None,
) -> list[dict[str, Any]]:
hits: list[NeighborHit] = parse_neighbor_output(
raw_text,
vendor=vendor,
device_type=device_type,
command=command,
)
_ = (params, fsm_tables)
rows: list[dict[str, Any]] = []
for h in hits:
rows.append(
{
"local_if": str(h.local_port or "").strip(),
"remote_sys": str(h.remote_name or "").strip(),
"remote_if": str(h.remote_port or "").strip(),
"remote_ip": str(h.remote_ip or "").strip(),
"protocol": str(h.protocol or "lldp").strip() or "lldp",
}
)
return rows
normalize_lldp_neighbors.RULE_KEYS = RULE_KEYS