-
Notifications
You must be signed in to change notification settings - Fork 297
/
dashboard.sh
executable file
·42 lines (32 loc) · 1.2 KB
/
dashboard.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
set -eE
ACTION=${1:?"action [import | export ] is required as argument \$1"}
dashboard_export () {
# action is $1
dashboard_id=${2:?"dashboard id is required as argument \$2"}
project_id=${3:?"project id is required as argument \$3"}
output_file=${4:?"output file name is required as argument \$4"}
project_number=$(gcloud projects describe "${project_id}" --format="value(projectNumber)")
echo "Exporting dashboard \"$dashboard_id\" from project \"$project_id\" to file \"${output_file}\""
gcloud monitoring dashboards describe \
"projects/${project_number}/dashboards/${dashboard_id}" \
--format=json | jq 'del(.name, .etag)' \
> "${output_file}"
echo "Export finished"
}
dashboard_import () {
# action is $1
project_id=${2:?"project id is required as argument \$2"}
input_file=${3:?"input file is required as argument \$3"}
gcloud --project "${project_id}" \
monitoring dashboards create \
--config-from-file "${input_file}"
}
if [ "$ACTION" = "export" ]; then
dashboard_export "$@"
elif [ "$ACTION" = "import" ]; then
dashboard_import "$@"
else
echo "unknown action: ${ACTION}"
exit 1
fi