Skip to content

Commit

Permalink
Merge pull request #1627 from AndreLouisCaron/url-prefix-environment-…
Browse files Browse the repository at this point in the history
…variable

Configure ElasticSearch URL prefix using environment variable
  • Loading branch information
Qmando authored May 22, 2018
2 parents ae716bd + 64d1ef1 commit 7c0a8d4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ build/
.pytest_cache/
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

0 comments on commit 7c0a8d4

Please sign in to comment.