From bc71af7a1fbc1995df388044fe88a83ebe5b8a6e Mon Sep 17 00:00:00 2001 From: weslambert Date: Fri, 13 Sep 2024 13:27:26 -0400 Subject: [PATCH] Check status --- .../tools/sbin/so-elastic-fleet-common | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/salt/elasticfleet/tools/sbin/so-elastic-fleet-common b/salt/elasticfleet/tools/sbin/so-elastic-fleet-common index d5b27c315..a07c7c8bc 100644 --- a/salt/elasticfleet/tools/sbin/so-elastic-fleet-common +++ b/salt/elasticfleet/tools/sbin/so-elastic-fleet-common @@ -104,34 +104,58 @@ elastic_fleet_package_is_installed() { elastic_fleet_agent_policy_names() { curl -s -K /opt/so/conf/elasticsearch/curl.config -b "sid=$SESSIONCOOKIE" -L -X GET "localhost:5601/api/fleet/agent_policies" | jq -r .items[].name + if [ $? -ne 0 ]; then + echo "Error: Failed to retrieve agent policies." + exit 1 + fi } elastic_fleet_integration_policy_names() { AGENT_POLICY=$1 curl -s -K /opt/so/conf/elasticsearch/curl.config -b "sid=$SESSIONCOOKIE" -L -X GET "localhost:5601/api/fleet/agent_policies/$AGENT_POLICY" | jq -r .item.package_policies[].name + if [ $? -ne 0 ]; then + echo "Error: Failed to retrieve integrations." + exit 1 + fi } elastic_fleet_integration_policy_package_name() { AGENT_POLICY=$1 INTEGRATION=$2 curl -s -K /opt/so/conf/elasticsearch/curl.config -b "sid=$SESSIONCOOKIE" -L -X GET "localhost:5601/api/fleet/agent_policies/$AGENT_POLICY" | jq -r --arg INTEGRATION "$INTEGRATION" '.item.package_policies[] | select(.name==$INTEGRATION)| .package.name' + if [ $? -ne 0 ]; then + echo "Error: Failed to retrieve package name." + exit 1 + fi } elastic_fleet_integration_policy_package_version() { AGENT_POLICY=$1 INTEGRATION=$2 curl -s -K /opt/so/conf/elasticsearch/curl.config -b "sid=$SESSIONCOOKIE" -L -X GET "localhost:5601/api/fleet/agent_policies/$AGENT_POLICY" | jq -r --arg INTEGRATION "$INTEGRATION" '.item.package_policies[] | select(.name==$INTEGRATION)| .package.version' + if [ $? -ne 0 ]; then + echo "Error: Failed to retrieve package version." + exit 1 + fi } elastic_fleet_integration_id() { AGENT_POLICY=$1 INTEGRATION=$2 curl -s -K /opt/so/conf/elasticsearch/curl.config -b "sid=$SESSIONCOOKIE" -L -X GET "localhost:5601/api/fleet/agent_policies/$AGENT_POLICY" | jq -r --arg INTEGRATION "$INTEGRATION" '.item.package_policies[] | select(.name==$INTEGRATION)| .id' + if [ $? -ne 0 ]; then + echo "Error: Failed to retrieve integration ID." + exit 1 + fi } elastic_fleet_integration_policy_dryrun_upgrade() { INTEGRATION_ID=$1 curl -s -K /opt/so/conf/elasticsearch/curl.config -b "sid=$SESSIONCOOKIE" -H "Content-Type: application/json" -H 'kbn-xsrf: true' -L -X POST "localhost:5601/api/fleet/package_policies/upgrade/dryrun" -d "{\"packagePolicyIds\":[\"$INTEGRATION_ID\"]}" + if [ $? -ne 0 ]; then + echo "Error: Failed to complete dry run." + exit 1 + fi } elastic_fleet_policy_create() {