Skip to content

Commit

Permalink
Merge pull request #224 from nsano-rururu/bugfix_chatwork
Browse files Browse the repository at this point in the history
Fix chatwork alerter
  • Loading branch information
jertel authored Jun 4, 2021
2 parents 2455b74 + 803de30 commit 5adbd43
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions elastalert/alerters/chatwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class ChatworkAlerter(Alerter):

def __init__(self, rule):
super(ChatworkAlerter, self).__init__(rule)
self.chatwork_apikey = self.rule.get('chatwork_apikey')
self.chatwork_room_id = self.rule.get('chatwork_room_id')
self.chatwork_apikey = self.rule['chatwork_apikey']
self.chatwork_room_id = self.rule['chatwork_room_id']
self.url = 'https://api.chatwork.com/v2/rooms/%s/messages' % (self.chatwork_room_id)
self.chatwork_proxy = self.rule.get('chatwork_proxy', None)
self.chatwork_proxy_login = self.rule.get('chatwork_proxy_login', None)
Expand Down
54 changes: 54 additions & 0 deletions tests/alerters/chatwork_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,57 @@ def test_chatwork_ea_exception():
alert.alert([match])
except EAException:
assert True


def test_chatwork_getinfo():
rule = {
'name': 'Test Chatwork Rule',
'type': 'any',
'chatwork_apikey': 'xxxx1',
'chatwork_room_id': 'xxxx2',
'alert': []
}
rules_loader = FileRulesLoader({})
rules_loader.load_modules(rule)
alert = ChatworkAlerter(rule)

expected_data = {
"type": "chatwork",
"chatwork_room_id": "xxxx2"
}
actual_data = alert.get_info()
assert expected_data == actual_data


@pytest.mark.parametrize('chatwork_apikey, chatwork_room_id, expected_data', [
('', '', True),
('xxxx1', '', True),
('', 'xxxx2', True),
('xxxx1', 'xxxx2',
{
"type": "chatwork",
"chatwork_room_id": "xxxx2"
}),
])
def test_chatwork_key_error(chatwork_apikey, chatwork_room_id, expected_data):
try:
rule = {
'name': 'Test Chatwork Rule',
'type': 'any',
'alert': []
}

if chatwork_apikey != '':
rule['chatwork_apikey'] = chatwork_apikey

if chatwork_room_id != '':
rule['chatwork_room_id'] = chatwork_room_id

rules_loader = FileRulesLoader({})
rules_loader.load_modules(rule)
alert = ChatworkAlerter(rule)

actual_data = alert.get_info()
assert expected_data == actual_data
except KeyError:
assert expected_data

0 comments on commit 5adbd43

Please sign in to comment.