Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tool fails when grafana-config hide_version is set #225

Closed
chriz-active opened this issue Jun 27, 2023 · 0 comments · Fixed by #228
Closed

tool fails when grafana-config hide_version is set #225

chriz-active opened this issue Jun 27, 2023 · 0 comments · Fixed by #228

Comments

@chriz-active
Copy link
Contributor

chriz-active commented Jun 27, 2023

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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant