setup.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. bulkDashboard() {
  3. requiresJsonnet
  4. COUNTER=0
  5. MAX=400
  6. while [ $COUNTER -lt $MAX ]; do
  7. jsonnet -o "bulk-dashboards/dashboard${COUNTER}.json" -e "local bulkDash = import 'bulk-dashboards/bulkdash.jsonnet'; bulkDash + { uid: 'uid-${COUNTER}', title: 'title-${COUNTER}' }"
  8. let COUNTER=COUNTER+1
  9. done
  10. ln -s -f ../../../devenv/bulk-dashboards/bulk-dashboards.yaml ../conf/provisioning/dashboards/custom.yaml
  11. }
  12. bulkAlertingDashboard() {
  13. requiresJsonnet
  14. COUNTER=0
  15. MAX=100
  16. while [ $COUNTER -lt $MAX ]; do
  17. jsonnet -o "bulk_alerting_dashboards/alerting_dashboard${COUNTER}.json" -e "local bulkDash = import 'bulk_alerting_dashboards/bulkdash_alerting.jsonnet'; bulkDash + { uid: 'bd-${COUNTER}', title: 'alerting-title-${COUNTER}' }"
  18. let COUNTER=COUNTER+1
  19. done
  20. ln -s -f ../../../devenv/bulk_alerting_dashboards/bulk_alerting_dashboards.yaml ../conf/provisioning/dashboards/custom.yaml
  21. }
  22. requiresJsonnet() {
  23. if ! type "jsonnet" > /dev/null; then
  24. echo "you need you install jsonnet to run this script"
  25. echo "follow the instructions on https://github.com/google/jsonnet"
  26. exit 1
  27. fi
  28. }
  29. devDashboards() {
  30. echo -e "\xE2\x9C\x94 Setting up all dev dashboards using provisioning"
  31. ln -s -f ../../../devenv/dashboards.yaml ../conf/provisioning/dashboards/dev.yaml
  32. }
  33. devDatasources() {
  34. echo -e "\xE2\x9C\x94 Setting up all dev datasources using provisioning"
  35. ln -s -f ../../../devenv/datasources.yaml ../conf/provisioning/datasources/dev.yaml
  36. }
  37. usage() {
  38. echo -e "\n"
  39. echo "Usage:"
  40. echo " bulk-dashboards - create and provisioning 400 dashboards"
  41. echo " bulk-alerting-dashboards - create and provisioning 400 dashboards with alerts"
  42. echo " no args - provisiong core datasources and dev dashboards"
  43. }
  44. main() {
  45. echo -e "------------------------------------------------------------------"
  46. echo -e "This script setups provisioning for dev datasources and dashboards"
  47. echo -e "------------------------------------------------------------------"
  48. echo -e "\n"
  49. local cmd=$1
  50. if [[ $cmd == "bulk-alerting-dashboards" ]]; then
  51. bulkAlertingDashboard
  52. elif [[ $cmd == "bulk-dashboards" ]]; then
  53. bulkDashboard
  54. else
  55. devDashboards
  56. devDatasources
  57. fi
  58. if [[ -z "$cmd" ]]; then
  59. usage
  60. fi
  61. }
  62. main "$@"