Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grafana Backup Tool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Migrated Projects
Tooling
Grafana Backup Tool
Commits
b02937d8
Commit
b02937d8
authored
4 years ago
by
Aaron Johnson
Browse files
Options
Downloads
Patches
Plain Diff
only use uid for dashboard when version 5.0.0 or newer
parent
5cbbb1d5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
grafana_backup/save_dashboards.py
+12
-8
12 additions, 8 deletions
grafana_backup/save_dashboards.py
with
12 additions
and
8 deletions
grafana_backup/save_dashboards.py
+
12
−
8
View file @
b02937d8
...
...
@@ -24,9 +24,9 @@ def main(args, settings):
is_api_support_page_param
=
left_ver_newer_than_right_ver
(
api_version
,
"
6.2.0
"
)
if
is_api_support_page_param
:
save_dashboards_above_Ver6_2
(
folder_path
,
log_file
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
)
save_dashboards_above_Ver6_2
(
folder_path
,
log_file
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
,
api_version
)
else
:
save_dashboards
(
folder_path
,
log_file
,
limit
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
)
save_dashboards
(
folder_path
,
log_file
,
limit
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
,
api_version
)
def
get_all_dashboards_in_grafana
(
page
,
limit
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
):
...
...
@@ -52,12 +52,16 @@ def save_dashboard_setting(dashboard_name, file_name, dashboard_settings, folder
print
(
"
dashboard: {0} -> saved to: {1}
"
.
format
(
dashboard_name
,
file_path
))
def
get_individual_dashboard_setting_and_save
(
dashboards
,
folder_path
,
log_file
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
):
def
get_individual_dashboard_setting_and_save
(
dashboards
,
folder_path
,
log_file
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
,
api_version
):
file_path
=
folder_path
+
'
/
'
+
log_file
if
dashboards
:
with
open
(
u
"
{0}
"
.
format
(
file_path
),
'
w
'
)
as
f
:
for
board
in
dashboards
:
board_uri
=
"
uid/{0}
"
.
format
(
board
[
'
uid
'
])
if
left_ver_newer_than_right_ver
(
api_version
,
"
4.6.3
"
):
board_uri
=
"
uid/{0}
"
.
format
(
board
[
'
uid
'
])
else
:
board_uri
=
board
[
'
uri
'
]
(
status
,
content
)
=
get_dashboard
(
board_uri
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
)
if
status
==
200
:
save_dashboard_setting
(
...
...
@@ -70,7 +74,7 @@ def get_individual_dashboard_setting_and_save(dashboards, folder_path, log_file,
f
.
write
(
'
{0}
\t
{1}
\n
'
.
format
(
board
[
'
uid
'
],
to_python2_and_3_compatible_string
(
board
[
'
title
'
])))
def
save_dashboards_above_Ver6_2
(
folder_path
,
log_file
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
):
def
save_dashboards_above_Ver6_2
(
folder_path
,
log_file
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
,
api_version
):
limit
=
5000
# limit is 5000 above V6.2+
current_page
=
1
while
True
:
...
...
@@ -80,13 +84,13 @@ def save_dashboards_above_Ver6_2(folder_path, log_file, grafana_url, http_get_he
break
else
:
current_page
+=
1
get_individual_dashboard_setting_and_save
(
dashboards
,
folder_path
,
log_file
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
)
get_individual_dashboard_setting_and_save
(
dashboards
,
folder_path
,
log_file
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
,
api_version
)
print_horizontal_line
()
def
save_dashboards
(
folder_path
,
log_file
,
limit
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
):
def
save_dashboards
(
folder_path
,
log_file
,
limit
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
,
api_version
):
current_page
=
1
dashboards
=
get_all_dashboards_in_grafana
(
current_page
,
limit
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
)
print_horizontal_line
()
get_individual_dashboard_setting_and_save
(
dashboards
,
folder_path
,
log_file
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
)
get_individual_dashboard_setting_and_save
(
dashboards
,
folder_path
,
log_file
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
,
api_version
)
print_horizontal_line
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment