Skip to content

Commit

Permalink
Update ism-init script to parametrize the path of the wazuh-template
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRuiz7 committed Jan 3, 2024
1 parent df78e02 commit 98dd408
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions distribution/src/bin/indexer-ism-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -335,6 +336,15 @@ function main() {
shift 2
fi
;;
"-t" | "--template")
if [ -z "${2}" ]; then
echo "Error on arguments. Probably missing <template> after -t|--template"
show_help
else
ALERTS_TEMPLATE="${2}"
shift 2
fi
;;
"-v" | "--verbose")
set -x
shift
Expand Down

0 comments on commit 98dd408

Please sign in to comment.