Skip to content

Commit

Permalink
Revise Elastalert index check deletion logic
Browse files Browse the repository at this point in the history
  • Loading branch information
weslambert committed Jul 19, 2022
1 parent 07b8785 commit 4a7c994
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions salt/common/tools/sbin/soup
Original file line number Diff line number Diff line change
Expand Up @@ -852,13 +852,33 @@ up_to_2.3.140() {
fi

# Delete Elastalert indices
for i in $(so-elasticsearch-query _cat/indices | grep elastalert | awk '{print $3}'); do so-elasticsearch-query $i -XDELETE; done
# Check to ensure Elastalert indices have been deleted
RESPONSE=$(so-elasticsearch-query elastalert*)
if [[ "$RESPONSE" == "{}" ]]; then
echo "Elastalert indices have been deleted."
else
fail "Something went wrong. Could not delete the Elastalert indices. Exiting."
for i in $(so-elasticsearch-query _cat/indices | grep elastalert | awk '{print $3}');
do
so-elasticsearch-query $i -XDELETE;
done

# Check to ensure Elastalert indices are deleted
COUNT=0
ELASTALERT_INDICES_DELETED="no"
while [[ "$COUNT" -le 240 ]]; do
RESPONSE=$(so-elasticsearch-query elastalert*)
if [[ "$RESPONSE" == "{}" ]]; then
ELASTALERT_INDICES_DELETED="yes"
echo "Elastalert indices successfully deleted."
break
else
((COUNT+=1))
sleep 1
echo -n "."
fi
done

# If we were unable to delete the Elastalert indices, exit the script
if [ "$ELASTALERT_INDICES_DELETED" == "no" ]; then
echo
echo -e "Unable to connect to delete Elastalert indices. Exiting."
echo
exit 1
fi
##
INSTALLEDVERSION=2.3.140
Expand Down

0 comments on commit 4a7c994

Please sign in to comment.