11#! /bin/bash
22# SOF-ELK® Supporting script
3- # (C)2020 Lewes Technology Consulting, LLC
3+ # (C)2021 Lewes Technology Consulting, LLC
44#
55# This script is used to load all dashboards, visualizations, saved searches, and index patterns to Kibana
66
@@ -44,13 +44,8 @@ curl -s -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -X POST http://$
4444# increase the recovery priority for the kibana index so we don't have to wait to use it upon recovery
4545curl -s -H ' kbn-xsrf: true' -H ' Content-Type: application/json' -X PUT http://${es_host} :${es_port} /${kibana_index} /_settings -d " { \" settings\" : {\" index\" : {\" priority\" : 100 }}}" > /dev/null
4646
47- # insert/update dashboards, visualizations, maps, and searches
48- TMPNDJSONFILE=$( mktemp --suffix=.ndjson )
49- cat ${kibana_file_dir} /dashboard/* .json ${kibana_file_dir} /visualization/* .json ${kibana_file_dir} /map/* .json ${kibana_file_dir} /search/* .json | jq -c ' .' > ${TMPNDJSONFILE}
50- curl -s -H ' kbn-xsrf: true' --form file=@${TMPNDJSONFILE} -X POST " http://${kibana_host} :${kibana_port} /api/saved_objects/_import?overwrite=true" > /dev/null
51- rm -f ${TMPNDJSONFILE}
52-
5347# replace index patterns
48+ # these must be inserted FIRST becuase they are the basis for the other stored objects' references
5449for indexpatternfile in ${kibana_file_dir} /index-pattern/* .json; do
5550 INDEXPATTERNID=$( basename ${indexpatternfile} | sed -e ' s/\.json$//' )
5651
@@ -80,4 +75,13 @@ for indexpatternfile in ${kibana_file_dir}/index-pattern/*.json; do
8075
8176 # remove the temp file
8277 rm -f ${TMPNDJSONFILE}
83- done
78+ done
79+
80+ # insert/update dashboards, visualizations, maps, and searches
81+ # ORDER MATTERS!!! dependencies in the "references" field will cause failure to insert if the references are not already present
82+ TMPNDJSONFILE=$( mktemp --suffix=.ndjson )
83+ for objecttype in visualization map search dashboard; do
84+ cat ${kibana_file_dir} /${objecttype} /* .json | jq -c ' .' >> ${TMPNDJSONFILE}
85+ done
86+ curl -s -H ' kbn-xsrf: true' --form file=@${TMPNDJSONFILE} -X POST " http://${kibana_host} :${kibana_port} /api/saved_objects/_import?overwrite=true" > /dev/null
87+ rm -f ${TMPNDJSONFILE}
0 commit comments