fix(backend): parse CLI command string into RouterOS API command + args

execute_cli was passing the full CLI string (e.g. '/ping address=8.8.8.8
count=4') as a single command to the Go poller. go-routeros expects the
command path and args separately. Now splits into command + prefixed args.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jason Staack
2026-03-09 22:05:05 -05:00
parent 394be01145
commit 837ab6f8fa

View File

@@ -143,8 +143,8 @@ async def remove_entry(
async def execute_cli(device_id: str, cli_command: str) -> dict[str, Any]: async def execute_cli(device_id: str, cli_command: str) -> dict[str, Any]:
"""Execute an arbitrary RouterOS CLI command. """Execute an arbitrary RouterOS CLI command.
For commands that don't follow the standard /path/action pattern. Parses a CLI-style string like '/ping address=8.8.8.8 count=4' into the
The command is sent as-is to the RouterOS API. RouterOS API command ('/ping') and args (['=address=8.8.8.8', '=count=4']).
Args: Args:
device_id: Device UUID. device_id: Device UUID.
@@ -153,7 +153,16 @@ async def execute_cli(device_id: str, cli_command: str) -> dict[str, Any]:
Returns: Returns:
Command response dict. Command response dict.
""" """
return await execute_command(device_id, cli_command) parts = cli_command.strip().split()
command = parts[0]
# RouterOS API args need '=' prefix: 'address=8.8.8.8' -> '=address=8.8.8.8'
args = []
for p in parts[1:]:
if "=" in p and not p.startswith("="):
args.append(f"={p}")
else:
args.append(p)
return await execute_command(device_id, command, args=args if args else None)
async def close() -> None: async def close() -> None: