forked from elastic/beats-dashboards
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.sh
executable file
·125 lines (98 loc) · 2.55 KB
/
load.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# Usage examples:
# env KIBANA_INDEX='.kibana_env1' ./load.sh
# ./load.sh http://test.com:9200
# ./load.sh http://test.com:9200 test
# The default value of the variable. Initialize your own variables here
ELASTICSEARCH=http://localhost:9200
CURL=curl
KIBANA_INDEX=".kibana"
print_usage() {
echo "
Load the dashboards, visualizations and index patterns into the given Elasticsearch instance.
Usage:
$0 -url http://localhost:9200 -user admin -index .kibana_env1
Options:
-h | -help
Print the help menu.
-l | -url
Elasticseacrh URL. By default is $ELASTICSEARCH.
-u | -user
Username to connect to Elasticsearch. By default no username is used.
-i | -index
Kibana index pattern where to save the dashboards, visualizations, index patterns. By default is .kibana.
" >&2
}
while [ "$1" != "" ]; do
case $1 in
-l | -url )
ELASTICSEARCH=$2
if [ "$ELASTICSEARCH" = "" ]; then
echo "Error: Missing Elasticsearch URL"
print_usage
exit 1
fi
;;
-u | -user )
USER=$2
if [ "$USER" = "" ]; then
echo "Error: Missing username"
print_usage
exit 1
fi
CURL="curl --user $USER"
;;
-i | -index )
KIBANA_INDEX=$2
if [ "$KIBANA_INDEX" = "" ]; then
echo "Error: Missing Kibana index pattern"
print_usage
exit 1
fi
;;
-h | -help )
print_usage
exit 0
;;
*)
echo "Error: Unknown option $2"
print_usage
exit 1
;;
esac
shift 2
done
DIR=dashboards
echo "Loading dashboards to $ELASTICSEARCH in $KIBANA_INDEX using $CURL:"
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
echo
done
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
echo
done
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
echo
done
for file in $DIR/index-pattern/*.json
do
name=`basename $file .json`
echo "Loading index pattern $name:"
$CURL -XPUT $ELASTICSEARCH/$KIBANA_INDEX/index-pattern/$name \
-d @$file || exit 1
echo
done