Skip to content
Snippets Groups Projects
Commit c166b73b authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

search for dashboard in specific folder

parent b100a61c
No related branches found
No related tags found
No related merge requests found
......@@ -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 "Provisioning"
action = "Updating" if existing_dashboard else "Creating"
logger.info(f'{action} dashboard: {title}')
r = request.post('api/dashboards/db', json=payload)
return r
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment