From 6ce89eb3234b288b41c80ccd8df5767cac8262be Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Tue, 22 Sep 2026 21:25:50 -0500 Subject: [PATCH] jq -e exits 0 with empty input --- salt/elasticfleet/tools/sbin/so-elastic-fleet-common | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/salt/elasticfleet/tools/sbin/so-elastic-fleet-common b/salt/elasticfleet/tools/sbin/so-elastic-fleet-common index 9f6c25728..3a35c4c0c 100644 --- a/salt/elasticfleet/tools/sbin/so-elastic-fleet-common +++ b/salt/elasticfleet/tools/sbin/so-elastic-fleet-common @@ -34,8 +34,12 @@ elastic_fleet_require_agent_policy() { local AGENT_POLICY=$1 local POLICY_JSON - POLICY_JSON=$(fleet_api "agent_policies/$AGENT_POLICY") - if ! jq -e '.item.package_policies' <<<"$POLICY_JSON" >/dev/null 2>&1; then + if ! POLICY_JSON=$(fleet_api "agent_policies/$AGENT_POLICY") || [ -z "$POLICY_JSON" ]; then + echo "Error: Agent policy '$AGENT_POLICY' was not found or is not visible in the current Kibana space." >&2 + return 1 + fi + + if ! jq -e '.item.package_policies | type == "array"' <<<"$POLICY_JSON" >/dev/null 2>&1; then echo "Error: Agent policy '$AGENT_POLICY' was not found or is not visible in the current Kibana space." >&2 return 1 fi