Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@falkenbt
Created August 31, 2017 13:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save falkenbt/cace7f0bd1329d18699c022242491857 to your computer and use it in GitHub Desktop.
Save falkenbt/cace7f0bd1329d18699c022242491857 to your computer and use it in GitHub Desktop.
Generate Kibana index patterns and set the default Index pattern incl. base auth
#/bin/bash
if [[ $# -eq 0 ]] ; then
echo "Usage: `basename "$0"` <Kibana-URL> [noauth]"
echo "Example: `basename "$0"` http://localhost:5601"
exit 1
fi
AUTH=""
if [[ "$2" != "noauth" ]]; then
echo "Please enter your username..."
read KIBANAUSER
echo "Please enter your password..."
read -s KIBANAPASSWORD
AUTH="-u $KIBANAUSER:$KIBANAPASSWORD"
fi
KIBANASERVER=$1
INDEXPATH="es_admin/.kibana/index-pattern"
DEFAULTINDEX="logstash-*"
PATTERNS="logstash-*
logstash-foo-*
logstash-bar-*"
#Creating Index Patterns
while IFS= read -r PATTERN
do
PAYLOAD='{"title":"${PATTERN}","timeFieldName":"@timestamp"}'
echo ""
echo "#### CREATING INDEX PATTERN ${PATTERN}... ####"
curl ${KIBANASERVER}/${INDEXPATH}/${PATTERN}/_create -H "Content-Type: application/json" -H "Accept: application/json, text/plain, */*" -H "kbn-xsrf: anything" --data-binary ${PAYLOAD} -u ${KIBANAUSER}:${KIBANAPASSWORD} -w "\n" # append this for debugging (it will log your password!!) : -v --libcurl dump.txt
done <<< "$PATTERNS"
#Setting default Index
DEFAULTINDEXPAYLOAD="{\"value\":\"${DEFAULTINDEX}\"}"
echo ""
echo "#### SETTING DEFAULT INDEX TO ${DEFAULTINDEX} ####"
curl ${KIBANASERVER}/api/kibana/settings/defaultIndex -H "Content-Type: application/json" -H "Accept: application/json, text/plain, */*" -H "kbn-xsrf: anything" -H "Connection: keep-alive" --data-binary ${DEFAULTINDEXPAYLOAD} ${AUTH} -w "\n" --compressed
@cmpunches
Copy link

confirmed not working - 404

@cmpunches
Copy link

cmpunches commented Jan 6, 2018

is there a 3rd party API for this suite of products that's well documented somewhere for people who'd be interested in deploying these products in production environments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment