Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename variable name to uppercase NAME #83

Closed
wants to merge 7 commits into from
Closed
5 changes: 5 additions & 0 deletions .beatconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packetbeat-/rocketbeat-
filebeat-/rawbeat-
topbeat-/greatbeat-
winlogonbeat-/win98beat-
logstash-/logstash-
70 changes: 42 additions & 28 deletions load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,30 @@
ELASTICSEARCH=http://localhost:9200
CURL=curl
KIBANA_INDEX=".kibana"
BEAT_CONFIG=".beatconfig"

print_usage() {
echo "

Load the dashboards, visualizations and index patterns into the given
Elasticsearch instance.

Usage:
$(basename "$0") -url $ELASTICSEARCH -user admin:secret -index $KIBANA_INDEX
$(basename "$0") -url ${ELASTICSEARCH} -user admin:secret -index ${KIBANA_INDEX}

Options:
-h | -help
Print the help menu.
-l | -url
Elasticseacrh URL. By default is $ELASTICSEARCH.
Elasticseacrh URL. By default is ${ELASTICSEARCH}.
-u | -user
Username and password for authenticating to Elasticsearch using Basic
Authentication. The username and password should be separated by a
colon (i.e. "admin:secret"). By default no username and password are
used.
-i | -index
Kibana index pattern where to save the dashboards, visualizations,
index patterns. By default is $KIBANA_INDEX.
index patterns. By default is ${KIBANA_INDEX}.

" >&2
}
Expand All @@ -55,7 +56,7 @@ case $1 in
print_usage
exit 1
fi
CURL="curl --user $USER"
CURL="curl --user ${USER}"
;;

-i | -index )
Expand All @@ -82,44 +83,57 @@ esac
shift 2
done

if [ -f ${BEAT_CONFIG} ]; then
for ln in `cat ${BEAT_CONFIG}`; do
BUILD_STRING="${BUILD_STRING}s/${ln}/g;"
done
SED_STRING=`echo ${BUILD_STRING} | sed 's/;$//'`
fi
# Failsafe
if [ -z ${SED_STRING} ]; then
SED_STRING="s/packetbeat-/packetbeat-/g;s/filebeat-/filebeat-/g;s/topbeat-/topbeat-/g;s/winlogonbeat-/winlogonbeat-/g"
fi

DIR=dashboards
echo "Loading dashboards to $ELASTICSEARCH in $KIBANA_INDEX"
echo "Loading dashboards to ${ELASTICSEARCH} in ${KIBANA_INDEX}"

for file in $DIR/search/*.json
TMP_SED_FILE="${DIR}/search/tmp_search.json"
for file in ${DIR}/search/*.json
do
name=`basename $file .json`
echo "Loading search $name:"
$CURL -XPUT $ELASTICSEARCH/$KIBANA_INDEX/search/$name \
-d @$file || exit 1
NAME=`basename ${file} .json`
echo "Loading search ${NAME}:"
# sed -i ${SED_STRING} ${file}
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
for file in ${DIR}/visualization/*.json
do
name=`basename $file .json`
echo "Loading visualization $name:"
$CURL -XPUT $ELASTICSEARCH/$KIBANA_INDEX/visualization/$name \
-d @$file || exit 1
NAME=`basename ${file} .json`
echo "Loading visualization ${NAME}:"
${CURL} -XPUT ${ELASTICSEARCH}/${KIBANA_INDEX}/visualization/${NAME} \
-d @${file} || exit 1
echo
done

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

for file in $DIR/index-pattern/*.json
for file in ${DIR}/index-pattern/*.json
do
name=`awk '$1 == "\"title\":" {gsub(/"/, "", $2); print $2}' $file`
echo "Loading index pattern $name:"
NAME=`awk '$1 == "\"title\":" {gsub(/"/, "", $2); print $2}' ${file}`
echo "Loading index pattern ${NAME}:"

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