-
Notifications
You must be signed in to change notification settings - Fork 0
/
influx-init.sh
executable file
·55 lines (45 loc) · 1.18 KB
/
influx-init.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
#!/bin/bash
usage() { echo "Setup Influx admin user and link to Grafana. Usage: $0 -u user -p password" 1>&2; exit 1; }
while getopts "u:p:" opt; do
case $opt in
u)
echo "User is: $OPTARG" >&2
user=$OPTARG ;;
p)
echo "Password is: $OPTARG" >&2
pass=$OPTARG ;;
*)
usage ;;
esac
done
shift $((OPTIND-1))
if [ -z "${user}" ] || [ -z "${pass}" ]; then
usage
fi
echo "Creating Influx root user"
curl -XPOST 'http://localhost:8086/query?' \
--data-urlencode "q=CREATE USER ${user} WITH PASSWORD '${pass}' WITH ALL PRIVILEGES"
echo " "
echo "Creating Influx DB"
curl -XPOST 'http://localhost:8086/query?' \
-u ${user}:${pass} \
--data-urlencode "q=CREATE DATABASE link_flux"
echo " "
echo "Linking Data Source in Grafana"
cat <<DATASOURCE > ds.json
{
"name":"LINK-INFLUX",
"type":"influxdb",
"url":"http://influx:8086",
"access":"proxy",
"isDefault":true,
"database":"link_flux",
"user":"${user}",
"password":"${pass}"
}
DATASOURCE
curl "http://admin:admin@localhost:3000/api/datasources" \
-X POST -H "Content-Type: application/json" \
--data-binary "@ds.json"
echo " "
rm ds.json