@@ -80,6 +80,48 @@ function generate_rollover_template() {
80
80
EOF
81
81
}
82
82
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
+
83
125
# ########################################################################
84
126
# Loads the index templates for the rollover policy to the indexer.
85
127
# ########################################################################
@@ -89,18 +131,44 @@ function load_templates() {
89
131
echo " Will create 'wazuh' index template"
90
132
if [ -f $wazuh_template_path ]; then
91
133
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 |
92
150
if ! curl -s -k ${C_AUTH} \
93
- -X PUT " ${INDEXER_URL} /_template/wazuh " \
151
+ -X PUT " ${INDEXER_URL} /_template/ism_history_indices " \
94
152
-o " ${LOG_FILE} " --create-dirs \
95
153
-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
98
156
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"
100
171
fi
101
- else
102
- echo " ERROR: $wazuh_template_path not found"
103
- fi
104
172
105
173
echo " Will create index templates to configure the alias"
106
174
for alias in " ${aliases[@]} " ; do
@@ -201,7 +269,7 @@ function create_write_index() {
201
269
-H ' Content-Type: application/json' \
202
270
-d " $( generate_write_index_alias " ${1} " ) " ; then
203
271
echo " ERROR: creating '${1} ' write index"
204
- exit 1
272
+ return 1
205
273
else
206
274
echo " SUCC: '${1} ' write index created"
207
275
fi
@@ -263,7 +331,7 @@ function show_help() {
263
331
echo -e " -v, --verbose"
264
332
echo -e " Set verbose mode. Prints more information."
265
333
echo -e " "
266
- exit 1
334
+ return 1
267
335
}
268
336
269
337
# ########################################################################
@@ -353,7 +421,7 @@ function main() {
353
421
echo " SUCC: Indexer ISM initialization finished successfully."
354
422
else
355
423
echo " ERROR: Indexer ISM initialization failed. Check ${LOG_FILE} for more information."
356
- exit 1
424
+ return 1
357
425
fi
358
426
}
359
427
0 commit comments