Skip to content

fix(caddy-logs): parse OPNsense bracketless JSON lines - #1991

Open
hrithiksaini99 wants to merge 1 commit into
crowdsecurity:masterfrom
hrithiksaini99:fix/1935-caddy-bracketless-json
Open

hrithiksaini99 wants to merge 1 commit into
crowdsecurity:masterfrom
hrithiksaini99:fix/1935-caddy-bracketless-json

Conversation

@hrithiksaini99

@hrithiksaini99 hrithiksaini99 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When Caddy logs arrive via OPNsense syslog/journald, the daemon strips the leading {"level": prefix (leaving "info","ts":...), so UnmarshalJSON on the raw message fails and every such line is dropped.

Fix

In the parser filter, retry the parse against {"level": + message as a fallback, then {"level": + message + } in case a daemon also strips the trailing brace. The fixture line keeps its trailing }} (verified via json.loads: prepend-only repairs it, prepend+append does not), which is why prepend-only comes first. Intact lines are unaffected.

Verification

New bracketless fixture line in .tests/caddy-logs/ from the issue (IP anonymized) + parsed/http_path assertions; stage counts bumped. Verified with python json.loads: repaired line parses, raw line does not.

Fixes #1935.

The stripped line retains its trailing braces (resp_headers close +
root close), so a plain prefix repair works; appending '}' would
unbalance it. Try '{"level":' + message first, then the
appended variant for daemons that also strip the trailing brace.
@hrithiksaini99
hrithiksaini99 force-pushed the fix/1935-caddy-bracketless-json branch from d81aaae to ab3f698 Compare November 7, 2026 08:11

@sabban sabban left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thank you for your contribution!

  1. The test fails: UnmarshalJSON returns an error on bad JSON, which stops the filter, so the || fallbacks never run.
  2. Run cscli hubtest run caddy-logs and regenerate the asserts instead of editing them.
  3. Drop the appended-} variant: the issue's line keeps its closing brace.
  4. In #1935, could the reporter share the raw line (evt.Line.Raw) and acquisition config? Standard OPNsense syslog formats parse fine on master, so the prefix is likely lost before the parser.

@sabban sabban added the waiting-for-user Waiting for submitter answer regarding specific points in the PR label Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-user Waiting for submitter answer regarding specific points in the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser fails on OPNsense when syslog/journald strips outer brackets

2 participants