Skip to content

Commit

Permalink
Version 0.1.30
Browse files Browse the repository at this point in the history
  • Loading branch information
Qmando committed May 3, 2018
1 parent a59e91f commit 87119b8
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 81 deletions.
20 changes: 19 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# Change Log

# v0.1.30

### Added
- Alerta alerter
- Added support for transitioning JIRA issues
- Option to recreate index in elastalert-create-index

### Fixed
- Update jira_ custom fields before each alert if they were modified
- Use json instead of simplejson
- Allow for relative path for smtp_auth_file
- Fixed some grammar issues
- Better code formatting of index mappings
- Better formatting and size limit for HipChat HTML
- Fixed gif link in readme for kibana plugin
- Fixed elastalert-test-rule with Elasticsearch > 4
- Added documentation for is_enabled option

## v0.1.29

###
### Added
- Added a feature forget_keys to prevent realerting when using flatline with query_key
- Added a new alert_text_type, aggregation_summary_only

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
base_dir = os.path.dirname(__file__)
setup(
name='elastalert',
version='0.1.29',
version='0.1.30',
description='Runs custom filters on Elasticsearch and alerts on matches',
author='Quentin Long',
author_email='[email protected]',
Expand Down
157 changes: 78 additions & 79 deletions tests/alerts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest
from jira.exceptions import JIRAError

from elastalert.alerts import AlertaAlerter
from elastalert.alerts import Alerter
from elastalert.alerts import BasicMatchString
from elastalert.alerts import CommandAlerter
Expand All @@ -20,10 +21,8 @@
from elastalert.alerts import PagerDutyAlerter
from elastalert.alerts import SlackAlerter
from elastalert.alerts import StrideAlerter
from elastalert.alerts import AlertaAlerter
from elastalert.config import load_modules
from elastalert.opsgenie import OpsGenieAlerter

from elastalert.util import ts_add
from elastalert.util import ts_now

Expand Down Expand Up @@ -1770,32 +1769,32 @@ def test_alerta_resolve_string(ea):
'temperature': 45,
'humidity': 80.56,
'sensors': ['outsideSensor', 'insideSensor']
}
}
rule = {
'name': 'Test Alerta rule!',
'alerta_api_url': 'http://elastalerthost:8080/api/alert'
}
'name': 'Test Alerta rule!',
'alerta_api_url': 'http://elastalerthost:8080/api/alert'
}

alert = AlertaAlerter(rule)

expected_outputs = [
"mySystem is online <MISSING VALUE>",
"Sensors ['outsideSensor', 'insideSensor'] in the <MISSING VALUE> have temp 45 and 80.56 humidity",
"Actuator <MISSING VALUE> in the <MISSING VALUE> has temp <MISSING VALUE>"]
"mySystem is online <MISSING VALUE>",
"Sensors ['outsideSensor', 'insideSensor'] in the <MISSING VALUE> have temp 45 and 80.56 humidity",
"Actuator <MISSING VALUE> in the <MISSING VALUE> has temp <MISSING VALUE>"]
old_style_strings = [
"%(name)s is online %(noKey)s",
"Sensors %(sensors)s in the %(noPlace)s have temp %(temperature)s and %(humidity)s humidity",
"Actuator %(noKey)s in the %(noPlace)s has temp %(noKey)s"]
"%(name)s is online %(noKey)s",
"Sensors %(sensors)s in the %(noPlace)s have temp %(temperature)s and %(humidity)s humidity",
"Actuator %(noKey)s in the %(noPlace)s has temp %(noKey)s"]

assert alert.resolve_string(old_style_strings[0], match) == expected_outputs[0]
assert alert.resolve_string(old_style_strings[1], match) == expected_outputs[1]
assert alert.resolve_string(old_style_strings[2], match) == expected_outputs[2]

