Skip to content

Commit c37fef4

Browse files
authored
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 df78e02 commit c37fef4

File tree

1 file changed

+78
-10
lines changed

1 file changed

+78
-10
lines changed

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

+78-10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,48 @@ function generate_rollover_template() {
8080
EOF
8181
}
8282

83+
#########################################################################
84+
# Creates an index template to disable replicas on ISM configurastion indices.
85+
# Returns:
86+
# The index template as a JSON string.
87+
#########################################################################
88+
function generate_ism_config_template() {
89+
cat <<-EOF
90+
{
91+
"order": 1,
92+
"index_patterns": [
93+
".opendistro-ism-managed-index-history-*",
94+
".opendistro-ism-config",
95+
".opendistro-job-scheduler-lock"
96+
],
97+
"settings": {
98+
"number_of_replicas": 0
99+
}
100+
}
101+
EOF
102+
}
103+
104+
#########################################################################
105+
# Creates persistent cluster's settings to disable replicas for ISM history.
106+
# Returns:
107+
# The setting as a JSON string.
108+
#########################################################################
109+
function generate_ism_config() {
110+
cat <<-EOF
111+
{
112+
"persistent": {
113+
"plugins": {
114+
"index_state_management": {
115+
"history": {
116+
"number_of_replicas": "0"
117+
}
118+
}
119+
}
120+
}
121+
}
122+
EOF
123+
}
124+
83125
#########################################################################
84126
# Loads the index templates for the rollover policy to the indexer.
85127
#########################################################################
@@ -89,18 +131,44 @@ function load_templates() {
89131
echo "Will create 'wazuh' index template"
90132
if [ -f $wazuh_template_path ]; then
91133
cat $wazuh_template_path |
134+
if ! curl -s -k ${C_AUTH} \
135+
-X PUT "${INDEXER_URL}/_template/wazuh" \
136+
-o "${LOG_FILE}" --create-dirs \
137+
-H 'Content-Type: application/json' -d @-; then
138+
echo " ERROR: 'wazuh' template creation failed"
139+
return 1
140+
else
141+
echo " SUCC: 'wazuh' template created or updated"
142+
fi
143+
else
144+
echo " ERROR: $wazuh_template_path not found"
145+
fi
146+
147+
# Load template for ISM configuration indices
148+
echo "Will create 'ism_history_indices' index template"
149+
generate_ism_config_template |
92150
if ! curl -s -k ${C_AUTH} \
93-
-X PUT "${INDEXER_URL}/_template/wazuh" \
151+
-X PUT "${INDEXER_URL}/_template/ism_history_indices" \
94152
-o "${LOG_FILE}" --create-dirs \
95153
-H 'Content-Type: application/json' -d @-; then
96-
echo " ERROR: 'wazuh' template creation failed"
97-
exit 1
154+
echo " ERROR: 'ism_history_indices' template creation failed"
155+
return 1
98156
else
99-
echo " SUCC: 'wazuh' template created or updated"
157+
echo " SUCC: 'ism_history_indices' template created or updated"
158+
fi
159+
160+
# Make settings persistent
161+
echo "Will disable replicas for 'plugins.index_state_management.history' indices"
162+
generate_ism_config |
163+
if ! curl -s -k ${C_AUTH} \
164+
-X PUT "${INDEXER_URL}/_cluster/settings" \
165+
-o "${LOG_FILE}" --create-dirs \
166+
-H 'Content-Type: application/json' -d @-; then
167+
echo " ERROR: cluster's settings update failed"
168+
return 1
169+
else
170+
echo " SUCC: cluster's settings saved"
100171
fi
101-
else
102-
echo " ERROR: $wazuh_template_path not found"
103-
fi
104172

105173
echo "Will create index templates to configure the alias"
106174
for alias in "${aliases[@]}"; do
@@ -201,7 +269,7 @@ function create_write_index() {
201269
-H 'Content-Type: application/json' \
202270
-d "$(generate_write_index_alias "${1}")"; then
203271
echo " ERROR: creating '${1}' write index"
204-
exit 1
272+
return 1
205273
else
206274
echo " SUCC: '${1}' write index created"
207275
fi
@@ -263,7 +331,7 @@ function show_help() {
263331
echo -e " -v, --verbose"
264332
echo -e " Set verbose mode. Prints more information."
265333
echo -e ""
266-
exit 1
334+
return 1
267335
}
268336

269337
#########################################################################
@@ -353,7 +421,7 @@ function main() {
353421
echo "SUCC: Indexer ISM initialization finished successfully."
354422
else
355423
echo "ERROR: Indexer ISM initialization failed. Check ${LOG_FILE} for more information."
356-
exit 1
424+
return 1
357425
fi
358426
}
359427

0 commit comments

Comments
 (0)