Skip to content
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

Fix zabbix alerter #227

Merged
merged 2 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/ruletypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2768,9 +2768,9 @@ Zabbix will send notification to a Zabbix server. The item in the host specified

Required:

``zbx_sender_host``: The address where zabbix server is running.
``zbx_sender_host``: The address where zabbix server is running, defaults to ``'localhost'``.

``zbx_sender_port``: The port where zabbix server is listenning.
``zbx_sender_port``: The port where zabbix server is listenning, defaults to ``10051``.

``zbx_host``: This field setup the host in zabbix that receives the value sent by ElastAlert 2.

Expand Down
4 changes: 2 additions & 2 deletions elastalert/alerters/zabbix.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def __init__(self, *args):

self.zbx_sender_host = self.rule.get('zbx_sender_host', 'localhost')
self.zbx_sender_port = self.rule.get('zbx_sender_port', 10051)
self.zbx_host = self.rule.get('zbx_host')
self.zbx_key = self.rule.get('zbx_key')
self.zbx_host = self.rule['zbx_host']
self.zbx_key = self.rule['zbx_key']
self.timestamp_field = self.rule.get('timestamp_field', '@timestamp')
self.timestamp_type = self.rule.get('timestamp_type', 'iso')
self.timestamp_strptime = self.rule.get('timestamp_strptime', '%Y-%m-%dT%H:%M:%S.%fZ')
Expand Down
57 changes: 57 additions & 0 deletions tests/alerters/zabbix_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import mock

from elastalert.alerters.zabbix import ZabbixAlerter
Expand Down Expand Up @@ -32,3 +33,59 @@ def test_zabbix_basic():
}
alerter_args = mock_zbx_send.call_args.args
assert vars(alerter_args[0][0]) == zabbix_metrics


def test_zabbix_getinfo():
rule = {
'name': 'Basic Zabbix test',
'type': 'any',
'alert_text_type': 'alert_text_only',
'alert': [],
'alert_subject': 'Test Zabbix',
'zbx_host': 'example.com',
'zbx_key': 'example-key'
}
rules_loader = FileRulesLoader({})
rules_loader.load_modules(rule)
alert = ZabbixAlerter(rule)

expected_data = {
'type': 'zabbix Alerter'
}
actual_data = alert.get_info()
assert expected_data == actual_data


@pytest.mark.parametrize('zbx_host, zbx_key, expected_data', [
('', '', True),
('example.com', '', True),
('', 'example-key', True),
('example.com', 'example-key',
{
'type': 'zabbix Alerter'
})
])
def test_zabbix_key_error(zbx_host, zbx_key, expected_data):
try:
rule = {
'name': 'Basic Zabbix test',
'type': 'any',
'alert_text_type': 'alert_text_only',
'alert': [],
'alert_subject': 'Test Zabbix'
}

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

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

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

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