From 98dd40811239ca5aba569f8d9aaa1efba85482ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Ruiz?= Date: Wed, 3 Jan 2024 17:20:39 +0100 Subject: [PATCH] Update ism-init script to parametrize the path of the wazuh-template --- distribution/src/bin/indexer-ism-init.sh | 36 +++++++++++++++--------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/distribution/src/bin/indexer-ism-init.sh b/distribution/src/bin/indexer-ism-init.sh index 4217979624bc7..6051ab95788ae 100644 --- a/distribution/src/bin/indexer-ism-init.sh +++ b/distribution/src/bin/indexer-ism-init.sh @@ -19,6 +19,8 @@ INDEXER_URL="https://${INDEXER_HOSTNAME}:9200" # curl settings shortcuts C_AUTH="-u admin:${INDEXER_PASSWORD}" +ALERTS_TEMPLATE="/etc/wazuh-indexer/wazuh-template.json" + ######################################################################### # Creates the rollover_policy ISM policy. # Globals: @@ -85,21 +87,20 @@ function generate_rollover_template() { ######################################################################### function load_templates() { # Load wazuh-template.json, needed for initial indices creation. - local wazuh_template_path="/etc/wazuh-indexer/wazuh-template.json" echo "Will create 'wazuh' index template" - if [ -f $wazuh_template_path ]; then - cat $wazuh_template_path | - if ! curl -s -k ${C_AUTH} \ - -X PUT "${INDEXER_URL}/_template/wazuh" \ - -o "${LOG_FILE}" --create-dirs \ - -H 'Content-Type: application/json' -d @-; then - echo " ERROR: 'wazuh' template creation failed" - exit 1 - else - echo " SUCC: 'wazuh' template created or updated" - fi + if [ -f "${ALERTS_TEMPLATE}" ]; then + cat "${ALERTS_TEMPLATE}" | + if ! curl -s -k ${C_AUTH} \ + -X PUT "${INDEXER_URL}/_template/wazuh" \ + -o "${LOG_FILE}" --create-dirs \ + -H 'Content-Type: application/json' -d @-; then + echo " ERROR: 'wazuh' template creation failed" + exit 1 + else + echo " SUCC: 'wazuh' template created or updated" + fi else - echo " ERROR: $wazuh_template_path not found" + echo " ERROR: ${ALERTS_TEMPLATE} not found" fi echo "Will create index templates to configure the alias" @@ -335,6 +336,15 @@ function main() { shift 2 fi ;; + "-t" | "--template") + if [ -z "${2}" ]; then + echo "Error on arguments. Probably missing