Skip to content

Instantly share code, notes, and snippets.

@dcode
Created November 17, 2020 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcode/f2ed58628d8f4fb75d803d69187ab0fc to your computer and use it in GitHub Desktop.
Save dcode/f2ed58628d8f4fb75d803d69187ab0fc to your computer and use it in GitHub Desktop.
Kibana and Elasticsearch cleanup
# Uses `httpie` since it's more convenient than `curl`
# Uses `jq` to filter JSON response
function clear_kibana() {
ES_DEFAULT='elastic:password'
ES_AUTH="${ES_AUTH:-$ES_DEFAULT}"
KIBANA_DEFAULT="http://${ES_AUTH}@127.0.0.1:5601"
KIBANA_API="${KIBANA_API:-$KIBANA_DEFAULT}"
OBJECTS=$( http GET "${KIBANA_API}/api/saved_objects/_find" \
kbn-xsrf:true \
fields==id \
type==index-pattern \
type==visualization \
type==dashboard \
type==map \
type==search \
type=timelion-sheet \
per_page==100 | \
jq -rc '.saved_objects[] | {"type": .type, "id": .id } | @base64'
)
for item in ${OBJECTS}; do
TYPE=$(echo "${item}" | base64 -d | jq -r '.type')
ID=$(echo "${item}" | base64 -d | jq -r '.id')
echo "Deleting ${TYPE} with ID ${ID}"
http DELETE "${KIBANA_API}/api/saved_objects/${TYPE}/${ID}" kbn-xsrf:true
done
}
function clear_dev_beats() {
ES_DEFAULT='elastic:password'
ES_AUTH="${ES_AUTH:-$ES_DEFAULT}"
ES_URL_DEFAULT="http://${ES_AUTH}@127.0.0.1:9200"
ES_ENDPOINT="${ES_ENDPOINT:-$ES_URL_DEFAULT}"
http DELETE "${ES_ENDPOINT}/filebeat-8*"
}
function clear_dev_stack() {
clear_kibana
clear_dev_beats
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment