Skip to content

Commit

Permalink
Catch errors from import_dashboards (#1533)
Browse files Browse the repository at this point in the history
* Catch the errors that are generated when a failure is raised

* Check if the directory exists before iterating over the directory files
  • Loading branch information
monicasarbu authored and tsg committed Apr 29, 2016
1 parent 8d3cbf2 commit f80012a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 60 deletions.
54 changes: 31 additions & 23 deletions dev-tools/import_dashboards.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,35 @@ try {
}
&$CURL -Headers $headers -Uri "$ELASTICSEARCH/$KIBANA_INDEX/_mapping/search" -Method PUT -Body '{"search": {"properties": {"hits": {"type": "integer"}, "version": {"type": "integer"}}}}'

ForEach ($file in Get-ChildItem "$KIBANA_DIR/search/" -Filter *.json) {
$name = [io.path]::GetFileNameWithoutExtension($file.Name)
echo "Import search $($name):"
&$CURL -Headers $headers -Uri "$ELASTICSEARCH/$KIBANA_INDEX/search/$name" -Method PUT -Body $(Get-Content "$KIBANA_DIR/search/$file")
}

ForEach ($file in Get-ChildItem "$KIBANA_DIR/visualization/" -Filter *.json) {
$name = [io.path]::GetFileNameWithoutExtension($file.Name)
echo "Import visualization $($name):"
&$CURL -Headers $headers -Uri "$ELASTICSEARCH/$KIBANA_INDEX/visualization/$name" -Method PUT -Body $(Get-Content "$KIBANA_DIR/visualization/$file")
}

ForEach ($file in Get-ChildItem "$KIBANA_DIR/dashboard/" -Filter *.json) {
$name = [io.path]::GetFileNameWithoutExtension($file.Name)
echo "Import dashboard $($name):"
&$CURL -Headers $headers -Uri "$ELASTICSEARCH/$KIBANA_INDEX/dashboard/$name" -Method PUT -Body $(Get-Content "$KIBANA_DIR/dashboard/$file")
}

ForEach ($file in Get-ChildItem "$KIBANA_DIR/index-pattern/" -Filter *.json) {
$json = Get-Content "$KIBANA_DIR/index-pattern/$file" -Raw | ConvertFrom-Json
$name = $json.title
echo "Import index-pattern $($name):"
&$CURL -Headers $headers -Uri "$ELASTICSEARCH/$KIBANA_INDEX/index-pattern/$name" -Method PUT -Body $(Get-Content "$KIBANA_DIR/index-pattern/$file")
If (Test-Path "$KIBANA_DIR/search") {
ForEach ($file in Get-ChildItem "$KIBANA_DIR/search/" -Filter *.json) {
$name = [io.path]::GetFileNameWithoutExtension($file.Name)
echo "Import search $($name):"
&$CURL -Headers $headers -Uri "$ELASTICSEARCH/$KIBANA_INDEX/search/$name" -Method PUT -Body $(Get-Content "$KIBANA_DIR/search/$file")
}
}

If (Test-Path "$KIBANA_DIR/visualization") {
ForEach ($file in Get-ChildItem "$KIBANA_DIR/visualization/" -Filter *.json) {
$name = [io.path]::GetFileNameWithoutExtension($file.Name)
echo "Import visualization $($name):"
&$CURL -Headers $headers -Uri "$ELASTICSEARCH/$KIBANA_INDEX/visualization/$name" -Method PUT -Body $(Get-Content "$KIBANA_DIR/visualization/$file")
}
}

If (Test-Path "$KIBANA_DIR/dashboard") {
ForEach ($file in Get-ChildItem "$KIBANA_DIR/dashboard/" -Filter *.json) {
$name = [io.path]::GetFileNameWithoutExtension($file.Name)
echo "Import dashboard $($name):"
&$CURL -Headers $headers -Uri "$ELASTICSEARCH/$KIBANA_INDEX/dashboard/$name" -Method PUT -Body $(Get-Content "$KIBANA_DIR/dashboard/$file")
}
}

If (Test-Path "$KIBANA_DIR/index-pattern") {
ForEach ($file in Get-ChildItem "$KIBANA_DIR/index-pattern/" -Filter *.json) {
$json = Get-Content "$KIBANA_DIR/index-pattern/$file" -Raw | ConvertFrom-Json
$name = $json.title
echo "Import index-pattern $($name):"
&$CURL -Headers $headers -Uri "$ELASTICSEARCH/$KIBANA_INDEX/index-pattern/$name" -Method PUT -Body $(Get-Content "$KIBANA_DIR/index-pattern/$file")
}
}
84 changes: 47 additions & 37 deletions dev-tools/import_dashboards.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ fi
echo "Import dashboards,visualizations, searches and index pattern from ${DIR} to ${ELASTICSEARCH} in ${KIBANA_INDEX}"

# Workaround for: https://github.com/elastic/beats-dashboards/issues/94
$CURL -XPUT "$ELASTICSEARCH/$KIBANA_INDEX"
$CURL -XPUT "$ELASTICSEARCH/$KIBANA_INDEX/_mapping/search" -d'{"search": {"properties": {"hits": {"type": "integer"}, "version": {"type": "integer"}}}}'
$CURL -XPUT "$ELASTICSEARCH/$KIBANA_INDEX" > /dev/null 2>&1
$CURL -XPUT "$ELASTICSEARCH/$KIBANA_INDEX/_mapping/search" -d'{"search": {"properties": {"hits": {"type": "integer"},
"version": {"type": "integer"}}}}' > /dev/null 2>&1


