ysde/grafana-backup-tool

tool fails when grafana-config `hide_version` is set

Closed this issue · 0 comments

Problem

Running grafana-backup save with the grafana-config-setting hide_version fails:

   sys.exit(main())                                                                                                                                        
            ^^^^^^
 File "/usr/local/lib/python3.11/site-packages/grafana_backup/cli.py", line 52, in main
   save(args, settings)
 File "/usr/local/lib/python3.11/site-packages/grafana_backup/save.py", line 61, in main
   backup_functions[backup_function](args, settings)
 File "/usr/local/lib/python3.11/site-packages/grafana_backup/save_alert_rules.py", line 19, in main
   grafana_version = get_grafana_version(grafana_url, verify_ssl)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/usr/local/lib/python3.11/site-packages/grafana_backup/dashboardApi.py", line 440, in get_grafana_version
   return version.parse(r.json()['version'])
                        ~~~~~~~~^^^^^^^^^^^
KeyError: 'version'

Error is thrown here:

def get_grafana_version(grafana_url, verify_ssl):
r = requests.get('{0}/api/health'.format(grafana_url), verify=verify_ssl)
if r.status_code == 200:
return version.parse(r.json()['version'])
else:
raise Exception("Unable to get version, returned response: {0}".format(r.status_code))

calling api/health in our instance v9.5.2 as admin returns

api/health
{          
  "database": "ok"
}

That is, the version-field is not available.

Possible Solution

  • The version is currently needed for the alert-rules:
    grafana_version = get_grafana_version(grafana_url, verify_ssl)
    minimum_version = version.parse('9.4.0')
    if minimum_version <= grafana_version:
    alert_rule = json.loads(data)

    grafana_version = get_grafana_version(grafana_url, verify_ssl)
    minimum_version = version.parse('9.4.0')
    if minimum_version <= grafana_version:
  • Might it be an option to provide the version as fallback as config/environment-variable?