Skip to content

Commit 623e3b1

Browse files
committed
Fix yellow cluster state (#95)
* Add template and settings to disable replicas on ISM plugin internal indices * Fix documentation Replaces exit 1 statements with return 1 * Fix uncommented comment line
1 parent 98dd408 commit 623e3b1

File tree

1 file changed

+72
-4
lines changed

1 file changed

+72
-4
lines changed

distribution/src/bin/indexer-ism-init.sh

+72-4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,48 @@ function generate_rollover_template() {
8282
EOF
8383
}
8484

85+
#########################################################################
86+
# Creates an index template to disable replicas on ISM configurastion indices.
87+
# Returns:
88+
# The index template as a JSON string.
89+
#########################################################################
90+
function generate_ism_config_template() {
91+
cat <<-EOF
92+
{
93+
"order": 1,
94+
"index_patterns": [
95+
".opendistro-ism-managed-index-history-*",
96+
".opendistro-ism-config",
97+
".opendistro-job-scheduler-lock"
98+
],
99+
"settings": {
100+
"number_of_replicas": 0
101+
}
102+
}
103+
EOF
104+
}
105+
106+
#########################################################################
107+
# Creates persistent cluster's settings to disable replicas for ISM history.
108+
# Returns:
109+
# The setting as a JSON string.
110+
#########################################################################
111+
function generate_ism_config() {
112+
cat <<-EOF
113+
{
114+
"persistent": {
115+
"plugins": {
116+
"index_state_management": {
117+
"history": {
118+
"number_of_replicas": "0"
119+
}
120+
}
121+
}
122+
}
123+
}
124+
EOF
125+
}
126+
85127
#########################################################################
86128
# Loads the index templates for the rollover policy to the indexer.
87129
#########################################################################
@@ -95,14 +137,40 @@ function load_templates() {
95137
-o "${LOG_FILE}" --create-dirs \
96138
-H 'Content-Type: application/json' -d @-; then
97139
echo " ERROR: 'wazuh' template creation failed"
98-
exit 1
140+
return 1
99141
else
100142
echo " SUCC: 'wazuh' template created or updated"
101143
fi
102144
else
103145
echo " ERROR: ${ALERTS_TEMPLATE} not found"
104146
fi
105147

148+
# Load template for ISM configuration indices
149+
echo "Will create 'ism_history_indices' index template"
150+
generate_ism_config_template |
151+
if ! curl -s -k ${C_AUTH} \
152+
-X PUT "${INDEXER_URL}/_template/ism_history_indices" \
153+
-o "${LOG_FILE}" --create-dirs \
154+
-H 'Content-Type: application/json' -d @-; then
155+
echo " ERROR: 'ism_history_indices' template creation failed"
156+
return 1
157+
else
158+
echo " SUCC: 'ism_history_indices' template created or updated"
159+
fi
160+
161+
# Make settings persistent
162+
echo "Will disable replicas for 'plugins.index_state_management.history' indices"
163+
generate_ism_config |
164+
if ! curl -s -k ${C_AUTH} \
165+
-X PUT "${INDEXER_URL}/_cluster/settings" \
166+
-o "${LOG_FILE}" --create-dirs \
167+
-H 'Content-Type: application/json' -d @-; then
168+
echo " ERROR: cluster's settings update failed"
169+
return 1
170+
else
171+
echo " SUCC: cluster's settings saved"
172+
fi
173+
106174
echo "Will create index templates to configure the alias"
107175
for alias in "${aliases[@]}"; do
108176
generate_rollover_template "${alias}" |
@@ -202,7 +270,7 @@ function create_write_index() {
202270
-H 'Content-Type: application/json' \
203271
-d "$(generate_write_index_alias "${1}")"; then
204272
echo " ERROR: creating '${1}' write index"
205-
exit 1
273+
return 1
206274
else
207275
echo " SUCC: '${1}' write index created"
208276
fi
@@ -264,7 +332,7 @@ function show_help() {
264332
echo -e " -v, --verbose"
265333
echo -e " Set verbose mode. Prints more information."
266334
echo -e ""
267-
exit 1
335+
return 1
268336
}
269337

270338
#########################################################################
@@ -363,7 +431,7 @@ function main() {
363431
echo "SUCC: Indexer ISM initialization finished successfully."
364432
else
365433
echo "ERROR: Indexer ISM initialization failed. Check ${LOG_FILE} for more information."
366-
exit 1
434+
return 1
367435
fi
368436
}
369437

0 commit comments

Comments
 (0)