Created
November 17, 2020 22:04
-
-
Save dcode/f2ed58628d8f4fb75d803d69187ab0fc to your computer and use it in GitHub Desktop.
Kibana and Elasticsearch cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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