alert.use_new_string_format = True
new_style_strings = [
"{match[name]} is online {match[noKey]}",
"Sensors {match[sensors]} in the {match[noPlace]} have temp {match[temperature]} and {match[humidity]} humidity",
"Actuator {match[noKey]} in the {match[noPlace]} has temp {match[noKey]}"]
"{match[name]} is online {match[noKey]}",
"Sensors {match[sensors]} in the {match[noPlace]} have temp {match[temperature]} and {match[humidity]} humidity",
"Actuator {match[noKey]} in the {match[noPlace]} has temp {match[noKey]}"]

assert alert.resolve_string(new_style_strings[0], match) == expected_outputs[0]
assert alert.resolve_string(new_style_strings[1], match) == expected_outputs[1]
Expand All @@ -1804,31 +1803,31 @@ def test_alerta_resolve_string(ea):

def test_alerta_no_auth(ea):
rule = {
'name': 'Test Alerta rule!',
'alerta_api_url': 'http://elastalerthost:8080/api/alert',
'timeframe': datetime.timedelta(hours=1),
'timestamp_field': u'@timestamp',
'alerta_attributes_keys': ["hostname", "TimestampEvent", "senderIP"],
'alerta_attributes_values': ["%(key)s", "%(logdate)s", "%(sender_ip)s"],
'alerta_correlate': ["ProbeUP", "ProbeDOWN"],
'alerta_event': "ProbeUP",
'alerta_group': "Health",
'alerta_origin': "Elastalert",
'alerta_severity': "debug",
'alerta_text': "Probe %(hostname)s is UP at %(logdate)s GMT",
'alerta_value': "UP",
'type': 'any',
'alerta_use_match_timestamp': True,
'alert': 'alerta'
}
'name': 'Test Alerta rule!',
'alerta_api_url': 'http://elastalerthost:8080/api/alert',
'timeframe': datetime.timedelta(hours=1),
'timestamp_field': u'@timestamp',
'alerta_attributes_keys': ["hostname", "TimestampEvent", "senderIP"],
'alerta_attributes_values': ["%(key)s", "%(logdate)s", "%(sender_ip)s"],
'alerta_correlate': ["ProbeUP", "ProbeDOWN"],
'alerta_event': "ProbeUP",
'alerta_group': "Health",
'alerta_origin': "Elastalert",
'alerta_severity': "debug",
'alerta_text': "Probe %(hostname)s is UP at %(logdate)s GMT",
'alerta_value': "UP",
'type': 'any',
'alerta_use_match_timestamp': True,
'alert': 'alerta'
}

match = {
u'@timestamp': '2014-10-10T00:00:00',
# 'key': ---- missing field on purpose, to verify that simply the text is left empty
# 'logdate': ---- missing field on purpose, to verify that simply the text is left empty
'sender_ip': '1.1.1.1',
'hostname': 'aProbe'
}
u'@timestamp': '2014-10-10T00:00:00',
# 'key': ---- missing field on purpose, to verify that simply the text is left empty
# 'logdate': ---- missing field on purpose, to verify that simply the text is left empty
'sender_ip': '1.1.1.1',
'hostname': 'aProbe'
}

load_modules(rule)
alert = AlertaAlerter(rule)
Expand All @@ -1852,7 +1851,7 @@ def test_alerta_no_auth(ea):
"attributes": {"senderIP": "1.1.1.1", "hostname": "<MISSING VALUE>", "TimestampEvent": "<MISSING VALUE>"},
"type": "elastalert",
"event": "ProbeUP"
}
}

mock_post_request.assert_called_once_with(
alert.url,
Expand All @@ -1866,22 +1865,22 @@ def test_alerta_no_auth(ea):

def test_alerta_auth(ea):
rule = {
'name': 'Test Alerta rule!',
'alerta_api_url': 'http://elastalerthost:8080/api/alert',
'alerta_api_key': '123456789ABCDEF',
'timeframe': datetime.timedelta(hours=1),
'timestamp_field': '@timestamp',
'alerta_severity': "debug",
'type': 'any',
'alerta_use_match_timestamp': True,
'alert': 'alerta'
}
'name': 'Test Alerta rule!',
'alerta_api_url': 'http://elastalerthost:8080/api/alert',
'alerta_api_key': '123456789ABCDEF',
'timeframe': datetime.timedelta(hours=1),
'timestamp_field': '@timestamp',
'alerta_severity': "debug",
'type': 'any',
'alerta_use_match_timestamp': True,
'alert': 'alerta'
}

