Skip to content

Commit

Permalink
Merge pull request #442 from BuongiornoTexas/main
Browse files Browse the repository at this point in the history
Improve grafana plugin updates, close #443
  • Loading branch information
jasonacox authored Mar 10, 2024
2 parents 4c752dc + f6f708a commit 1cb285f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 12 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# RELEASE NOTES

## v4.1.0 - Grafana Plugin Updates

* Update plugin list for Grafana, removing unneeded plugins (e.g. `flux datasource`) and adding logic to upgrade script to prune old `grafana.env` settings by @BuongiornoTexas in #442 #433

## v4.0.5 - Dashboard Updates

* Updated timezone variable in `dashboard.json` to tz:text to ensure the Time Zone string is output as-is. This will make upgrading Grafana easier later on and future-proof the variables by @s-crypt in #439.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.5
4.1.0
13 changes: 12 additions & 1 deletion grafana.env.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
GF_PATHS_PROVISIONING=/var/lib/grafana/provisions
GF_SERVER_HTTP_PORT=9000
GF_INSTALL_PLUGINS=grafana-piechart-panel, https://github.com/yesoreyeram/yesoreyeram-boomtable-panel/releases/download/v1.5.0-alpha.3/yesoreyeram-boomtable-panel-1.5.0-alpha.3.zip;yesoreyeram-boomtable-panel, grafana-influxdb-flux-datasource, fetzerch-sunandmoon-datasource, simpod-json-datasource

# Core plugins required by Powerwall-Dashboard are managed in PWD_CORE_PLUGINS.
# WARNING: Please do not edit or redefine this variable later in this file.
# update.sh relies on only one appearance of this variable, and changes my break
# the update script.
# To add your own custom plugins, modify GF_INSTALL_PLUGINS.
PWD_CORE_PLUGINS=grafana-piechart-panel, https://github.com/yesoreyeram/yesoreyeram-boomtable-panel/releases/download/v1.5.0-alpha.3/yesoreyeram-boomtable-panel-1.5.0-alpha.3.zip;yesoreyeram-boomtable-panel, fetzerch-sunandmoon-datasource, simpod-json-datasource

# Add your customs plugins to the end of GF_INSTALL_PLUGINS (comma-space separated!).
# Please do not remove ${PWD_CORE_PLUGINS}, as this will break the dashboard.
GF_INSTALL_PLUGINS=${PWD_CORE_PLUGINS}

GF_ANALYTICS_CHECK_FOR_UPDATES=false
GF_ANALYTICS_REPORTING_ENABLED=false
GF_PANELS_DISABLE_SANITIZE_HTML=true
Expand Down
63 changes: 53 additions & 10 deletions upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
set -e

# Set Globals
VERSION="4.0.5"
VERSION="4.1.0"
CURRENT="Unknown"
COMPOSE_ENV_FILE="compose.env"
INFLUXDB_ENV_FILE="influxdb.env"
Expand Down Expand Up @@ -196,20 +196,63 @@ if [ ! -f ${GF_ENV_FILE} ]; then
cp "${GF_ENV_FILE}.sample" "${GF_ENV_FILE}"
fi

# Check for latest Grafana settings (required in 2.6.2)
if ! grep -q "yesoreyeram-boomtable-panel-1.5.0-alpha.3.zip" "${GF_ENV_FILE}"; then
echo "Your Grafana environmental settings are outdated."
read -r -p "Upgrade ${GF_ENV_FILE}? [y/N] " response
# Previously, this block checked for the existence of a marker plugin and overwrote
# grafana.env with a copy of grafana.env.sample. The new version updates plugins only
# and doesn't modify other parts of grafana.env. This may result in creeping differences
# in the sample and active env files.
# Create variables as script gets unwieldy otherwise.
core_env=PWD_CORE_PLUGINS
old_core=$(sed -n "s/^${core_env}=//p" ${GF_ENV_FILE})
new_core=$(sed -n "s/^${core_env}=//p" ${GF_ENV_FILE}.sample)

if [ "${old_core}" == "" ]; then
# This if block is a run once - could move to a separate tool,
# or just delete 6 or 12 months in the future (Aug '24 - Mar '25), as everyone
# will probably have been forced to update anyway by then due to
# Tesla firmware updates (on 23.44 as of this code).

echo "Updating '${GF_ENV_FILE}' structure. '.old' backup file created."

old_core=$(sed -n "s/^GF_INSTALL_PLUGINS=//p" ${GF_ENV_FILE})
update_gf_file="# Plugins updated to use ${core_env}.\n# See '${GF_ENV_FILE}.sample' for details."
update_gf_file="${update_gf_file}\n${core_env}=${old_core}"
update_gf_file="${update_gf_file}\nGF_INSTALL_PLUGINS=\${${core_env}}"

# Force update of grafana env file with new PWD_CORE_PLUGINS structure.
sed -i.old -e "s@^GF_INSTALL_PLUGINS=.*@${update_gf_file}@" $GF_ENV_FILE
fi

if [ "${old_core}" == "${new_core}" ]; then
echo "Grafana plugin list is current. No action required."
else
echo
echo "Grafana plugin list has changed."
echo
echo "You appear to be running an older Grafana configuration with"
echo "plugins that are different to the current recommended list."
echo "This script can update your plugins to the current recommendations."
echo "If you have installed custom plugins or want to keep it as"
echo "it is, answer 'n' below and the script will provide instructions for"
echo "manual checks/updates."
echo
read -r -p "Do you want to update your Grafana plugin list? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
cp "${GF_ENV_FILE}" "${GF_ENV_FILE}.bak"
cp "${GF_ENV_FILE}.sample" "${GF_ENV_FILE}"
echo "Updated"
sed -i.bak -e "s@^${core_env}=.*@${core_env}=${new_core}@" $GF_ENV_FILE
docker stop grafana
docker rm grafana
# Probably safe to delete all plugins as grafana downloads everything everytime anyway.
rm -fr ./grafana/plugins/*
else
echo "No Change"
fi
echo
echo " Okay. Your grafana plugin list has not been updated."
echo
echo "However, this version of Powerwall-Dashboard may need new plugins"
echo "for the latest grafana dashboard. To address this, please"
echo "check the list of required plugins (listed in ${core_env} in"
echo "'${GF_ENV_FILE}.sample') and make sure all of these plugins are"
echo "added to ${core_env}' in '${GF_ENV_FILE}'."
fi
fi

# Silently create default docker compose env file if needed.
Expand Down

0 comments on commit 1cb285f

Please sign in to comment.