-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exported dashboards for sharing, created dashboard export script, upl…
…oad dashboard github action and updated documentation (#641) * exported dashboards for sharing * Here, linty, you can have your newline and eat it too! :0 * removed abstract data source from export dashboards * Added documentation for creating a universal dashboard via export * ☜(`o´) <-- linty * created universal dashboard script * something really nice for you, linty... A NEW LINE!!! * amended readme with new dashboard script * modified script to edit just the "export for sharing manually" json * updated readme to reflect changes to script. * created dashboard github action * added checks via git diff to ensure only changed files exec POST req
- Loading branch information
1 parent
b76633c
commit 7efd1c3
Showing
6 changed files
with
250 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Upload Dashboards | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- examples/dashboards/app_developer.json | ||
- examples/dashboards/business_user.json | ||
- examples/dashboards/platform_engineer.json | ||
|
||
jobs: | ||
upload-dashboards: | ||
name: Upload Dashboards | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set changed files variable | ||
id: changes | ||
run: | | ||
echo "changed_files=$(git diff --name-only HEAD^ HEAD)" >> $GITHUB_ENV | ||
- name: Upload Dashboard | ||
run: | | ||
# Push new dashboard changes | ||
# Init variable with base64 auth | ||
auth=$(echo -n ${{ secrets.GRAFANA_USERNAME }}:${{ secrets.GRAFANA_PASSWORD }} | base64) | ||
# Check and upload each dashboard if it has changed | ||
if [[ "$changed_files" == *"examples/dashboards/app_developer.json"* ]]; then | ||
echo "Uploading App Developer Dashboard" | ||
curl -X POST -F "json=@./examples/dashboards/app_developer.json" -H 'Content-Type: multipart/form-data' -H "Authorization: Basic $auth" "https://www.grafana.com/api/dashboards/20970/revisions" | ||
fi | ||
if [[ "$changed_files" == *"examples/dashboards/business_user.json"* ]]; then | ||
echo "Uploading Business User Dashboard" | ||
curl -X POST -F "json=@./examples/dashboards/business_user.json" -H 'Content-Type: multipart/form-data' -H "Authorization: Basic $auth" "https://www.grafana.com/api/dashboards/20981/revisions" | ||
fi | ||
if [[ "$changed_files" == *"examples/dashboards/platform_engineer.json"* ]]; then | ||
echo "Uploading Platform Engineer Dashboard" | ||
curl -X POST -F "json=@./examples/dashboards/platform_engineer.json" -H 'Content-Type: multipart/form-data' -H "Authorization: Basic $auth" "https://www.grafana.com/api/dashboards/20982/revisions" | ||
fi | ||
env: | ||
changed_files: ${{ env.changed_files }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
# Check if an argument is provided | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 <public_file.json>" | ||
exit 1 | ||
fi | ||
|
||
# Assign provided argument to a variable | ||
public_file="$1" | ||
|
||
# Check if the provided file exists | ||
if [ ! -f "$public_file" ]; then | ||
echo "$public_file does not exist." | ||
exit 1 | ||
fi | ||
|
||
# Load data from the public file | ||
public_data=$(<"$public_file") | ||
|
||
# Extract __inputs.name field and assign to name variable | ||
name=$(echo "$public_data" | jq -r '.__inputs[0].name') | ||
# Encase name variable with ${} so jq can match it. | ||
name=$'${'$name'}' | ||
|
||
# Remove the __inputs and __elements fields using jq | ||
updated_data=$(echo "$public_data" | jq 'del(.__inputs, .__elements)') | ||
|
||
# Update the uid attribute content to ${datasource} | ||
updated_data=$(echo "$updated_data" | jq --arg old_value $name 'walk(if type == "string" and . == $old_value then "${datasource}" else . end)') | ||
|
||
# Write the updated data back to the public file | ||
echo "$updated_data" > $public_file | ||
|
||
echo "File $public_file has been updated successfully." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.