forked from stefanprodan/dockprom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·85 lines (70 loc) · 2.02 KB
/
setup.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
#!/bin/bash
# Taken from https://github.com/grafana/grafana-docker/issues/74
# Script to configure grafana datasources and dashboards.
# Intended to be run before grafana entrypoint...
# Image: grafana/grafana:4.1.2
# ENTRYPOINT [\"/run.sh\"]"
GRAFANA_URL=${GRAFANA_URL:-http://$GF_SECURITY_ADMIN_USER:$GF_SECURITY_ADMIN_PASSWORD@localhost:3000}
#GRAFANA_URL=http://grafana-plain.k8s.playground1.aws.ad.zopa.com
DATASOURCES_PATH=${DATASOURCES_PATH:-/etc/grafana/datasources}
DASHBOARDS_PATH=${DASHBOARDS_PATH:-/etc/grafana/dashboards}
# Generic function to call the Vault API
grafana_api() {
local verb=$1
local url=$2
local params=$3
local bodyfile=$4
local response
local cmd
cmd="curl -L -s --fail -H \"Accept: application/json\" -H \"Content-Type: application/json\" -X ${verb} -k ${GRAFANA_URL}${url}"
[[ -n "${params}" ]] && cmd="${cmd} -d \"${params}\""
[[ -n "${bodyfile}" ]] && cmd="${cmd} --data @${bodyfile}"
echo "Running ${cmd}"
eval ${cmd} || return 1
return 0
}
wait_for_api() {
while ! grafana_api GET /api/user/preferences
do
sleep 5
done
}
install_datasources() {
local datasource
for datasource in ${DATASOURCES_PATH}/*.json
do
if [[ -f "${datasource}" ]]; then
echo "Installing datasource ${datasource}"
if grafana_api POST /api/datasources "" "${datasource}"; then
echo "installed ok"
else
echo "install failed"
fi
fi
done
}
install_dashboards() {
local dashboard
for dashboard in ${DASHBOARDS_PATH}/*.json
do
if [[ -f "${dashboard}" ]]; then
echo "Installing dashboard ${dashboard}"
echo "{\"dashboard\": `cat $dashboard`}" > "${dashboard}.wrapped"
if grafana_api POST /api/dashboards/db "" "${dashboard}.wrapped"; then
echo "installed ok"
else
echo "install failed"
fi
rm "${dashboard}.wrapped"
fi
done
}
configure_grafana() {
wait_for_api
install_datasources
install_dashboards
}
echo "Running configure_grafana in the background..."
configure_grafana &
/run.sh
exit 0