-
Notifications
You must be signed in to change notification settings - Fork 334
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
Rule context can be modified within rule #526
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -852,3 +852,39 @@ def match_ipaddress(_): # pylint: disable=unused-variable | |
payload = load_and_classify_payload(toggled_config, service, entity, raw_record) | ||
|
||
assert_equal(len(new_rules_engine.process(payload)), 1) | ||
|
||
def test_rule_modify_context(self): | ||
"""Rules Engine - Testing Context Modification""" | ||
@rule(logs=['test_log_type_json_nested_with_data'], | ||
outputs=['s3:sample_bucket'], | ||
context={'assigned_user': 'not_set', 'assigned_policy': 'not_set2'}) | ||
def modify_context_test(rec, context): # pylint: disable=unused-variable | ||
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. you shouldn't need this |
||
"""Modify context rule""" | ||
context['assigned_user'] = 'valid_user' | ||
context['assigned_policy'] = 'valid_policy' | ||
return rec['application'] == 'web-app' | ||
|
||
kinesis_data = json.dumps({ | ||
'date': 'Dec 01 2016', | ||
'unixtime': '1483139547', | ||
'host': 'host1.web.prod.net', | ||
'application': 'web-app', | ||
'environment': 'prod', | ||
'data': { | ||
'category': 'web-server', | ||
'type': '1', | ||
'source': 'eu' | ||
} | ||
}) | ||
|
||
# prepare the payloads | ||
service, entity = 'kinesis', 'test_kinesis_stream' | ||
raw_record = make_kinesis_raw_record(entity, kinesis_data) | ||
payload = load_and_classify_payload(self.config, service, entity, raw_record) | ||
|
||
# process payloads | ||
alerts = self.rules_engine.process(payload) | ||
|
||
# alert tests | ||
assert_equal(alerts[0]['context']['assigned_user'], 'valid_user') | ||
assert_equal(alerts[0]['context']['assigned_policy'], 'valid_policy') |
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.
@javuto I know this isn't part of your changes, but can you get rid of this
except Exception:
line and just have this betry: ... except: ...
. This would get rid of that pylint disable message too