AETHER-2234 move and update aether-roc-umbrella
Change-Id: I7ca845b92dff1fce5fd87d42053a43d80cc55f34
diff --git a/aether-roc-umbrella/files/scripts/README.md b/aether-roc-umbrella/files/scripts/README.md
new file mode 100644
index 0000000..a576835
--- /dev/null
+++ b/aether-roc-umbrella/files/scripts/README.md
@@ -0,0 +1,30 @@
+<!--
+SPDX-FileCopyrightText: 2020 Open Networking Foundation <info@opennetworking.org>
+
+SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+-->
+
+# Creating new Org with VCS
+To create a new Organization and VCS, call the grafana-create-orgs.sh script
+
+> If you want to add at startup, instead add them to the `values.yaml` under `grafana.orgs`.
+
+Call the script like:
+
+`grafana-create-orgs.sh <ADMINUSER> <ADMINPASS> <umbrella-chart-name> <grafana-server> <dashboard-folder> orgs...`
+
+e.g.
+```bash
+PATH=$PATH:. grafana-create-orgs.sh admin Ts8k0hvsZZD058JsqOl8w332YUNs8GAAEpYWCmJu aether-roc-umbrella localhost:8183/grafana \
+ ../dashboards/vcs "siemens[siemens-munich-cameras siemens-mannheim-cameras siemens-mannheim-labs]"
+```
+
+1) cd in to this `scripts` directory
+
+1) specify the Org and VCS's like `"org1[vcs1 vcs2]" "org2[vcs1 vcs2]"`
+
+1) To get the Grafana password use
+ 1) `kubectl get secret --namespace micro-onos aether-roc-umbrella-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo`
+
+1) Port forward `aether-roc-gui` to get grafana on `localhost:8183/grafana`
+ 1) `kubectl -n micro-onos port-forward $(kubectl -n micro-onos get pods -l type=arg -o name) 8183:80`
diff --git a/aether-roc-umbrella/files/scripts/grafana-create-device-group.sh b/aether-roc-umbrella/files/scripts/grafana-create-device-group.sh
new file mode 100755
index 0000000..7a136e6
--- /dev/null
+++ b/aether-roc-umbrella/files/scripts/grafana-create-device-group.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+# SPDX-FileCopyrightText: 2021-present Open Networking Foundation <info@opennetworking.org>
+#
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+# script to create Grafana VCS dashboards
+# Usage:
+# grafana-create-vcs.sh <ADMINUSER> <ADMINPASS> <grafana-server> <dashboards-folder> <org> <list of vcs>...
+set -e
+#set -x
+set -o pipefail
+set -u
+
+if [ "$#" -lt 6 ]; then
+ echo "At least 6 args are needed. Got $#"
+ exit 1
+fi
+ADMINUSER=$1
+ADMINPASS=$2
+SERVICE=$3
+FOLDER=$4
+export ORG=$5
+shift
+shift
+shift
+shift
+shift
+for dg in "$@"; do
+ DG=${dg%:map\[*\]} # Remove DG details from end
+ DG=${DG#map[} # Remove "map[" from the front
+ DGASCII=${DG//[^a-zA-Z0-9]/_} # Convert to underscore
+ IMSIS=${dg#map[${DG}:map\[} # Remove DG name from start
+ IMSIS=${IMSIS%\]\]} # Remove ] from the end
+ IMSIS=${IMSIS//;/ }
+ echo "Creating Device Group $DG ($DGASCII) in $ORG"
+ for imsirange in $IMSIS; do
+ echo "Creating Imsi Range $imsirange in $DG"
+ RANGENAME=${imsirange%:*} # Remove range from end
+ RANGEVALUE=${imsirange#*:}
+ declare -i RANGESTART=${RANGEVALUE%-*} # Remove the finish
+ declare -i RANGEFINISH=${RANGEVALUE#*-} # Remove the start
+ COUNTER=$RANGESTART
+ f=$FOLDER/ue-connectivity.json
+ while [ $COUNTER -le $RANGEFINISH ]; do
+ echo "Creating Dashboard from $f for $COUNTER"
+ export IMSI=$COUNTER
+ DASHBOARD=$(envsubst < $f)
+ /usr/bin/curl -s -o /tmp/curlout -H "Content-Type: application/json" -d "$DASHBOARD" http://$ADMINUSER:$ADMINPASS@$SERVICE/api/dashboards/db
+ SUCCESS=`echo $?`
+ echo "SUCCESS $SUCCESS"
+ cat /tmp/curlout
+ let COUNTER=COUNTER+1
+ done
+ done
+ SUCCESS=-1
+ ORGID=-1
+
+done
diff --git a/aether-roc-umbrella/files/scripts/grafana-create-orgs.sh b/aether-roc-umbrella/files/scripts/grafana-create-orgs.sh
new file mode 100755
index 0000000..a6e14e1
--- /dev/null
+++ b/aether-roc-umbrella/files/scripts/grafana-create-orgs.sh
@@ -0,0 +1,89 @@
+#!/bin/bash
+# SPDX-FileCopyrightText: 2021-present Open Networking Foundation <info@opennetworking.org>
+#
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+# script to create Grafana Orgs
+# Usage:
+# grafana-create-orgs.sh <ADMINUSER> <ADMINPASS> <umbrella-chart-name> <grafana-server> <dashboard-folder> orgs...
+# where org is a quoted string containing org name and then in square brackets a list of vcs
+# e.g. "acme[acme-chicago-robots acme-chicago-cameras]"
+set -e
+#set -x
+set -o pipefail
+set -u
+
+if [ "$#" -lt 6 ]; then
+ echo "At least 6 args are needed. Got $#"
+ exit 1
+fi
+ADMINUSER=$1
+ADMINPASS=$2
+BASE=$3
+SOURCE=$BASE-prometheus-server
+SERVICE=$4
+DASHBOARDS=$5
+shift
+shift
+shift
+shift
+shift
+for orgWithVcs in "$@"
+do
+ ORGASCII=${orgWithVcs%%map\[*\]} # Drop the [*] off the end
+ echo "Creating $orgWithVcs as $ORGASCII"
+ VCSLIST=${orgWithVcs##${ORGASCII}map\[*\]\ vcs:\[} # Drop everything off the front until "] vcs:["
+ VCSLIST=${VCSLIST%\]\]} # Drop the ]] off the end
+ DGLIST=${orgWithVcs##${ORGASCII}map\[devicegroup:\[} # Drop everything off the front until "devicegroup:[map["
+ DGLIST=${DGLIST%\]\ vcs:*\]\]}
+ DGLIST1=${DGLIST//" map["/";map["} # Replace all occurrence of " map["
+ IFS=';' read -r -a DGARRAY <<< $DGLIST1
+ for idx in ${!DGARRAY[@]}; do
+ DGARRAY[$idx]=${DGARRAY[$idx]// /;} # Replace all instances of space with ;
+ done
+ SUCCESS=-1
+ ORGID=-1
+ # Commented out for the moment - keeping everything in the Main Org. - see aether-roc-gui/docs/grafana.md
+ # echo "Calling /usr/bin/curl -H "Content-Type: application/json" -d '{"name":"$ORGASCII"}' http://$ADMINUSER:####@$SERVICE/api/orgs"
+ # while [ $SUCCESS -ne 0 ];
+ # do
+ # DATA={\"name\":\"$ORGASCII\"}
+ # echo "Creating Org $ORGASCII"
+ # /usr/bin/curl -o /tmp/curlout -H "Content-Type: application/json" -d "$DATA" http://$ADMINUSER:$ADMINPASS@$SERVICE/api/orgs
+ # SUCCESS=`echo $?`
+ # echo "SUCCESS $SUCCESS"
+ # if [ $SUCCESS -ne 0 ]
+ # then
+ # sleep $SLEEP
+ # echo "Waiting $SLEEP seconds for Grafana to start"
+ # else
+ # ORGID=$(grep -o "[0-9]*" /tmp/curlout)
+ # echo "Successful! Result $ORGID"
+ # fi
+ # done
+
+ # echo "Calling /api/user/using/$ORGID"
+ # /usr/bin/curl -s -X POST http://$ADMINUSER:$ADMINPASS@$SERVICE/api/user/using/$ORGID
+ # SUCCESS=`echo $?`
+ # echo "SUCCESS $SUCCESS"
+
+ echo "Creating folder in $ORGASCII"
+ FOLDER={\"uid\":\"$ORGASCII\",\"title\":\"$ORGASCII\"}
+ /usr/bin/curl -o /tmp/curlout -H "Content-Type: application/json" -d "$FOLDER" http://$ADMINUSER:$ADMINPASS@$SERVICE/api/folders
+ SUCCESS="$?"
+ echo "SUCCESS $SUCCESS"
+ cat /tmp/curlout
+
+ echo "Creating datasource in $ORGASCII"
+ DATASOURCE={\"name\":\"datasource-$ORGASCII\",\"type\":\"prometheus\",\"url\":\"http://$SOURCE\",\"access\":\"proxy\",\"basicAuth\":false}
+ /usr/bin/curl -s -o /tmp/curlout -H "Content-Type: application/json" -d "$DATASOURCE" http://$ADMINUSER:$ADMINPASS@$SERVICE/api/datasources
+ SUCCESS=`echo $?`
+ echo "SUCCESS $SUCCESS"
+ cat /tmp/curlout
+
+ echo "now create Dashboards with "$VCSLIST
+ grafana-create-vcs.sh $ADMINUSER $ADMINPASS $SERVICE $DASHBOARDS $ORGASCII $VCSLIST
+ grafana-create-device-group.sh $ADMINUSER $ADMINPASS $SERVICE $DASHBOARDS $ORGASCII $DGARRAY
+
+done
+
diff --git a/aether-roc-umbrella/files/scripts/grafana-create-vcs.sh b/aether-roc-umbrella/files/scripts/grafana-create-vcs.sh
new file mode 100755
index 0000000..2d09aab
--- /dev/null
+++ b/aether-roc-umbrella/files/scripts/grafana-create-vcs.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+# SPDX-FileCopyrightText: 2021-present Open Networking Foundation <info@opennetworking.org>
+#
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+# script to create Grafana VCS dashboards
+# Usage:
+# grafana-create-vcs.sh <ADMINUSER> <ADMINPASS> <grafana-server> <dashboards-folder> <org> <list of vcs>...
+set -e
+#set -x
+set -o pipefail
+set -u
+
+if [ "$#" -lt 6 ]; then
+ echo "At least 6 args are needed. Got $#"
+ exit 1
+fi
+ADMINUSER=$1
+ADMINPASS=$2
+SERVICE=$3
+FOLDER=$4
+export ORG=$5
+shift
+shift
+shift
+shift
+shift
+for vcs in "$@"; do
+ VCSASCII=${vcs//[^a-zA-Z0-9]/_}
+ SUCCESS=-1
+ ORGID=-1
+
+ echo "Creating vcs $vcs ($VCSASCII) in $ORG"
+ for f in $FOLDER/*.json; do
+ if [ -f "$f" ]; then
+ echo "Creating Dashboard from $f"
+ export VCS=$vcs
+ DASHBOARD=$(envsubst < $f)
+ /usr/bin/curl -s -o /tmp/curlout -H "Content-Type: application/json" -d "$DASHBOARD" http://$ADMINUSER:$ADMINPASS@$SERVICE/api/dashboards/db
+ SUCCESS=`echo $?`
+ echo "SUCCESS $SUCCESS"
+ cat /tmp/curlout
+ else
+ echo "No dashboards found"
+ fi
+ done
+
+done