match = {
'@timestamp': '2014-10-10T00:00:00',
'sender_ip': '1.1.1.1',
'hostname': 'aProbe'
}
'@timestamp': '2014-10-10T00:00:00',
'sender_ip': '1.1.1.1',
'hostname': 'aProbe'
}

load_modules(rule)
alert = AlertaAlerter(rule)
Expand All @@ -1898,32 +1897,32 @@ def test_alerta_auth(ea):

def test_alerta_new_style(ea):
rule = {
'name': 'Test Alerta rule!',
'alerta_api_url': 'http://elastalerthost:8080/api/alert',
'timeframe': datetime.timedelta(hours=1),
'timestamp_field': '@timestamp',
'alerta_attributes_keys': ["hostname", "TimestampEvent", "senderIP"],
'alerta_attributes_values': ["{match[hostname]}", "{match[logdate]}", "{match[sender_ip]}"],
'alerta_correlate': ["ProbeUP", "ProbeDOWN"],
'alerta_event': "ProbeUP",
'alerta_group': "Health",
'alerta_origin': "Elastalert",
'alerta_severity': "debug",
'alerta_text': "Probe {match[hostname]} is UP at {match[logdate]} GMT",
'alerta_value': "UP",
'alerta_new_style_string_format': True,
'type': 'any',
'alerta_use_match_timestamp': True,
'alert': 'alerta'
}
'name': 'Test Alerta rule!',
'alerta_api_url': 'http://elastalerthost:8080/api/alert',
'timeframe': datetime.timedelta(hours=1),
'timestamp_field': '@timestamp',
'alerta_attributes_keys': ["hostname", "TimestampEvent", "senderIP"],
'alerta_attributes_values': ["{match[hostname]}", "{match[logdate]}", "{match[sender_ip]}"],
'alerta_correlate': ["ProbeUP", "ProbeDOWN"],
'alerta_event': "ProbeUP",
'alerta_group': "Health",
'alerta_origin': "Elastalert",
'alerta_severity': "debug",
'alerta_text': "Probe {match[hostname]} is UP at {match[logdate]} GMT",
'alerta_value': "UP",
'alerta_new_style_string_format': True,
'type': 'any',
'alerta_use_match_timestamp': True,
'alert': 'alerta'
}

match = {
'@timestamp': '2014-10-10T00:00:00',
# 'key': ---- missing field on purpose, to verify that simply the text is left empty
# 'logdate': ---- missing field on purpose, to verify that simply the text is left empty
'sender_ip': '1.1.1.1',
'hostname': 'aProbe'
}
'@timestamp': '2014-10-10T00:00:00',
# 'key': ---- missing field on purpose, to verify that simply the text is left empty
# 'logdate': ---- missing field on purpose, to verify that simply the text is left empty
'sender_ip': '1.1.1.1',
'hostname': 'aProbe'
}

load_modules(rule)
alert = AlertaAlerter(rule)
Expand All @@ -1947,7 +1946,7 @@ def test_alerta_new_style(ea):
"attributes": {"senderIP": "1.1.1.1", "hostname": "aProbe", "TimestampEvent": "<MISSING VALUE>"},
"type": "elastalert",
"event": "ProbeUP"
}
}

mock_post_request.assert_called_once_with(
alert.url,
Expand All @@ -1956,4 +1955,4 @@ def test_alerta_new_style(ea):
'content-type': 'application/json'}
)
assert expected_data == json.loads(
mock_post_request.call_args_list[0][1]['data'])
mock_post_request.call_args_list[0][1]['data'])

0 comments on commit 87119b8

Please sign in to comment.