From 56b520b399e67c4531479e23f710e3e1fb176bd2 Mon Sep 17 00:00:00 2001 From: Michael Cayanan <42812746+mcayanan@users.noreply.github.com> Date: Fri, 12 May 2023 08:12:53 -0700 Subject: [PATCH] HC-469: Python tool to install the base ES template (#59) * HC-469: Add script to install base ES template This allows us to install it either to local GRQ or AWS ES * pass in args --------- Co-authored-by: Mike Cayanan --- scripts/install_base_es_template.py | 32 +++++++++++++++++++++++++++++ scripts/install_base_es_template.sh | 7 +++++++ 2 files changed, 39 insertions(+) create mode 100755 scripts/install_base_es_template.py create mode 100755 scripts/install_base_es_template.sh diff --git a/scripts/install_base_es_template.py b/scripts/install_base_es_template.py new file mode 100755 index 0000000..1193fad --- /dev/null +++ b/scripts/install_base_es_template.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import division +from __future__ import absolute_import +from builtins import open +from future import standard_library +standard_library.install_aliases() +import os +import sys +import json + +from grq2 import grq_es + + +def write_template(tmpl_file): + """Write template to ES.""" + + with open(tmpl_file) as f: + tmpl = json.load(f) + + # https://elasticsearch-py.readthedocs.io/en/1.3.0/api.html#elasticsearch.Elasticsearch.put_template + grq_es.es.indices.put_template(name="index_defaults", body=tmpl, ignore=400) + print(f"Successfully installed template to index_defaults:\n{json.dumps(tmpl, indent=2)}") + + +if __name__ == "__main__": + + # get template file + tmpl_file = os.path.abspath(sys.argv[1]) + + write_template(tmpl_file) diff --git a/scripts/install_base_es_template.sh b/scripts/install_base_es_template.sh new file mode 100755 index 0000000..92e4b4f --- /dev/null +++ b/scripts/install_base_es_template.sh @@ -0,0 +1,7 @@ +#!/bin/bash +BASE_PATH=$(dirname "${BASH_SOURCE}") +BASE_PATH=$(cd "${BASE_PATH}"; pwd) +export PYTHONPATH=$BASE_PATH/..:$PYTHONPATH + +# install ops and dev templates +$BASE_PATH/install_base_es_template.py $*