blob: 2d09aab407638fa21bcadd470884ee46f9912b30 [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 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
48done