From d85776db9cce72ae714da89dbd09e5dcea9eddb4 Mon Sep 17 00:00:00 2001 From: Pavol Loffay Date: Mon, 2 Sep 2019 16:43:21 +0200 Subject: [PATCH] Add elasticsearch version configuration to rollover script (#1769) * Add elasticsearch version configuration to rollover script Signed-off-by: Pavol Loffay * Remove version parameter from call Signed-off-by: Pavol Loffay --- plugin/storage/es/esRollover.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugin/storage/es/esRollover.py b/plugin/storage/es/esRollover.py index 662d3584db7..916ef6ce768 100755 --- a/plugin/storage/es/esRollover.py +++ b/plugin/storage/es/esRollover.py @@ -35,6 +35,7 @@ def main(): print('ES_TLS_CA ... Path to TLS CA file.') print('ES_TLS_CERT ... Path to TLS certificate file.') print('ES_TLS_KEY ... Path to TLS key file.') + print('ES_VERSION ... The major Elasticsearch version. If not specified, the value will be auto-detected from Elasticsearch.') print('init configuration:') print('\tSHARDS ... the number of shards per index in Elasticsearch (default {}).'.format(SHARDS)) print('\tREPLICAS ... the number of replicas per index in Elasticsearch (default {}).'.format(REPLICAS)) @@ -85,7 +86,7 @@ def perform_action(action, client, write_alias, read_alias, index_to_rollover, t mapping = Path('./mappings/'+template_name+'-7.json').read_text() else: mapping = Path('./mappings/'+template_name+'.json').read_text() - create_index_template(fix_mapping(mapping, shards, replicas), template_name, esVersion) + create_index_template(fix_mapping(mapping, shards, replicas), template_name) index = index_to_rollover + '-000001' create_index(client, index) @@ -103,7 +104,7 @@ def perform_action(action, client, write_alias, read_alias, index_to_rollover, t sys.exit(1) -def create_index_template(template, template_name, esVersion): +def create_index_template(template, template_name): print('Creating index template {}'.format(template_name)) headers = {'Content-Type': 'application/json'} s = get_request_session(os.getenv("ES_USERNAME"), os.getenv("ES_PASSWORD"), str2bool(os.getenv("ES_TLS", 'false')), os.getenv("ES_TLS_CA"), os.getenv("ES_TLS_CERT"), os.getenv("ES_TLS_KEY")) @@ -212,9 +213,12 @@ def get_request_session(username, password, tls, ca, cert, key): def get_version(client): - esVersion = client.info()['version']['number'][0] - print('Detected ElasticSearch Version {}'.format(esVersion)) - return int(esVersion) + esVersion = os.getenv('ES_VERSION') + if esVersion is None or esVersion == '': + esVersion = client.info()['version']['number'][0] + print('Detected ElasticSearch Version {}'.format(esVersion)) + esVersion = int(esVersion) + return esVersion if __name__ == "__main__":