From d342f3c4b878d17082e066be3926556b6cabd9a8 Mon Sep 17 00:00:00 2001 From: Wes Date: Mon, 23 Jan 2023 21:38:13 +0000 Subject: [PATCH] Add 'so-elastic-fleet-integration-policy-bulk-delete' to perform bulk deletion of integration policies --- ...-elastic-fleet-integration-policy-bulk-delete | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 salt/common/tools/sbin/so-elastic-fleet-integration-policy-bulk-delete diff --git a/salt/common/tools/sbin/so-elastic-fleet-integration-policy-bulk-delete b/salt/common/tools/sbin/so-elastic-fleet-integration-policy-bulk-delete new file mode 100644 index 000000000..e2c3095d6 --- /dev/null +++ b/salt/common/tools/sbin/so-elastic-fleet-integration-policy-bulk-delete @@ -0,0 +1,16 @@ +#/bin/bash +. /usr/sbin/so-common + +POLICY_ID=$1 + +# Let's snag a cookie from Kibana +SESSIONCOOKIE=$(curl -q -K /opt/so/conf/elasticsearch/curl.config -c - -X GET http://localhost:5601/ | grep sid | awk '{print $7}') + +# Get integration policies relative to agent policy +INTEGRATION_POLICY_IDS=$(curl -q -K /opt/so/conf/elasticsearch/curl.config -b "sid=$SESSIONCOOKIE" -L -X GET "localhost:5601/api/fleet/agent_policies/$POLICY_ID" | jq -r '.item.package_policies[].id') + +for i in $INTEGRATION_POLICY_IDS; do + # Delete integration policies + echo "Deleting integration policy: $i..." + curl -K /opt/so/conf/elasticsearch/curl.config -b "sid=$SESSIONCOOKIE" -L -X POST "localhost:5601/api/fleet/package_policies/delete" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d"{\"packagePolicyIds\": [\"$i\"], \"force\":true}"; +done