From de9f6425f9901cc82697ba216484e420e2864578 Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Thu, 2 May 2024 12:13:46 -0400 Subject: [PATCH] Automatically switch between Kafka output policy and logstash output policy when globals.pipeline changes Signed-off-by: reyesj2 <94730068+reyesj2@users.noreply.github.com> --- .../so-elastic-fleet-outputs-update | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-outputs-update b/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-outputs-update index 4d2867fc7..064d49d23 100644 --- a/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-outputs-update +++ b/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-outputs-update @@ -127,13 +127,27 @@ NEW_HASH=$(sha1sum <<< "$NEW_LIST_JSON" | awk '{print $1}') if [ "$NEW_HASH" = "$CURRENT_HASH" ]; then printf "\nHashes match - no update needed.\n" printf "Current List: $CURRENT_LIST\nNew List: $NEW_LIST_JSON\n" + + # Since output can be KAFKA or LOGSTASH, we need to check if the policy set as default matches the value set in GLOBALS.pipeline and update if needed + printf "Checking if the correct output policy is set as default\n" + OUTPUT_DEFAULT=$(jq -r '.item.is_default' <<< $RAW_JSON) + if [ "$OUTPUT_DEFAULT" = "false" ]; then + printf "Default output policy needs to be updated.\n" + {%- if GLOBALS.pipeline == "KAFKA" %} + update_kafka_outputs + {%- else %} + update_logstash_outputs + {%- endif %} + else + printf "Default output policy is set - no update needed.\n" + fi exit 0 else printf "\nHashes don't match - update needed.\n" printf "Current List: $CURRENT_LIST\nNew List: $NEW_LIST_JSON\n" -{% if GLOBALS.pipeline == "KAFKA" %} + {%- if GLOBALS.pipeline == "KAFKA" %} update_kafka_outputs -{% else %} + {%- else %} update_logstash_outputs -{% endif %} + {%- endif %} fi