From b3d1dd51a42bb9f03576797d9ac1e3d17dc18759 Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Thu, 29 Jan 2026 15:41:39 -0600 Subject: [PATCH 1/2] initialize specific indices as needed --- salt/common/tools/sbin/so-common | 36 ++++++++++++++++++++++++++++++++ salt/manager/tools/sbin/soup | 2 ++ setup/so-setup | 1 + 3 files changed, 39 insertions(+) diff --git a/salt/common/tools/sbin/so-common b/salt/common/tools/sbin/so-common index 9e98204a1..ab8570af4 100755 --- a/salt/common/tools/sbin/so-common +++ b/salt/common/tools/sbin/so-common @@ -404,6 +404,42 @@ is_single_node_grid() { grep "role: so-" /etc/salt/grains | grep -E "eval|standalone|import" &> /dev/null } +initialize_elasticsearch_indices() { + local index_names=$1 + local default_entry=${2:-'{"@timestamp":"0"}'} + + local retries=3 + local retry_delay=5 + + for idx in $index_names; do + local count=0 + if ! output=$(so-elasticsearch-query "$idx" --fail --retry 3 --retry-delay 30); then + echo "Index does not already exist. Initializing $idx index." + + while [[ $count -lt $retries ]]; do + response=$(so-elasticsearch-query "$idx/_doc" -d "$default_entry" -XPOST --fail 2>/dev/null) + if echo "$response" | grep -q '"successful":1'; then + echo "Successfully initialized $idx index." + + 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 + + else + echo "Index $idx already exists. No action needed." + fi + done + +} + lookup_bond_interfaces() { cat /proc/net/bonding/bond0 | grep "Slave Interface:" | sed -e "s/Slave Interface: //g" } diff --git a/salt/manager/tools/sbin/soup b/salt/manager/tools/sbin/soup index 92f3b6d14..b0ac226d2 100755 --- a/salt/manager/tools/sbin/soup +++ b/salt/manager/tools/sbin/soup @@ -692,6 +692,8 @@ post_to_2.4.210() { disable_redis_heavynodes + initialize_elasticsearch_indices "so-case so-casehistory so-assistant-session so-assistant-chat" + echo "Regenerating Elastic Agent Installers" /sbin/so-elastic-agent-gen-installers diff --git a/setup/so-setup b/setup/so-setup index c2f589a45..1fa078b78 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -828,6 +828,7 @@ if ! [[ -f $install_opt_file ]]; then fi checkin_at_boot set_initial_firewall_access + initialize_elasticsearch_indices "so-case so-casehistory so-assistant-session so-assistant-chat" # run a final highstate before enabling scheduled highstates. # this will ensure so-elasticsearch-ilm-policy-load and so-elasticsearch-templates-load have a chance to run after elasticfleet is setup info "Running final highstate for setup" From 6ce6eb95d6f3dc0102f7372b16e436e25e2ef8bf Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Thu, 29 Jan 2026 15:54:36 -0600 Subject: [PATCH 2/2] use existing retry --- salt/common/tools/sbin/so-common | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/salt/common/tools/sbin/so-common b/salt/common/tools/sbin/so-common index ab8570af4..9fd5d6576 100755 --- a/salt/common/tools/sbin/so-common +++ b/salt/common/tools/sbin/so-common @@ -408,36 +408,19 @@ initialize_elasticsearch_indices() { local index_names=$1 local default_entry=${2:-'{"@timestamp":"0"}'} - local retries=3 - local retry_delay=5 - for idx in $index_names; do - local count=0 - if ! output=$(so-elasticsearch-query "$idx" --fail --retry 3 --retry-delay 30); then + if ! so-elasticsearch-query "$idx" --fail --retry 3 --retry-delay 30 >/dev/null 2>&1; then echo "Index does not already exist. Initializing $idx index." - while [[ $count -lt $retries ]]; do - response=$(so-elasticsearch-query "$idx/_doc" -d "$default_entry" -XPOST --fail 2>/dev/null) - if echo "$response" | grep -q '"successful":1'; then - echo "Successfully initialized $idx index." - - 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." + if retry 3 10 "so-elasticsearch-query "$idx/_doc" -d '$default_entry' -XPOST --fail 2>/dev/null" '"successful":1'; then + echo "Successfully initialized $idx index." + else + echo "Failed to initialize $idx index after 3 attempts." fi - else echo "Index $idx already exists. No action needed." fi done - } lookup_bond_interfaces() {