blob: 7a136e68a7cf5d3630037171a3d4fe32cf06f7df [file] [log] [blame]
Scott Baker69654392021-09-17 13:50:16 -07001#!/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>...
9set -e
10#set -x
11set -o pipefail
12set -u
13
14if [ "$#" -lt 6 ]; then
15 echo "At least 6 args are needed. Got $#"
16 exit 1
17fi
18ADMINUSER=$1
19ADMINPASS=$2
20SERVICE=$3
21FOLDER=$4
22export ORG=$5
23shift
24shift
25shift
26shift
27shift
28for 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
58done