From 63bdf146ecef229bf5c000e6d8664c83d4d7f894 Mon Sep 17 00:00:00 2001 From: Andre Caron Date: Tue, 3 Apr 2018 11:49:12 -0400 Subject: [PATCH 1/2] Ignore text editor backup files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 97cc79aca..afda27514 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ build/ my_rules *.swp +*~ From 64d1ef130001d15055d1b240ffd983146d1b13ff Mon Sep 17 00:00:00 2001 From: Andre Caron Date: Tue, 3 Apr 2018 11:05:18 -0400 Subject: [PATCH 2/2] Enable setting `es_url_prefix` setting via an environment variable --- docs/source/elastalert.rst | 2 +- elastalert/config.py | 3 ++- tests/config_test.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/source/elastalert.rst b/docs/source/elastalert.rst index 75c644f64..fd2daec8c 100755 --- a/docs/source/elastalert.rst +++ b/docs/source/elastalert.rst @@ -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`` diff --git a/elastalert/config.py b/elastalert/config.py index 701d84167..89752b770 100644 --- a/elastalert/config.py +++ b/elastalert/config.py @@ -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) diff --git a/tests/config_test.py b/tests/config_test.py index 640814013..f444f0e25 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -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