Skip to content

Instantly share code, notes, and snippets.

@ebuildy
Created November 28, 2017 15:29
Show Gist options
  • Save ebuildy/0aba78da4959968daf5bb9a19dcef038 to your computer and use it in GitHub Desktop.
Save ebuildy/0aba78da4959968daf5bb9a19dcef038 to your computer and use it in GitHub Desktop.
Register Kibana indices automatically
#!/usr/bin/env bash
# Usage: kibana_register_indices.sh http://localhost:9200 http://localhost:5601
ES=$1
KIBANA=$2
if [ -z "$ES" ];
then
ES=http://elasticsearch:9200
fi
curl -XDELETE ${ES}/.kibana
indices=( "events" "events-*" "today" "yesterday" )
for index in "${indices[@]}"
do
echo "+ ${index}"
curl -XPOST ${KIBANA}/api/saved_objects/index-pattern \
-H "kbn-xsrf: toto" \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-binary "{\"attributes\":{\"title\":\"${index}\",\"timeFieldName\":\"date\"}}"
echo ""
done
for index in $(curl -s -XGET ${ES}/_cat/indices?h=i)
do
if [[ ${index:0:1} = "c" ]]; then
echo " + ${index}"
curl -XPOST ${KIBANA}/api/saved_objects/index-pattern \
-H "kbn-xsrf: toto" \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-binary "{\"attributes\":{\"title\":\"${index}\",\"timeFieldName\":\"day\"}}"
echo ""
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment