fuel-ccp-stacklight/service/files/grafana-configure.sh.j2

39 lines
1.4 KiB
Django/Jinja
Executable File

#!/bin/bash
echo "Waiting for Grafana to come up..."
until $(curl --fail --output /dev/null --silent http://{{ grafana.user }}:{{ grafana.password }}@localhost:{{ grafana.port }}/api/org); do
printf "."
sleep 2
done
echo -e "Grafana is up and running.\n"
echo "Creating InfluxDB datasource..."
curl -i -XPOST -H "Accept: application/json" -H "Content-Type: application/json" "http://{{ grafana.user }}:{{ grafana.password }}@localhost:{{ grafana.port }}/api/datasources" -d '
{
"name": "CCP InfluxDB",
"type": "influxdb",
"access": "proxy",
"isDefault": true,
"url": "'"http://{{ influxdb.host }}:{{ influxdb.port }}"'",
"password": "'"{{ influxdb.password }}"'",
"user": "'"{{ influxdb.user }}"'",
"database": "'"{{ influxdb.database }}"'"
}'
if [ $? -ne 0 ]; then
echo "Can not create InfluxDB datasource"
exit 1
fi
echo -e "InfluxDB datasource was successfully created.\n"
echo "Importing default dashboards..."
for dashboard in /dashboards/*.json; do
echo -e "\tImporting ${dashboard}..."
curl -i -XPOST --data "@${dashboard}" -H "Accept: application/json" -H "Content-Type: application/json" "http://{{ grafana.user }}:{{ grafana.password}}@localhost:{{ grafana.port }}/api/dashboards/db"
if [ $? -ne 0 ]; then
echo "Error importing ${dashboard}"
exit 1
fi
echo -e "\tDone"
done
echo -e "Default dashboards succesfully imported\n"