Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/retry strategy for elastalert #238

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions infrastructure/elasticsearch/setup-elastalert-indices.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,42 @@ docker service scale opencrvs_elastalert=0
echo 'Deleting Elastalert indices'
indices='elastalert_status,elastalert_status_error,elastalert_status_past,elastalert_status_silence,elastalert_status_status'

delete_status_code=$($docker_command --connect-timeout 60 -u elastic:$ELASTICSEARCH_SUPERUSER_PASSWORD -o /dev/null -w '%{http_code}' "http://elasticsearch:9200/${indices}" -X DELETE)
bulk_delete_status_code=$($docker_command --connect-timeout 60 -u elastic:$ELASTICSEARCH_SUPERUSER_PASSWORD -o /dev/null -w '%{http_code}' "http://elasticsearch:9200/${indices}" -X DELETE)

if [ "$delete_status_code" -ne 200 ]; then
echo "Could not delete indices. API returned status code: $delete_status_code"
exit 1
if [ "$bulk_delete_status_code" -ne 200 ]; then
echo "Could not delete indices. API returned status code: $bulk_delete_status_code"
fi


non_404_error_when_deleting_one_by_one=0

if [ "$bulk_delete_status_code" -eq 404 ]; then
echo "Some of the indices do not exist. Attempting to delete them one by one."

# Convert the comma-separated indices into an array
IFS=',' read -r -a indices_array <<< "$indices"

for index in "${indices_array[@]}"; do
echo "Deleting index: $index"
individual_delete_status_code=$($docker_command --connect-timeout 60 -u elastic:$ELASTICSEARCH_SUPERUSER_PASSWORD -o /dev/null -w '%{http_code}' "http://elasticsearch:9200/${index}" -X DELETE)

if [ "$individual_delete_status_code" -eq 200 ]; then
echo "Successfully deleted index: $index"
elif [ "$individual_delete_status_code" -eq 404 ]; then
echo "Index $index does not exist."
else
echo "Failed to delete index: $index. API returned status code: $individual_delete_status_code"
non_404_error_when_deleting_one_by_one=1
fi
done
fi


echo 'Scaling up Elastalert'
docker service scale opencrvs_elastalert=1

if [ "$non_404_error_when_deleting_one_by_one" -eq 0 ] && { [ "$bulk_delete_status_code" -eq 200 ] || [ "$bulk_delete_status_code" -eq 404 ]; }; then
exit 0
fi

exit 1
Loading