Repository navigation
fix: JsonParser crash without dict config, EventID 0 without message - #359
Open
viktorbeck98 wants to merge 3 commits into
Open
viktorbeck98 wants to merge 3 commits into
viktorbeck98 wants to merge 3 commits into
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>
Contributor
|
@viktorbeck98 is that fine like this? "A log without a message and a message that matches no template now share -1" |
Collaborator
Author
|
@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>
Collaborator
Author
|
@thorinaboenke I addressed your comments |
This branch has not been deployed
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
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.