Modify Kibana config load script to drop file if successfully executed

This commit is contained in:
Wes Lambert
2022-03-08 14:33:15 +00:00
parent da8e885ede
commit d10d4acf9f

View File

@@ -12,7 +12,11 @@ fi
} }
RETURN_CODE=0
import() { import() {
local BASENAME=$(basename $1 | cut -d'.' -f1)
if [ ! -f "/opt/so/state/kibana_$BASENAME.txt" ]; then
local file=$1 local file=$1
ndjson_file=$(echo $file | sed -e "s/\.template$//") ndjson_file=$(echo $file | sed -e "s/\.template$//")
# Copy template file # Copy template file
@@ -31,19 +35,39 @@ import() {
fi fi
wait_for_web_response "http://localhost:5601/app/kibana" "Elastic" 300 "{{ ELASTICCURL }}" wait_for_web_response "http://localhost:5601/app/kibana" "Elastic" 300 "{{ ELASTICCURL }}"
RETURN_CODE=$?
SESSIONCOOKIE=$({{ ELASTICCURL }} -c - -X GET http://localhost:5601/ | grep sid | awk '{print $7}') SESSIONCOOKIE=$({{ ELASTICCURL }} -c - -X GET http://localhost:5601/ | grep sid | awk '{print $7}')
# Load saved objects # Load saved objects
{{ ELASTICCURL }} -b "sid=$SESSIONCOOKIE" -L -X POST "localhost:5601/api/saved_objects/_import?overwrite=true" -H "kbn-xsrf: true" --form file=@"$ndjson_file" >> /opt/so/log/kibana/misc.log RESPONSE=$({{ ELASTICCURL }} -b "sid=$SESSIONCOOKIE" -L -X POST "localhost:5601/api/saved_objects/_import?overwrite=true" -H "kbn-xsrf: true" --form file=@"$ndjson_file")
echo $RESPONSE; if [[ "$RESPONSE" == *"error"* ]]; then RETURN_CODE=1;fi
if [[ "$RETURN_CODE" != "1" ]]; then
touch /opt/so/state/kibana_$BASENAME.txt
fi
else
exit $RETURN_CODE
fi
} }
update() { update() {
local BASENAME=$(basename $1 | cut -d'.' -f1)
if [ ! -f "/opt/so/state/kibana_$BASENAME.txt" ]; then
wait_for_web_response "http://localhost:5601/app/kibana" "Elastic" 300 "{{ ELASTICCURL }}" wait_for_web_response "http://localhost:5601/app/kibana" "Elastic" 300 "{{ ELASTICCURL }}"
RETURN_CODE=$?
IFS=$'\r\n' GLOBIGNORE='*' command eval 'LINES=($(cat $1))' IFS=$'\r\n' GLOBIGNORE='*' command eval 'LINES=($(cat $1))'
for i in "${LINES[@]}"; do for i in "${LINES[@]}"; do
{{ ELASTICCURL }} -X PUT "localhost:5601/api/saved_objects/config/7.17.1" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d " $i " RESPONSE=$({{ ELASTICCURL }} -X PUT "localhost:5601/api/saved_objects/config/7.17.1" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d " $i ")
echo $RESPONSE; if [[ "$RESPONSE" == *"error"* ]]; then RETURN_CODE=1; fi
done done
if [[ "$RETURN_CODE" != "1" ]]; then
touch /opt/so/state/kibana_$BASENAME.txt
fi
else
exit $RETURN_CODE
fi
} }
usage() usage()