-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update select_jsonpath to accept strings of JSON in addition to JsonN…
…ode objects (#17683) (#17896) * Update select_jsonpath to accept strings of JSON in addition to JsonNode objects * Add unit test * Add changelog entry * Update changelog with correct issue/pr --------- Co-authored-by: Zack King <91903901+kingzacko1@users.noreply.github.com>
- Loading branch information
1 parent
3a4a9ff
commit 56362c7
Showing
4 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type = "c" | ||
message = "Updated the select_jsonpath pipeline function to accept JSON strings as the `json` parameter in addition to parsed JsonNode objects." | ||
|
||
issues = ["17647"] | ||
pulls = ["17683"] |
This file contains 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
This file contains 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
23 changes: 23 additions & 0 deletions
23
...st/resources/org/graylog/plugins/pipelineprocessor/functions/jsonpathFromMessageField.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
rule "jsonpathFromMessageField" | ||
when | ||
is_json(parse_json("{}")) == true && | ||
is_json("foobar") == false && | ||
is_json(1234) == false && | ||
is_json(12.34) == false && | ||
is_json(true) == false | ||
then | ||
let new_fields = select_jsonpath($message.message, | ||
{ author_first: "$['store']['book'][0]['author']", | ||
author_last: "$['store']['book'][-1:]['author']" | ||
}); | ||
set_fields(new_fields); | ||
|
||
// Don't fail on empty input | ||
let invalid_json = parse_json("#FOOBAR#"); | ||
let invalid_json_fields = select_jsonpath(invalid_json, { some_field: "$.message" }); | ||
set_fields(invalid_json_fields); | ||
|
||
// Don't fail on missing field | ||
let missing_fields = select_jsonpath($message.message, { some_field: "$.i_dont_exist", this_should_exist: "$['store']['book'][-1:]['author']" }); | ||
set_fields(missing_fields); | ||
end |