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

Configure ElasticSearch URL prefix using environment variable #1627

Merged
merged 2 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ build/

my_rules
*.swp
*~
2 changes: 1 addition & 1 deletion docs/source/elastalert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ The environment variable ``ES_USE_SSL`` will override this field.

``es_password``: Optional; basic-auth password for connecting to ``es_host``. The environment variable ``ES_PASSWORD`` will override this field.

``es_url_prefix``: Optional; URL prefix for the Elasticsearch endpoint.
``es_url_prefix``: Optional; URL prefix for the Elasticsearch endpoint. The environment variable ``ES_URL_PREFIX`` will override this field.

``es_send_get_body_as``: Optional; Method for querying Elasticsearch - ``GET``, ``POST`` or ``source``. The default is ``GET``

Expand Down
3 changes: 2 additions & 1 deletion elastalert/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
'ES_PASSWORD': 'es_password',
'ES_USERNAME': 'es_username',
'ES_HOST': 'es_host',
'ES_PORT': 'es_port'}
'ES_PORT': 'es_port',
'ES_URL_PREFIX': 'es_url_prefix'}

env = Env(ES_USE_SSL=bool)

Expand Down
16 changes: 16 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ def test_load_ssl_env_true():
assert rules['use_ssl'] is True


def test_load_url_prefix_env():
test_rule_copy = copy.deepcopy(test_rule)
test_rule_copy.pop('es_host')
test_rule_copy.pop('es_port')
test_config_copy = copy.deepcopy(test_config)
with mock.patch('elastalert.config.yaml_loader') as mock_open:
mock_open.side_effect = [test_config_copy, test_rule_copy]

with mock.patch('os.listdir') as mock_ls:
with mock.patch.dict(os.environ, {'ES_URL_PREFIX': 'es/'}):
mock_ls.return_value = ['testrule.yaml']
rules = load_rules(test_args)

assert rules['es_url_prefix'] == 'es/'


def test_load_disabled_rules():
test_rule_copy = copy.deepcopy(test_rule)
test_rule_copy['is_enabled'] = False
Expand Down