mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-02-06 07:13:34 +01:00
use existing retry
This commit is contained in:
@@ -408,36 +408,19 @@ initialize_elasticsearch_indices() {
|
|||||||
local index_names=$1
|
local index_names=$1
|
||||||
local default_entry=${2:-'{"@timestamp":"0"}'}
|
local default_entry=${2:-'{"@timestamp":"0"}'}
|
||||||
|
|
||||||
local retries=3
|
|
||||||
local retry_delay=5
|
|
||||||
|
|
||||||
for idx in $index_names; do
|
for idx in $index_names; do
|
||||||
local count=0
|
if ! so-elasticsearch-query "$idx" --fail --retry 3 --retry-delay 30 >/dev/null 2>&1; then
|
||||||
if ! output=$(so-elasticsearch-query "$idx" --fail --retry 3 --retry-delay 30); then
|
|
||||||
echo "Index does not already exist. Initializing $idx index."
|
echo "Index does not already exist. Initializing $idx index."
|
||||||
|
|
||||||
while [[ $count -lt $retries ]]; do
|
if retry 3 10 "so-elasticsearch-query "$idx/_doc" -d '$default_entry' -XPOST --fail 2>/dev/null" '"successful":1'; then
|
||||||
response=$(so-elasticsearch-query "$idx/_doc" -d "$default_entry" -XPOST --fail 2>/dev/null)
|
echo "Successfully initialized $idx index."
|
||||||
if echo "$response" | grep -q '"successful":1'; then
|
else
|
||||||
echo "Successfully initialized $idx index."
|
echo "Failed to initialize $idx index after 3 attempts."
|
||||||
|
|
||||||
break
|
|
||||||
else
|
|
||||||
echo "Failed to initialize $idx index. Retrying in $retry_delay seconds..."
|
|
||||||
sleep $retry_delay
|
|
||||||
((count++))
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ $count -eq $retries ]]; then
|
|
||||||
echo "Failed to initialize $idx index after $retries attempts."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Index $idx already exists. No action needed."
|
echo "Index $idx already exists. No action needed."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lookup_bond_interfaces() {
|
lookup_bond_interfaces() {
|
||||||
|
|||||||
Reference in New Issue
Block a user