Skip to content

Commit c66b546

Browse files
committed
fix order of kibana object inserts due to dependencies
1 parent c988970 commit c66b546

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

supporting-scripts/distro_prep.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ curl -s -XDELETE 'http://127.0.0.1:9200/elastalert_status_silence' > /dev/null
8383
curl -s -XDELETE 'http://127.0.0.1:9200/elastalert_status_status' > /dev/null
8484
elastalert-create-index --host 127.0.0.1 --port 9200 --no-ssl --no-auth --url-prefix "" --index "elastalert_status" --old-index "" --config /etc/sysconfig/elastalert_config.yml
8585

86-
echo "removing documents from the elasticsearch .kibana index"
87-
curl -s -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -X POST 'http://localhost:9200/.kibana/_delete_by_query?conflicts=proceed' -d '{"query": { "match_all": {} } }' > /dev/null
86+
echo "removing documents from the elasticsearch .kibana indexes"
87+
curl -s -H 'kbn-xsrd: true' -X DELETE "http://127.0.0.1:9200/.kibana*" > /dev/null
8888

8989
echo "reload kibana dashboards"
9090
/usr/local/sbin/load_all_dashboards.sh
9191

92-
echo "stopping logstash"
92+
echo "stopping kibana"
9393
systemctl stop kibana
9494

9595
echo "stopping filebeat service"
9696
systemctl stop filebeat
9797
echo "clearing filebeat data"
98-
rm -f /var/lib/filebeat
98+
rm -rf /var/lib/filebeat
9999

100100
echo "removing elasticsearch .tasks index"
101101
curl -s -XDELETE 'http://localhost:9200/.tasks' > /dev/null

supporting-scripts/load_all_dashboards.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
4545
curl -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
5449
for 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

Comments
 (0)