Repository navigation
fix: JsonParser crash without dict config, EventID 0 without message - #359
Conversation
A JsonParserConfig object (or the default config) left the parser without a content parser, so the first log with a message field raised AttributeError. It now gets a MatcherParser without templates. Logs without a message field got EventID 0, the ID of the first template. They now get EventID -1 and the template <Not Found>, like any log that matches no template. Closes #357 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@viktorbeck98 is that fine like this? "A log without a message and a message that matches no template now share -1" |
|
@thorinaboenke we could also differentiate between the two cases. You're right, it's probably cleaner. We could use "-2" for when no message field is given |
Follow the schema field rename (#363) in the JsonParser fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A log without a message field now gets eventID -2 and an empty template, so it no longer shares -1 with a message that matches no template (and no longer triggers the template_not_found rule). A parser whose content parser has no templates logs one warning at the first message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@thorinaboenke I addressed your comments |
ipmach
left a comment
There was a problem hiding this comment.
Looks good, the only thing is about the -2. Should we connect this with other components as well? Or is just something from this parser.
For example, what happen when the template matcher does not receive templates because we are sending him Apache logs? Should those logs also have eventid -2?
Good point but let's come back to this when we encounter an issue with the -2 |
Task
Closes #357
Description
Two bugs in
JsonParser, both from the issue.1.
AttributeErrorwhen the config is not a dictionary. The content parser was only created insideif isinstance(config, dict):. WithJsonParser()or aJsonParserConfigobject the attribute never existed, and the first log with a message field crashed.MatcherParser()without templates, so the message comes back as<Not Found>/-1.2. Logs without a message field got
EventID 0.parse()started from a hardcoded0, which is also the ID of the first template.-1with the template<Not Found>, the same as a message that matches no template.Things to check when reviewing:
template_not_foundrule inrule_detector.pyalerts onEventID == -1, so it now fires for every JSON log without a message field.-1. If they should be told apart, that needs a separate ID.messagethat is a number, object or list raisesTypeError, and an empty,nullor0message is treated as no message.How Has This Been Tested?
test_parse_json_without_messageupdated: it asserted the oldEventID 0.-1for the log without a message and0for the first template.Checklist
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.