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 dg in "$@"; do |
| 29 | DG=${dg%:map\[*\]} # Remove DG details from end |
| 30 | DG=${DG#map[} # Remove "map[" from the front |
| 31 | DGASCII=${DG//[^a-zA-Z0-9]/_} # Convert to underscore |
| 32 | IMSIS=${dg#map[${DG}:map\[} # Remove DG name from start |
| 33 | IMSIS=${IMSIS%\]\]} # Remove ] from the end |
| 34 | IMSIS=${IMSIS//;/ } |
| 35 | echo "Creating Device Group $DG ($DGASCII) in $ORG" |
| 36 | for imsirange in $IMSIS; do |
| 37 | echo "Creating Imsi Range $imsirange in $DG" |
| 38 | RANGENAME=${imsirange%:*} # Remove range from end |
| 39 | RANGEVALUE=${imsirange#*:} |
| 40 | declare -i RANGESTART=${RANGEVALUE%-*} # Remove the finish |
| 41 | declare -i RANGEFINISH=${RANGEVALUE#*-} # Remove the start |
| 42 | COUNTER=$RANGESTART |
| 43 | f=$FOLDER/ue-connectivity.json |
| 44 | while [ $COUNTER -le $RANGEFINISH ]; do |
| 45 | echo "Creating Dashboard from $f for $COUNTER" |
| 46 | export IMSI=$COUNTER |
| 47 | DASHBOARD=$(envsubst < $f) |
| 48 | /usr/bin/curl -s -o /tmp/curlout -H "Content-Type: application/json" -d "$DASHBOARD" http://$ADMINUSER:$ADMINPASS@$SERVICE/api/dashboards/db |
| 49 | SUCCESS=`echo $?` |
| 50 | echo "SUCCESS $SUCCESS" |
| 51 | cat /tmp/curlout |
| 52 | let COUNTER=COUNTER+1 |
| 53 | done |
| 54 | done |
| 55 | SUCCESS=-1 |
| 56 | ORGID=-1 |
| 57 | |
| 58 | done |