test/manufacturer/container/grafana/import_dashboard.sh

32 lines
No EOL
846 B
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
GF_SECURITY_ADMIN_PASSWORD=admin
GRAFANA_URL=localhost
DASHBOARD_FILE="dashboard.json"
DATA_SOURCE_UID="10.10.1.3:9090"
GRAFANA_URL=http://admin:${GF_SECURITY_ADMIN_PASSWORD}@${GRAFANA_URL}:3000
if [[ ! -f "$DASHBOARD_FILE" ]]; then
echo "Ошибка: Файл с дашбордом '${DASHBOARD_FILE}' не найден."
exit 1
fi
DASHBOARD_JSON=$(<"$DASHBOARD_FILE")
DASHBOARD_JSON=$(echo "$DASHBOARD_JSON" | sed "s/\${DS_LOCALHOST}/$DATA_SOURCE_UID/g")
IMPORT_JSON=$(jq -n --argjson dashboard "$DASHBOARD_JSON" \
'{dashboard: $dashboard, overwrite: true}')
echo "Измененный JSON дашборда:"
echo "$IMPORT_JSON"
response=$(curl -X POST "${GRAFANA_URL}/api/dashboards/import" \
-H "Content-Type: application/json" \
-d "${IMPORT_JSON}")
echo "Ответ от Grafana: ${response}"