-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
add dingtalk and aiops alert #3240
Open
netkey
wants to merge
1
commit into
Yelp:master
Choose a base branch
from
netkey:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
Alert type not added to README.md and elastalert.rst |
The description of the alerter setting added to ruletypes.rst has not been added. |
No test code has been added. testcode example from elastalert.alerts import DingTalkAlerter
from elastalert.util import EAException
from requests import RequestException
def test_dingtalk():
rule = {
'name': 'Test DingTalk Rule',
'type': 'any',
'dingtalk_webhook': 'http://xxxxxxxxxx/xxxxxxxx',
'dingtalk_msgtype': 'text',
'alert': []
}
rules_loader = FileRulesLoader({})
rules_loader.load_modules(rule)
alert = DingTalkAlerter(rule)
match = {
'@timestamp': '2021-01-01T00:00:00',
'somefield': 'foobarbaz'
}
with mock.patch('requests.post') as mock_post_request:
alert.alert([match])
expected_data = {
'msgtype': 'text',
'text': {'content': 'Test DingTalk Rule\n\n@timestamp: 2021-01-01T00:00:00\nsomefield: foobarbaz\n'},
'at': {'isAtAll': False}
}
mock_post_request.assert_called_once_with(
'http://xxxxxxxxxx/xxxxxxxx',
data=mock.ANY,
headers={
'Content-Type': 'application/json',
'Accept': 'application/json;charset=utf-8'
},
)
actual_data = json.loads(mock_post_request.call_args_list[0][1]['data'])
assert expected_data == actual_data
def test_dingtalk_ea_exception():
with pytest.raises(EAException) as ea:
rule = {
'name': 'Test DingTalk Rule',
'type': 'any',
'dingtalk_webhook': 'http://xxxxxxxxxx/xxxxxxxx',
'dingtalk_msgtype': 'text',
'alert': []
}
rules_loader = FileRulesLoader({})
rules_loader.load_modules(rule)
alert = DingTalkAlerter(rule)
match = {
'@timestamp': '2021-01-01T00:00:00',
'somefield': 'foobarbaz'
}
mock_run = mock.MagicMock(side_effect=RequestException)
with mock.patch('requests.post', mock_run), pytest.raises(RequestException):
alert.alert([match])
assert 'Error request to Dingtalk: ' in str(ea)
def test_dingtalk_getinfo():
rule = {
'name': 'Test DingTalk Rule',
'type': 'any',
'dingtalk_webhook': 'http://xxxxxxxxxx/xxxxxxxx',
'dingtalk_msgtype': 'text',
'alert': [],
'alert_subject': 'Test DingTalk'
}
rules_loader = FileRulesLoader({})
rules_loader.load_modules(rule)
alert = DingTalkAlerter(rule)
expected_data = {
'type': 'dingtalk',
"dingtalk_webhook": 'http://xxxxxxxxxx/xxxxxxxx'
}
actual_data = alert.get_info()
assert expected_data == actual_data
@pytest.mark.parametrize('dingtalk_webhook, dingtalk_msgtype, expected_data', [
('x', '', 'Missing required option(s): dingtalk_webhook, dingtalk_msgtype'),
('', 'x', 'Missing required option(s): dingtalk_webhook, dingtalk_msgtype'),
])
def test_dingtalk_required_error(dingtalk_webhook, dingtalk_msgtype, expected_data):
try:
rule = {
'name': 'Test DingTalk Rule',
'type': 'any',
'alert': [],
'alert_subject': 'Test DingTalk'
}
if dingtalk_webhook:
rule['dingtalk_webhook'] = dingtalk_webhook
if dingtalk_msgtype:
rule['dingtalk_msgtype'] = dingtalk_msgtype
rules_loader = FileRulesLoader({})
rules_loader.load_modules(rule)
alert = DingTalkAlerter(rule)
actual_data = alert.get_info()
assert expected_data == actual_data
except Exception as ea:
assert expected_data in str(ea) |
lint error ./elastalert/alerts.py:2188:1: E302 expected 2 blank lines, found 1
./elastalert/alerts.py:2214:26: E231 missing whitespace after ':'
./elastalert/alerts.py:2219:25: E128 continuation line under-indented for visual indent
./elastalert/alerts.py:2220:25: E128 continuation line under-indented for visual indent
./elastalert/alerts.py:2232:1: E302 expected 2 blank lines, found 1
./elastalert/alerts.py:2253:1: W191 indentation contains tabs
./elastalert/alerts.py:2253:1: E101 indentation contains mixed spaces and tabs
./elastalert/alerts.py:2254:1: W191 indentation contains tabs
./elastalert/alerts.py:2254:1: E101 indentation contains mixed spaces and tabs
./elastalert/alerts.py:2255:1: W191 indentation contains tabs
./elastalert/alerts.py:2255:1: E101 indentation contains mixed spaces and tabs
./elastalert/alerts.py:2257:1: W191 indentation contains tabs
./elastalert/alerts.py:2257:1: E101 indentation contains mixed spaces and tabs
./elastalert/alerts.py:2261:25: E128 continuation line under-indented for visual indent
./elastalert/alerts.py:2262:25: E128 continuation line under-indented for visual indent
./elastalert/loaders.py:82:37: W291 trailing whitespace |
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.
add dingtalk and aiops alert