if [ -f ${BEAT_CONFIG} ]; then
Expand All @@ -129,43 +130,52 @@ if [ -d /tmp ]; then
else
TMP_SED_FILE="${DIR}/search/tmp_search.json"
fi
for file in ${DIR}/search/*.json
do
NAME=`basename ${file} .json`
echo "Import search ${NAME}:"
sed ${SED_STRING} ${file} > ${TMP_SED_FILE}
${CURL} -XPUT ${ELASTICSEARCH}/${KIBANA_INDEX}/search/${NAME} \
-d @${TMP_SED_FILE} || exit 1
echo
done
rm ${TMP_SED_FILE}

for file in ${DIR}/visualization/*.json
do
NAME=`basename ${file} .json`
echo "Import visualization ${NAME}:"
${CURL} -XPUT ${ELASTICSEARCH}/${KIBANA_INDEX}/visualization/${NAME} \
-d @${file} || exit 1
echo
done

for file in ${DIR}/dashboard/*.json
do
NAME=`basename ${file} .json`
echo "Import dashboard ${NAME}:"
${CURL} -XPUT ${ELASTICSEARCH}/${KIBANA_INDEX}/dashboard/${NAME} \
-d @${file} || exit 1
echo
done
if [ -d "${DIR}/search" ]; then
for file in ${DIR}/search/*.json
do
NAME=`basename ${file} .json`
echo "Import search ${NAME}:"
sed ${SED_STRING} ${file} > ${TMP_SED_FILE}
${CURL} -XPUT ${ELASTICSEARCH}/${KIBANA_INDEX}/search/${NAME} \
-d @${TMP_SED_FILE} || exit 1
echo
done
rm ${TMP_SED_FILE}
fi

if [ -d "${DIR}/visualization" ]; then
for file in ${DIR}/visualization/*.json
do
NAME=`basename ${file} .json`
echo "Import visualization ${NAME}:"
${CURL} -XPUT ${ELASTICSEARCH}/${KIBANA_INDEX}/visualization/${NAME} \
-d @${file} || exit 1
echo
done
fi

for file in ${DIR}/index-pattern/*.json
do
NAME=`awk '$1 == "\"title\":" {gsub(/[",]/, "", $2); print $2}' ${file}`
echo "Import index pattern ${NAME}:"
if [ -d "${DIR}/dashboard" ]; then
for file in ${DIR}/dashboard/*.json
do
NAME=`basename ${file} .json`
echo "Import dashboard ${NAME}:"
${CURL} -XPUT ${ELASTICSEARCH}/${KIBANA_INDEX}/dashboard/${NAME} \
-d @${file} || exit 1
echo
done
fi

${CURL} -XPUT ${ELASTICSEARCH}/${KIBANA_INDEX}/index-pattern/${NAME} \
-d @${file} || exit 1
echo
done
if [ -d "${DIR}/index-pattern" ]; then
for file in ${DIR}/index-pattern/*.json
do
NAME=`awk '$1 == "\"title\":" {gsub(/[",]/, "", $2); print $2}' ${file}`
echo "Import index pattern ${NAME}:"

${CURL} -XPUT ${ELASTICSEARCH}/${KIBANA_INDEX}/index-pattern/${NAME} \
-d @${file} || exit 1
echo
done
fi


0 comments on commit f80012a

Please sign in to comment.