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
2e2d2c7a
Commit
2e2d2c7a
authored
3 years ago
by
Felix Sperling
Browse files
Options
Downloads
Patches
Plain Diff
also delete snapshots
parent
e3494651
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
grafana_backup/dashboardApi.py
+5
-0
5 additions, 0 deletions
grafana_backup/dashboardApi.py
grafana_backup/delete_snapshots.py
+33
-0
33 additions, 0 deletions
grafana_backup/delete_snapshots.py
with
38 additions
and
0 deletions
grafana_backup/dashboardApi.py
+
5
−
0
View file @
2e2d2c7a
...
...
@@ -112,6 +112,11 @@ def delete_folder(uid, grafana_url, http_post_headers):
return
int
(
r
.
status_code
)
def
delete_snapshot
(
key
,
grafana_url
,
http_post_headers
):
r
=
requests
.
delete
(
'
{0}/api/snapshots/{1}
'
.
format
(
grafana_url
,
key
),
headers
=
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
)
return
int
(
r
.
status_code
)
...
...
This diff is collapsed.
Click to expand it.
grafana_backup/delete_snapshots.py
0 → 100644
+
33
−
0
View file @
2e2d2c7a
from
grafana_backup.dashboardApi
import
search_snapshot
,
delete_snapshot
from
grafana_backup.commons
import
print_horizontal_line
def
main
(
args
,
settings
):
grafana_url
=
settings
.
get
(
'
GRAFANA_URL
'
)
http_get_headers
=
settings
.
get
(
'
HTTP_GET_HEADERS
'
)
verify_ssl
=
settings
.
get
(
'
VERIFY_SSL
'
)
client_cert
=
settings
.
get
(
'
CLIENT_CERT
'
)
debug
=
settings
.
get
(
'
DEBUG
'
)
pretty_print
=
settings
.
get
(
'
PRETTY_PRINT
'
)
get_all_snapshots_and_delete
(
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
)
print_horizontal_line
()
def
get_all_snapshots_and_delete
(
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
,
pretty_print
):
status_code_and_content
=
search_snapshot
(
grafana_url
,
http_get_headers
,
verify_ssl
,
client_cert
,
debug
)
if
status_code_and_content
[
0
]
==
200
:
snapshots
=
status_code_and_content
[
1
]
print
(
"
There are {0} snapshots:
"
.
format
(
len
(
snapshots
)))
for
snapshot
in
snapshots
:
print
(
snapshot
)
status
=
delete_snapshot
(
snapshot
[
'
key
'
],
grafana_url
,
http_get_headers
)
if
status
==
200
:
print
(
"
deleted snapshot {0}
"
.
format
(
snapshot
[
'
name
'
]))
else
:
print
(
"
failed to delete snapshot {0}, with {1}
"
.
format
(
snapshot
[
'
name
'
],
status
))
else
:
print
(
"
query snapshot failed, status: {0}, msg: {1}
"
.
format
(
status_code_and_content
[
0
],
status_code_and_content
[
1
]))
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