Skip to content

Commit

Permalink
Merge pull request #161 from ferozsalam/begin-alerter-migration
Browse files Browse the repository at this point in the history
Begin alerter refactoring and migration
  • Loading branch information
jertel authored May 16, 2021
2 parents 5bdab79 + 68fb1ba commit cd6416c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
Empty file added elastalert/alerters/__init__.py
Empty file.
10 changes: 5 additions & 5 deletions elastalert/opsgenie.py → elastalert/alerters/opsgenie.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import os.path
import requests

from .alerts import Alerter
from .alerts import BasicMatchString
from .util import EAException
from .util import elastalert_logger
from .util import lookup_es_key
from ..alerts import Alerter
from ..alerts import BasicMatchString
from ..util import EAException
from ..util import elastalert_logger
from ..util import lookup_es_key


class OpsGenieAlerter(Alerter):
Expand Down
4 changes: 2 additions & 2 deletions elastalert/zabbix.py → elastalert/alerters/zabbix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from pyzabbix import ZabbixSender, ZabbixMetric, ZabbixAPI

from .alerts import Alerter
from .util import elastalert_logger, EAException
from ..alerts import Alerter
from ..util import elastalert_logger, EAException


class ZabbixClient(ZabbixAPI):
Expand Down
4 changes: 2 additions & 2 deletions elastalert/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from . import alerts
from . import enhancements
from . import ruletypes
from .opsgenie import OpsGenieAlerter
from .alerters.opsgenie import OpsGenieAlerter
from .alerters.zabbix import ZabbixAlerter
from .util import dt_to_ts
from .util import dt_to_ts_with_format
from .util import dt_to_unix
Expand All @@ -27,7 +28,6 @@
from .util import ts_to_dt_with_format
from .util import unix_to_dt
from .util import unixms_to_dt
from .zabbix import ZabbixAlerter
from .yaml import read_yaml


Expand Down
33 changes: 32 additions & 1 deletion tests/alerts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
from elastalert.alerts import SlackAlerter
from elastalert.alerts import TelegramAlerter
from elastalert.loaders import FileRulesLoader
from elastalert.opsgenie import OpsGenieAlerter
from elastalert.alerters.opsgenie import OpsGenieAlerter
from elastalert.alerters.zabbix import ZabbixAlerter
from elastalert.alerts import VictorOpsAlerter
from elastalert.util import ts_add
from elastalert.util import ts_now
Expand Down Expand Up @@ -7156,3 +7157,33 @@ def test_thehive_alerter():
del actual_data['sourceRef']

assert expected_data == actual_data


def test_zabbix_basic():
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)
match = {
'@timestamp': '2021-01-01T00:00:00Z',
'somefield': 'foobarbaz'
}
with mock.patch('pyzabbix.ZabbixSender.send') as mock_zbx_send:
alert.alert([match])

zabbix_metrics = {
"host": "example.com",
"key": "example-key",
"value": "1",
"clock": 1609459200
}
alerter_args = mock_zbx_send.call_args.args
assert vars(alerter_args[0][0]) == zabbix_metrics

0 comments on commit cd6416c

Please sign in to comment.