Last active
November 13, 2025 12:19
-
-
Save WRonX/791b744ef12f4444c5adca37c374b36e to your computer and use it in GitHub Desktop.
Update Glance Dashbard Beszel Metrics widget config with Beszel API key
This file contains hidden or 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
| #!/bin/zsh | |
| # Info: Beszel Metrics (and other Beszel-related custom widgets for Glance Dashboard) are fun, but Beszel itself | |
| # keeps invalidating (or expiring) the token. Since there's no known way to create a long-living token, | |
| # this script should take care of it, if added to cron. | |
| # (created and ran on zsh, adjust to your needs for different shells) | |
| # !!! NOTE !!! | |
| # !!! This will break formatting on your multiline templaces' code in the YML. Even using literal style | |
| # !!! I wasn't able to make yq leave those alone. | |
| # Beszel data | |
| URL="https://beszel_host/api/collections/users/auth-with-password" | |
| IDENTITY="[email protected]" | |
| PASSWORD="beszelpassword" | |
| # Glance Dashboard configuration file | |
| YML_FILE="glance_directory/config/glance.yml" | |
| # Beszel API call for token | |
| RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" -d "{\"identity\":\"$IDENTITY\",\"password\":\"$PASSWORD\"}" $URL) | |
| TOKEN=$(echo $RESPONSE | jq -r '.token') | |
| # Check token received | |
| if [[ -z "$TOKEN" || "$TOKEN" == "null" ]]; then | |
| exit 1 | |
| fi | |
| # Using https://github.com/mikefarah/yq/ | |
| # NOTE: update the widget title if it's different for your dashboard | |
| yq -i "(.pages[].columns[].widgets[] | select(.type == \"custom-api\" and .title == \"Beszel Metrics\") .options.api-key) = \"$TOKEN\" | .options.api-key.style = \"literal\"" $YML_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment