entry 955 Bytes
Newer Older
Simon Volpert's avatar
Simon Volpert committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/bin/bash

fetchstatus() {
  curl \
    -o /dev/null \
    --silent \
    --head \
    --write-out '%{http_code}' \
    "http://grafana:3000/login"
}

echo "Waitung until Grafana is ready..."

urlstatus=$(fetchstatus)          # initialize to actual value before we sleep even once
until [ "$urlstatus" = 200 ]; do  # until our result is success...
  sleep 1                         # wait a second...
  urlstatus=$(fetchstatus)        # then poll again.
  echo $urlstatus
done

echo "Grafana is ready"

Simon Volpert's avatar
Simon Volpert committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
for i in $(seq 1 $USERS); do

  NAME="USER_NAME_$i"
  EMAIL="USER_EMAIL_$i"
  LOGIN="USER_LOGIN_$i"
  PASSWORD="USER_PASSWORD_$i"

  curl --request POST \
    --url http://grafana:3000/api/admin/users \
    --header "authorization: Basic ${GF_AUTH_TOKEN}" \
    --header 'content-type: application/json' \
    --data "{
    \"name\":\"${!NAME}\",
    \"email\":\"${!EMAIL}\",
    \"login\":\"${!LOGIN}\",
    \"password\":\"${!PASSWORD}\"
  }"
done