-
Notifications
You must be signed in to change notification settings - Fork 288
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
Don't overwrite self.teams
upon parsing responders in OpsGenie integration
#1539
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e3c2298
Update opsgenie.py
lstyles de111ac
Merge pull request #1 from lstyles/lstyles-patch-1
lstyles 7bc8993
fixes, spelling corrections and tests for parsing of opsgenie teams a…
lstyles 762d3a6
Merge branch 'master' into master
lstyles c96e53c
Update opsgenie.py
lstyles 21d6f33
Update alerts.rst
lstyles 6913731
updated rule config option `opsgenie_default_recipients to correct sp…
lstyles 65b7630
updated CHANGELOG
lstyles 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
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 |
---|---|---|
|
@@ -105,21 +105,23 @@ def test_opsgenie_alert_routing(): | |
'opsgenie_key': 'ogkey', | ||
'opsgenie_account': 'genies', | ||
'opsgenie_addr': 'https://api.opsgenie.com/v2/alerts', | ||
'opsgenie_recipients': ['{RECEIPIENT_PREFIX}'], | ||
'opsgenie_recipients_args': {'RECEIPIENT_PREFIX': 'recipient'}, | ||
'opsgenie_recipients': ['{RECIPIENT_PREFIX}'], | ||
'opsgenie_recipients_args': {'RECIPIENT_PREFIX': 'recipient'}, | ||
'type': mock_rule(), | ||
'filter': [{'query': {'query_string': {'query': '*hihi*'}}}], | ||
'alert': 'opsgenie', | ||
'opsgenie_teams': ['{TEAM_PREFIX}-Team'], | ||
'opsgenie_teams_args': {'TEAM_PREFIX': 'team'} | ||
} | ||
with mock.patch('requests.post'): | ||
|
||
with mock.patch('requests.post') as mock_post: | ||
alert = OpsGenieAlerter(rule) | ||
alert.alert([{'@timestamp': '2014-10-31T00:00:00', 'team': "Test", 'recipient': "lytics"}]) | ||
|
||
assert alert.get_info()['teams'] == ['Test-Team'] | ||
assert alert.get_info()['recipients'] == ['lytics'] | ||
_, kwargs = mock_post.call_args | ||
payload = kwargs['json'] | ||
|
||
assert payload['teams'][0]['name'] == 'Test-Team' | ||
assert payload['responders'][0]['username'] == 'lytics' | ||
|
||
|
||
def test_opsgenie_default_alert_routing(): | ||
|
@@ -128,22 +130,24 @@ def test_opsgenie_default_alert_routing(): | |
'opsgenie_key': 'ogkey', | ||
'opsgenie_account': 'genies', | ||
'opsgenie_addr': 'https://api.opsgenie.com/v2/alerts', | ||
'opsgenie_recipients': ['{RECEIPIENT_PREFIX}'], | ||
'opsgenie_recipients_args': {'RECEIPIENT_PREFIX': 'recipient'}, | ||
'opsgenie_recipients': ['{RECIPIENT_PREFIX}'], | ||
'opsgenie_recipients_args': {'RECIPIENT_PREFIX': 'recipient'}, | ||
'type': mock_rule(), | ||
'filter': [{'query': {'query_string': {'query': '*hihi*'}}}], | ||
'alert': 'opsgenie', | ||
'opsgenie_teams': ['{TEAM_PREFIX}-Team'], | ||
'opsgenie_default_receipients': ["[email protected]"], | ||
'opsgenie_default_teams': ["Test"] | ||
'opsgenie_default_recipients': ["[email protected]"], | ||
'opsgenie_default_teams': ["Default-Team"] | ||
} | ||
with mock.patch('requests.post'): | ||
with mock.patch('requests.post') as mock_post: | ||
|
||
alert = OpsGenieAlerter(rule) | ||
alert.alert([{'@timestamp': '2014-10-31T00:00:00', 'team': "Test"}]) | ||
|
||
assert alert.get_info()['teams'] == ['{TEAM_PREFIX}-Team'] | ||
assert alert.get_info()['recipients'] == ['[email protected]'] | ||
_, kwargs = mock_post.call_args | ||
payload = kwargs['json'] | ||
assert payload['teams'][0]['name'] == 'Default-Team' | ||
assert payload['responders'][0]['username'] == '[email protected]' | ||
|
||
|
||
def test_opsgenie_details_with_constant_value(): | ||
|
@@ -1006,8 +1010,8 @@ def test_opsgenie_parse_responders(caplog): | |
'opsgenie_key': 'ogkey', | ||
'opsgenie_account': 'genies', | ||
'opsgenie_addr': 'https://api.opsgenie.com/v2/alerts', | ||
'opsgenie_recipients': ['{RECEIPIENT_PREFIX}'], | ||
'opsgenie_recipients_args': {'RECEIPIENT_PREFIX': 'recipient'}, | ||
'opsgenie_recipients': ['{RECIPIENT_PREFIX}'], | ||
'opsgenie_recipients_args': {'RECIPIENT_PREFIX': 'recipient'}, | ||
'type': mock_rule(), | ||
'filter': [{'query': {'query_string': {'query': '*hihi*'}}}], | ||
'alert': 'opsgenie', | ||
|
@@ -1040,7 +1044,7 @@ def test_opsgenie_parse_responders(caplog): | |
assert expected == actual | ||
user, level, message = caplog.record_tuples[0] | ||
assert logging.WARNING == level | ||
assert "Cannot create responder for OpsGenie Alert. Key not foud: 'RECEIPIENT_PREFIX'." in message | ||
assert "Cannot create responder for OpsGenie Alert. Key not found: 'RECIPIENT_PREFIX'." in message | ||
user, level, message = caplog.record_tuples[1] | ||
assert logging.WARNING == level | ||
assert 'no responders can be formed. Trying the default responder' in message | ||
|
@@ -1049,12 +1053,79 @@ def test_opsgenie_parse_responders(caplog): | |
assert 'default responder not set. Falling back' in message | ||
user, level, message = caplog.record_tuples[3] | ||
assert logging.WARNING == level | ||
assert "Cannot create responder for OpsGenie Alert. Key not foud: 'TEAM_PREFIX'." in message | ||
assert "Cannot create responder for OpsGenie Alert. Key not found: 'TEAM_PREFIX'." in message | ||
user, level, message = caplog.record_tuples[4] | ||
assert logging.WARNING == level | ||
assert 'no responders can be formed. Trying the default responder' in message | ||
|
||
|
||
def test_opsgenie_parse_opsgenie_teams(): | ||
rule = { | ||
'name': 'testOGalert', | ||
'opsgenie_key': 'ogkey', | ||
'opsgenie_account': 'genies', | ||
'opsgenie_addr': 'https://api.opsgenie.com/v2/alerts', | ||
'type': mock_rule(), | ||
'filter': [{'query': {'query_string': {'query': '*hihi*'}}}], | ||
'alert': 'opsgenie', | ||
'opsgenie_teams': ['{TEAM_PREFIX}-Team'], | ||
'opsgenie_teams_args': {'TEAM_PREFIX': 'team'}, | ||
'opsgenie_default_teams': ["Test"] | ||
} | ||
match = [ | ||
{ | ||
'@timestamp': '2014-10-10T00:00:00', | ||
'sender_ip': '1.1.1.1', | ||
'hostname': 'aProbe', | ||
'team': 'Test' | ||
}, | ||
{ | ||
'@timestamp': '2014-10-10T00:00:00', | ||
'sender_ip': '1.1.1.1', | ||
'hostname2': 'aProbe', | ||
'team': 'Test' | ||
} | ||
] | ||
|
||
with mock.patch('requests.post'): | ||
alert = OpsGenieAlerter(rule) | ||
alert.alert(match) | ||
assert alert.teams == rule['opsgenie_teams'] | ||
|
||
|
||
def test_opsgenie_parse_opsgenie_recipients(): | ||
rule = { | ||
'name': 'testOGalert', | ||
'opsgenie_key': 'ogkey', | ||
'opsgenie_account': 'genies', | ||
'opsgenie_addr': 'https://api.opsgenie.com/v2/alerts', | ||
'opsgenie_recipients': ['{RECIPIENT_PREFIX}'], | ||
'opsgenie_recipients_args': {'RECIPIENT_PREFIX': 'recipient'}, | ||
'type': mock_rule(), | ||
'filter': [{'query': {'query_string': {'query': '*hihi*'}}}], | ||
'alert': 'opsgenie' | ||
} | ||
match = [ | ||
{ | ||
'@timestamp': '2014-10-10T00:00:00', | ||
'sender_ip': '1.1.1.1', | ||
'hostname': 'aProbe', | ||
'recipient': 'Test' | ||
}, | ||
{ | ||
'@timestamp': '2014-10-10T00:00:00', | ||
'sender_ip': '1.1.1.1', | ||
'hostname2': 'aProbe', | ||
'recipient': 'Test' | ||
} | ||
] | ||
|
||
with mock.patch('requests.post'): | ||
alert = OpsGenieAlerter(rule) | ||
alert.alert(match) | ||
assert alert.recipients == rule['opsgenie_recipients'] | ||
|
||
|
||
def test_opsgenie_create_custom_title(): | ||
rule = { | ||
'name': 'Opsgenie Details', | ||
|
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.
The top two lines prevent other tests from failing as missing
responder_args
no longer skips the execution.The bottom two lines fix a scenario where
responders
contains a placeholder, butresponders_args
isn't configured in a rule at all. Previously, a text with placeholder would end up as a responder. Now, a warning will be shown anddefault_responders
will be used instead.