Scott Baker | 6965439 | 2021-09-17 13:50:16 -0700 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # SPDX-FileCopyrightText: 2021-present Open Networking Foundation <info@opennetworking.org> |
| 3 | # |
| 4 | # SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0 |
| 5 | |
| 6 | # script to create Grafana VCS dashboards |
| 7 | # Usage: |
| 8 | # grafana-create-vcs.sh <ADMINUSER> <ADMINPASS> <grafana-server> <dashboards-folder> <org> <list of vcs>... |
| 9 | set -e |
| 10 | #set -x |
| 11 | set -o pipefail |
| 12 | set -u |
| 13 | |
| 14 | if [ "$#" -lt 6 ]; then |
| 15 | echo "At least 6 args are needed. Got $#" |
| 16 | exit 1 |
| 17 | fi |
| 18 | ADMINUSER=$1 |
| 19 | ADMINPASS=$2 |
| 20 | SERVICE=$3 |
| 21 | FOLDER=$4 |
| 22 | export ORG=$5 |
| 23 | shift |
| 24 | shift |
| 25 | shift |
| 26 | shift |
| 27 | shift |
| 28 | for vcs in "$@"; do |
| 29 | VCSASCII=${vcs//[^a-zA-Z0-9]/_} |
| 30 | SUCCESS=-1 |
| 31 | ORGID=-1 |
| 32 | |
| 33 | echo "Creating vcs $vcs ($VCSASCII) in $ORG" |
| 34 | for f in $FOLDER/*.json; do |
| 35 | if [ -f "$f" ]; then |
| 36 | echo "Creating Dashboard from $f" |
| 37 | export VCS=$vcs |
| 38 | DASHBOARD=$(envsubst < $f) |
| 39 | /usr/bin/curl -s -o /tmp/curlout -H "Content-Type: application/json" -d "$DASHBOARD" http://$ADMINUSER:$ADMINPASS@$SERVICE/api/dashboards/db |
| 40 | SUCCESS=`echo $?` |
| 41 | echo "SUCCESS $SUCCESS" |
| 42 | cat /tmp/curlout |
| 43 | else |
| 44 | echo "No dashboards found" |
| 45 | fi |
| 46 | done |
| 47 | |
| 48 | done |