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
be46d7cc
Commit
be46d7cc
authored
3 years ago
by
Felix Sperling
Browse files
Options
Downloads
Patches
Plain Diff
add compatibility for older grafana versions
parent
b61baae5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
grafana_backup/dashboardApi.py
+16
-4
16 additions, 4 deletions
grafana_backup/dashboardApi.py
grafana_backup/delete_dashboards.py
+6
-2
6 additions, 2 deletions
grafana_backup/delete_dashboards.py
grafana_backup/delete_datasources.py
+12
-7
12 additions, 7 deletions
grafana_backup/delete_datasources.py
with
34 additions
and
13 deletions
grafana_backup/dashboardApi.py
+
16
−
4
View file @
be46d7cc
...
...
@@ -132,8 +132,13 @@ def delete_snapshot(key, grafana_url, http_post_headers):
return
int
(
r
.
status_code
)
def
delete_dashboard
(
board_uri
,
grafana_url
,
http_post_headers
):
r
=
requests
.
delete
(
'
{0}/api/dashboards/uid/{1}
'
.
format
(
grafana_url
,
board_uri
),
headers
=
http_post_headers
)
def
delete_dashboard_by_uid
(
uid
,
grafana_url
,
http_post_headers
):
r
=
requests
.
delete
(
'
{0}/api/dashboards/uid/{1}
'
.
format
(
grafana_url
,
uid
),
headers
=
http_post_headers
)
return
int
(
r
.
status_code
)
def
delete_dashboard_by_slug
(
slug
,
grafana_url
,
http_post_headers
):
r
=
requests
.
delete
(
'
{0}/api/dashboards/db/{1}
'
.
format
(
grafana_url
,
slug
),
headers
=
http_post_headers
)
return
int
(
r
.
status_code
)
...
...
@@ -168,8 +173,15 @@ def create_datasource(payload, grafana_url, http_post_headers, verify_ssl, clien
client_cert
,
debug
)
def
delete_datasource
(
uid
,
grafana_url
,
http_post_headers
,
verify_ssl
,
client_cert
,
debug
):
r
=
requests
.
delete
(
'
{0}/api/datasources/uid/{1}
'
.
format
(
grafana_url
,
uid
),
headers
=
http_post_headers
)
def
delete_datasource_by_uid
(
uid
,
grafana_url
,
http_post_headers
,
verify_ssl
,
client_cert
,
debug
):
url
=
'
{0}/api/datasources/uid/{1}
'
.
format
(
grafana_url
,
uid
)
r
=
requests
.
delete
(
url
,
headers
=
http_post_headers
)
return
int
(
r
.
status_code
)
def
delete_datasource_by_id
(
id_
,
grafana_url
,
http_post_headers
,
verify_ssl
,
client_cert
,
debug
):
url
=
'
{0}/api/datasources/{1}
'
.
format
(
grafana_url
,
id_
)
r
=
requests
.
delete
(
url
,
headers
=
http_post_headers
)
return
int
(
r
.
status_code
)
...
...
This diff is collapsed.
Click to expand it.
grafana_backup/delete_dashboards.py
+
6
−
2
View file @
be46d7cc
from
grafana_backup.dashboardApi
import
search_dashboard
,
delete_dashboard
from
grafana_backup.dashboardApi
import
search_dashboard
,
delete_dashboard
_by_uid
,
delete_dashboard_by_slug
from
grafana_backup.commons
import
to_python2_and_3_compatible_string
,
print_horizontal_line
...
...
@@ -40,7 +40,11 @@ def get_all_dashboards_in_grafana(page, limit, grafana_url, http_get_headers, ve
def
get_individual_dashboard_and_delete
(
dashboards
,
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
,
uid_support
):
if
dashboards
:
for
board
in
dashboards
:
status
=
delete_dashboard
(
board
[
'
uid
'
],
grafana_url
,
http_get_headers
)
if
uid_support
:
status
=
delete_dashboard_by_uid
(
board
[
'
uid
'
],
grafana_url
,
http_get_headers
)
else
:
status
=
delete_dashboard_by_slug
(
board
[
'
slug
'
],
grafana_url
,
http_get_headers
)
if
status
==
200
:
print
(
"
deleted dashboard {0}
"
.
format
(
board
[
'
title
'
]))
else
:
...
...
This diff is collapsed.
Click to expand it.
grafana_backup/delete_datasources.py
+
12
−
7
View file @
be46d7cc
from
grafana_backup.dashboardApi
import
search_datasource
,
delete_datasource
from
grafana_backup.dashboardApi
import
search_datasource
,
delete_datasource
_by_uid
,
delete_datasource_by_id
from
grafana_backup.commons
import
print_horizontal_line
def
main
(
args
,
settings
):
grafana_url
=
settings
.
get
(
'
GRAFANA_URL
'
)
http_get_headers
=
settings
.
get
(
'
HTTP_POST_HEADERS
'
)
debug
=
settings
.
get
(
'
DEBUG
'
)
verify_ssl
=
settings
.
get
(
'
VERIFY_SSL
'
)
grafana_url
=
settings
.
get
(
'
GRAFANA_URL
'
)
client_cert
=
settings
.
get
(
'
CLIENT_CERT
'
)
debug
=
settings
.
get
(
'
DEBUG
'
)
uid_support
=
settings
.
get
(
'
UID_SUPPORT
'
)
pretty_print
=
settings
.
get
(
'
PRETTY_PRINT
'
)
http_get_headers
=
settings
.
get
(
'
HTTP_POST_HEADERS
'
)
get_all_datasources_and_delete
(
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
)
get_all_datasources_and_delete
(
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
,
uid_support
)
print_horizontal_line
()
def
get_all_datasources_and_delete
(
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
):
def
get_all_datasources_and_delete
(
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
,
uid_support
):
status_code_and_content
=
search_datasource
(
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
)
if
status_code_and_content
[
0
]
==
200
:
datasources
=
status_code_and_content
[
1
]
print
(
"
There are {0} datasources:
"
.
format
(
len
(
datasources
)))
for
datasource
in
datasources
:
print
(
datasource
)
status
=
delete_datasource
(
datasource
[
'
uid
'
],
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
)
if
uid_support
:
status
=
delete_datasource_by_uid
(
datasource
[
'
uid
'
],
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
)
else
:
status
=
delete_datasource_by_id
(
datasource
[
'
id
'
],
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
)
if
status
==
200
:
print
(
"
datasource:{0} is deleted
"
.
format
(
datasource
[
'
name
'
]))
else
:
...
...
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