feat: where a host's logs go beyond it (4.31.0) #95

Merged
christianmanivong merged 2 commits from feat/log-forwarding-2053 into main 2026-11-06 10:14:20 +00:00
Showing only changes of commit b685b200cc - Show all commits
+47 -33
View File
@@ -99,37 +99,48 @@ def _uncomment(text: str) -> str:
return "".join(out)
def _pieces(text: str) -> list[str]:
"""Statements, ``{`` and ``}`` in order: a line runs on while a bracket is
open, and a brace outside one stands as a piece of its own."""
pieces: list[str] = []
current: list[str] = []
depth = 0
quoted = False
class _Pieces:
"""Cuts a configuration into statements, ``{`` and ``}``: a line runs on
while a bracket is open, and a brace outside one stands as a piece of its own."""
def close() -> None:
piece = "".join(current).strip()
def __init__(self) -> None:
self.pieces: list[str] = []
self.current: list[str] = []
self.depth = 0
self.quoted = False
def close(self) -> None:
piece = "".join(self.current).strip()
if piece:
pieces.append(piece)
current.clear()
self.pieces.append(piece)
self.current.clear()
for char in text:
def bracket(self, char: str) -> None:
if char in "([":
self.depth += 1
elif char in ")]":
self.depth = max(self.depth - 1, 0)
def feed(self, char: str) -> None:
if char == '"':
quoted = not quoted
elif not quoted and char in "([":
depth += 1
elif not quoted and char in ")]":
depth = max(depth - 1, 0)
elif not quoted and depth == 0 and char in "{}":
close()
pieces.append(char)
continue
elif char == "\n" and depth == 0:
close()
continue
current.append(char)
close()
return pieces
self.quoted = not self.quoted
elif not self.quoted:
self.bracket(char)
if self.depth == 0 and char in "{}\n":
self.close()
if char != "\n":
self.pieces.append(char)
return
self.current.append(char)
def _pieces(text: str) -> list[str]:
"""Statements, ``{`` and ``}`` in order (:class:`_Pieces`)."""
cutter = _Pieces()
for char in text:
cutter.feed(char)
cutter.close()
return cutter.pieces
def _params(args: str) -> dict[str, str]:
@@ -221,12 +232,15 @@ class _Reader:
{"path": params["file"], "ruleset": params.get("ruleset")}
)
elif name == "action":
selector = self.last_selector if before == "&" else (before or "*.*")
self.last_selector = selector
kind = params.get("type", "")
if kind in _FORWARD_TYPES and params.get("target"):
protocol = "relp" if kind == "omrelp" else params.get("protocol", "udp").lower()
self.forward(protocol, params["target"], _port(params.get("port")), selector, once)
self.action(params, before, once)
def action(self, params: dict[str, str], before: str, once: str | None) -> None:
selector = self.last_selector if before == "&" else (before or "*.*")
self.last_selector = selector
kind = params.get("type", "")
if kind in _FORWARD_TYPES and params.get("target"):
protocol = "relp" if kind == "omrelp" else params.get("protocol", "udp").lower()
self.forward(protocol, params["target"], _port(params.get("port")), selector, once)
def module(self, name: str) -> None:
if name == "imjournal":