Feat/brain parser - #283
Open
Leokaufi wants to merge 5 commits into
Open
Conversation
Ports Brain's tuple-tree template-derivation core (get_frequecy_vector, tuple_generate, tupletree.find_root/up_split/down_split, output_result) into an in-memory, file-I/O-free form: no CSV/argparse/print, just a LogParser.parse(contents: list[str]) -> list[str]) entry point. The algorithm itself, including its known quirks, is kept faithful to upstream.
Bridges Brain's batch algorithm into the streaming CoreParser lifecycle: train() buffers each log's content (stripped of log_format headers, same as run() does for parse()); post_train() runs Brain once over the buffer to derive a template set and builds a TemplateMatcher from it; parse() then looks templates up per-log via that matcher instead of re-running Brain. No further templates are learned once training ends.
Covers config/type wiring, the pre-training fallback, the train -> post_train -> parse lifecycle end-to-end on synthetic logs, and the vendored Brain engine directly.
…ining Adds a training corpus with two genuinely different log shapes and asserts each gets its own template + EventID, and a detect-phase log that matches neither template, asserting the "<Not Found>"/EventID=-1 fallback fires via TemplateMatcher's own no-match path (matcher already built), not the earlier "training not finished yet" fallback branch.
ipmach
requested changes
Aug 26, 2026
ipmach
left a comment
Contributor
There was a problem hiding this comment.
This is an apache license, we cannot simple added it, also Brain from logpai is really slow and not great. We can make our own much faster in DetectMatePerformance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task
Description
Integrates the Brain log-parsing algorithm (logpai/logparser, Apache-2.0)
into the library as a new
BrainParser.parsers/brain/engine/): the Brain algorithm, file-I/Ostripped, exposes
parse(list[str]) -> list[str]. Apache-2.0 license keptalongside the code.
parsers/brain/parser.py):BrainParserbridges Brain (batch)into the streaming
CoreParserlifecycle —trainbuffers logs,post_trainruns Brain once and builds theTemplateMatcher,parselooksup each new log (falls back to
<Not Found>/ EventID -1 on no match).Known limitations (open for discussion)
<*>template that matches everything — unknown logs then aren't flagged asunknown. Workaround: train on homogeneous log groups.
event_idstored in the template manager (1-indexed) and theEventIDreturned by parse (0-indexed) are off by one — worth confirming whether
intended.
How Has This Been Tested?
Unit tests in
tests/test_parsers/test_brain_parser.py: multi-shape corpora,template-building after training, and the no-match-after-training fallback.
Full suite green, all prek hooks pass. Also verified template output against
upstream Brain on real auditd logs (AIT Log Data Set).
Checklist
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.