From aaf9f536956b1206a4f51ebb0cac06bf19f77588 Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Mon, 11 Nov 2024 22:40:06 -0600 Subject: [PATCH] update soup; check for index before applying new index setting Signed-off-by: reyesj2 <94730068+reyesj2@users.noreply.github.com> --- salt/manager/tools/sbin/soup | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/salt/manager/tools/sbin/soup b/salt/manager/tools/sbin/soup index d5aa26bae..98a7f9402 100755 --- a/salt/manager/tools/sbin/soup +++ b/salt/manager/tools/sbin/soup @@ -520,16 +520,7 @@ post_to_2.4.110() { } post_to_2.4.120() { - for idx in "so-detection" "so-detectionhistory" "so-case" "so-casehistory"; do - JSON_STRING=$( jq -n \ - --arg INDEX_NAME "$idx" \ - '{"settings": {"index.auto_expand_replicas":"0-2","index.lifecycle.name":($INDEX_NAME + "-logs")}}' - ) - echo "Updating $idx index settings" - retry 5 15 "so-elasticsearch-query $idx/_settings -d "$JSON_STRING" -XPUT| grep '{\"acknowledged\":true}'" - echo "" - done - + update_elasticsearch_index_settings POSTVERSION=2.4.120 } @@ -947,6 +938,23 @@ update_airgap_repo() { createrepo /nsm/repo } +update_elasticsearch_index_settings() { + # Update managed indices to reflect latest index template + for idx in "so-detection" "so-detectionhistory" "so-case" "so-casehistory"; do + JSON_STRING=$( jq -n --arg INDEX_NAME "$idx" '{"settings": {"index.auto_expand_replicas":"0-2","index.lifecycle.name":($INDEX_NAME + "-logs")}}') + echo "Checking if index \"$idx\" exists" + exists=$(curl -K /opt/so/conf/elasticsearch/curl.config -s -o /dev/null -w "%{http_code}" -k -L -H "Content-Type: application/json" "https://localhost:9200/$idx") + if [ $exists -eq 200 ]; then + echo "$idx index found..." + echo "Updating $idx index settings" + so-elasticsearch-query $idx/_settings -d "$JSON_STRING" -XPUT + echo -e "\n" + else + echo -e "Skipping $idx... index does not exist\n" + fi + done +} + update_salt_mine() { echo "Populating the mine with mine_functions for each host." set +e