@@ -82,6 +82,48 @@ function generate_rollover_template() {
82
82
EOF
83
83
}
84
84
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
+
85
127
# ########################################################################
86
128
# Loads the index templates for the rollover policy to the indexer.
87
129
# ########################################################################
@@ -95,14 +137,40 @@ function load_templates() {
95
137
-o " ${LOG_FILE} " --create-dirs \
96
138
-H ' Content-Type: application/json' -d @-; then
97
139
echo " ERROR: 'wazuh' template creation failed"
98
- exit 1
140
+ return 1
99
141
else
100
142
echo " SUCC: 'wazuh' template created or updated"
101
143
fi
102
144
else
103
145
echo " ERROR: ${ALERTS_TEMPLATE} not found"
104
146
fi
105
147
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
+
106
174
echo " Will create index templates to configure the alias"
107
175
for alias in " ${aliases[@]} " ; do
108
176
generate_rollover_template " ${alias} " |
@@ -202,7 +270,7 @@ function create_write_index() {
202
270
-H ' Content-Type: application/json' \
203
271
-d " $( generate_write_index_alias " ${1} " ) " ; then
204
272
echo " ERROR: creating '${1} ' write index"
205
- exit 1
273
+ return 1
206
274
else
207
275
echo " SUCC: '${1} ' write index created"
208
276
fi
@@ -264,7 +332,7 @@ function show_help() {
264
332
echo -e " -v, --verbose"
265
333
echo -e " Set verbose mode. Prints more information."
266
334
echo -e " "
267
- exit 1
335
+ return 1
268
336
}
269
337
270
338
# ########################################################################
@@ -363,7 +431,7 @@ function main() {
363
431
echo " SUCC: Indexer ISM initialization finished successfully."
364
432
else
365
433
echo " ERROR: Indexer ISM initialization failed. Check ${LOG_FILE} for more information."
366
- exit 1
434
+ return 1
367
435
fi
368
436
}
369
437
0 commit comments