@@ -85,10 +85,15 @@ function generate_rollover_template() {
85
85
function load_templates() {
86
86
# Note: the wazuh-template.json could also be loaded here.
87
87
for alias in " ${aliases[@]} " ; do
88
- echo " TEMPLATES AND POLICIES - Uploading ${alias} template"
89
- generate_rollover_template " ${alias} " | curl -s -k ${C_AUTH} \
90
- -X PUT " ${INDEXER_URL} /_template/${alias} -rollover" -o /dev/null \
91
- -H ' Content-Type: application/json' -d @-
88
+ generate_rollover_template " ${alias} " |
89
+ if ! curl -s -k ${C_AUTH} \
90
+ -X PUT " ${INDEXER_URL} /_template/${alias} -rollover" -o /dev/null \
91
+ -H ' Content-Type: application/json' -d @-; then
92
+ echo " Error uploading ${alias} template"
93
+ return 1
94
+ else
95
+ echo " ${alias} template uploaded"
96
+ fi
92
97
done
93
98
}
94
99
@@ -110,15 +115,21 @@ function upload_rollover_policy() {
110
115
111
116
# Check if the ${POLICY_NAME} ISM policy was loaded (404 error if not found)
112
117
if [[ " ${policy_exists} " == " 404" ]]; then
113
- echo " TEMPLATES AND POLICIES - Uploading ${POLICY_NAME} ISM policy"
114
- curl -s -k ${C_AUTH} -o /dev/null \
118
+ if ! curl -s -k ${C_AUTH} -o /dev/null \
115
119
-X PUT " ${INDEXER_URL} /_plugins/_ism/policies/${POLICY_NAME} " \
116
- -H ' Content-Type: application/json' -d " $( generate_rollover_policy) "
120
+ -H ' Content-Type: application/json' \
121
+ -d " $( generate_rollover_policy) " ; then
122
+ echo " Error uploading ${POLICY_NAME} policy"
123
+ return 1
124
+ else
125
+ echo " ${POLICY_NAME} policy uploaded"
126
+ fi
117
127
else
118
128
if [[ " ${policy_exists} " == " 200" ]]; then
119
- echo " TEMPLATES AND POLICIES - ${POLICY_NAME} policy already exists"
129
+ echo " ${POLICY_NAME} policy already exists"
120
130
else
121
- echo " TEMPLATES AND POLICIES - Error uploading ${POLICY_NAME} policy"
131
+ echo " Error checking if ${POLICY_NAME} exists"
132
+ return 1
122
133
fi
123
134
fi
124
135
}
@@ -158,9 +169,15 @@ function generate_write_index_alias() {
158
169
# 1. The alias. String.
159
170
# ########################################################################
160
171
function create_write_index() {
161
- curl -s -k ${C_AUTH} -o /dev/null \
172
+ if ! curl -s -k ${C_AUTH} -o /dev/null \
162
173
-X PUT " $INDEXER_URL /%3C${1} -4.x-%7Bnow%2Fd%7D-000001%3E?pretty" \
163
- -H ' Content-Type: application/json' -d " $( generate_write_index_alias " ${1} " ) "
174
+ -H ' Content-Type: application/json' \
175
+ -d " $( generate_write_index_alias " ${1} " ) " ; then
176
+ echo " Error creating ${1} write index"
177
+ exit 1
178
+ else
179
+ echo " ${1} write index created"
180
+ fi
164
181
}
165
182
166
183
# ########################################################################
@@ -169,7 +186,6 @@ function create_write_index() {
169
186
# 1. List of aliases to initialize.
170
187
# ########################################################################
171
188
function create_indices() {
172
- echo " TEMPLATES AND POLICIES - Creating write indices"
173
189
for alias in " ${aliases[@]} " ; do
174
190
# Check if there are any write indices for the current alias
175
191
write_index_exists=$( check_for_write_index " ${alias} " )
@@ -181,7 +197,6 @@ function create_indices() {
181
197
done
182
198
}
183
199
184
-
185
200
# ########################################################################
186
201
# Shows usage help.
187
202
# ########################################################################
@@ -209,9 +224,15 @@ function show_help() {
209
224
echo -e " -p, --indexer-password <password>"
210
225
echo -e " Specifies the Wazuh indexer admin user password."
211
226
echo -e " "
227
+ echo -e " -P, --priority <priority>"
228
+ echo -e " Specifies the policy's priority."
229
+ echo -e " "
212
230
echo -e " -s, --min-shard-size <shard-size>"
213
231
echo -e " Set the minimum shard size in GB. By default 25."
214
232
echo -e " "
233
+ echo -e " -v, --verbose"
234
+ echo -e " Set verbose mode. Prints more information."
235
+ echo -e " "
215
236
exit 1
216
237
}
217
238
@@ -252,6 +273,7 @@ function main() {
252
273
show_help
253
274
else
254
275
INDEXER_HOSTNAME=" ${2} "
276
+ INDEXER_URL=" https://${INDEXER_HOSTNAME} :9200"
255
277
shift 2
256
278
fi
257
279
;;
@@ -274,6 +296,19 @@ function main() {
274
296
shift 2
275
297
fi
276
298
;;
299
+ " -P" | " --priority" )
300
+ if [ -z " ${2} " ]; then
301
+ echo " Error on arguments. Probably missing <priority> after -P|--priority"
302
+ show_help
303
+ else
304
+ ISM_PRIORITY=" ${2} "
305
+ shift 2
306
+ fi
307
+ ;;
308
+ " -v" | " --verbose" )
309
+ set -x
310
+ shift
311
+ ;;
277
312
* )
278
313
echo " Unknow option: ${1} "
279
314
show_help
@@ -282,13 +317,14 @@ function main() {
282
317
done
283
318
284
319
# Load the Wazuh Indexer templates
285
- load_templates
286
-
287
320
# Upload the rollover policy
288
- upload_rollover_policy
289
-
290
321
# Create the initial write indices
291
- create_indices " ${aliases[@]} "
322
+ if load_templates && upload_rollover_policy && create_indices " ${aliases[@]} " ; then
323
+ echo " Indexer ISM initialization finished successfully"
324
+ else
325
+ echo " Indexer ISM initialization failed"
326
+ exit 1
327
+ fi
292
328
}
293
329
294
330
main " $@ "
0 commit comments