Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-dashboard-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
geant-swd
brian
brian-dashboard-manager
Commits
c166b73b
Commit
c166b73b
authored
4 years ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
search for dashboard in specific folder
parent
b100a61c
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
brian_dashboard_manager/grafana/dashboard.py
+8
-4
8 additions, 4 deletions
brian_dashboard_manager/grafana/dashboard.py
with
8 additions
and
4 deletions
brian_dashboard_manager/grafana/dashboard.py
+
8
−
4
View file @
c166b73b
...
...
@@ -54,7 +54,7 @@ def find_dashboard(request: TokenRequest, title):
# Searches Grafana for a dashboard
# matching the title of the provided dashboard.
def
_search_dashboard
(
request
:
TokenRequest
,
dashboard
:
Dict
):
def
_search_dashboard
(
request
:
TokenRequest
,
dashboard
:
Dict
,
folder_id
=
None
):
try
:
r
=
request
.
get
(
'
api/search
'
,
params
=
{
'
query
'
:
dashboard
[
"
title
"
]
...
...
@@ -62,8 +62,12 @@ def _search_dashboard(request: TokenRequest, dashboard: Dict):
if
r
and
isinstance
(
r
,
list
):
if
len
(
r
)
>=
1
:
for
dash
in
r
:
if
folder_id
:
if
folder_id
!=
dash
[
'
folderId
'
]:
continue
if
dash
[
'
title
'
]
==
dashboard
[
'
title
'
]:
return
_get_dashboard
(
request
,
dash
[
'
uid
'
])
definition
=
_get_dashboard
(
request
,
dash
[
'
uid
'
])
return
definition
return
None
except
HTTPError
:
return
None
...
...
@@ -98,7 +102,7 @@ def create_dashboard(request: TokenRequest, dashboard: Dict, folder_id=None):
different
=
False
if
existing_dashboard
is
None
or
different
:
existing_dashboard
=
_search_dashboard
(
request
,
dashboard
)
existing_dashboard
=
_search_dashboard
(
request
,
dashboard
,
folder_id
)
if
existing_dashboard
:
dashboard
[
'
uid
'
]
=
existing_dashboard
[
'
dashboard
'
][
'
uid
'
]
...
...
@@ -116,7 +120,7 @@ def create_dashboard(request: TokenRequest, dashboard: Dict, folder_id=None):
payload
[
'
folderId
'
]
=
folder_id
try
:
action
=
"
Updating
"
if
existing_dashboard
else
"
Provision
ing
"
action
=
"
Updating
"
if
existing_dashboard
else
"
Creat
ing
"
logger
.
info
(
f
'
{
action
}
dashboard:
{
title
}
'
)
r
=
request
.
post
(
'
api/dashboards/db
'
,
json
=
payload
)
return
r
...
...
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