-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createst: Allow to exclude certain fields #2115
Closed
Nancyenos
wants to merge
1
commit into
OISF:master
from
Nancyenos:createst-Allow-to-exclude-certain-fields-v2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -226,17 +226,30 @@ def get_manipulated_list(): | |
mentioned in `skip_fields` variable. | ||
""" | ||
eve_path = os.path.join(test_dir, "output", "eve.json") | ||
exclude_fields = args["exclude_fields"].strip().split(",") if args["exclude_fields"] else [] | ||
allow_events = args["allow_events"].strip().split(",") if args["allow_events"] else [] | ||
|
||
def exclude_nested_fields(data, base_key=""): | ||
if isinstance(data, dict): | ||
filtered_data = {} | ||
for k, v in data.items(): | ||
full_key = f"{base_key}.{k}" if base_key else k | ||
if not any(full_key == excl or full_key.startswith(f"{excl}.") for excl in exclude_fields): | ||
filtered_data[k] = exclude_nested_fields(v, full_key) | ||
return filtered_data | ||
return data | ||
|
||
with open(eve_path, "r") as fp: | ||
content = fp.read() | ||
content_list = content.strip().split("\n") | ||
jcontent_list = [json.loads(e) for e in content_list] | ||
all_content_list = [] | ||
for e in jcontent_list: | ||
md = {k: v for k, v in e.items() if k not in skip_fields} | ||
md = exclude_nested_fields(e) | ||
|
||
if "event_type" in md and md["event_type"] == "stats": | ||
continue | ||
all_content_list.append(md) | ||
all_content_list.append(md) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit typo added space |
||
if allow_events: | ||
def_eve_content_list = [item for item in all_content_list if item["event_type"] in allow_events] | ||
if not def_eve_content_list: | ||
|
@@ -393,6 +406,8 @@ def parse_args(): | |
help="Adds a suricata.yaml to the test") | ||
parser.add_argument("--features", default=None, metavar="<features>", | ||
help="Adds specified features") | ||
parser.add_argument("--exclude-fields", nargs="?", default=None, | ||
help="Exclude specified fields from filter block") | ||
# add arg to allow stdout only | ||
args = parser.parse_args() | ||
|
||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
skip_fields
should till be used