Skip to content

Commit 170121a

Browse files
authored
Retrieve dashboard by name/title (#9)
1 parent afa73dc commit 170121a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

grafana_client/elements/dashboard.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ def get_dashboard(self, dashboard_uid):
1515
get_dashboard_path = "/dashboards/uid/%s" % dashboard_uid
1616
r = self.client.GET(get_dashboard_path)
1717
return r
18+
19+
def get_dashboard_by_name(self, dashboard_name):
20+
"""
21+
22+
:param dashboard_name:
23+
:return:
24+
"""
25+
get_dashboard_path = "/dashboards/db/%s" % dashboard_name
26+
r = self.client.GET(get_dashboard_path)
27+
return r
1828

1929
def update_dashboard(self, dashboard):
2030
"""

test/elements/test_dashboard.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ def test_get_dashboard(self, m):
3232
)
3333
dashboard = self.grafana.dashboard.get_dashboard("cIBgcSjkk")
3434
self.assertEqual(dashboard["dashboard"]["uid"], "cIBgcSjkk")
35+
36+
@requests_mock.Mocker()
37+
def test_get_dashboard_by_name(self, m):
38+
m.get(
39+
"http://localhost/api/dashboards/db/Production Overview",
40+
json={
41+
"dashboard": {
42+
"id": 1,
43+
"uid": "cIBgcSjkk",
44+
"title": "Production Overview",
45+
"tags": ["templated"],
46+
"timezone": "browser",
47+
"schemaVersion": 16,
48+
"version": 0,
49+
},
50+
"meta": {
51+
"isStarred": "false",
52+
"url": "/d/cIBgcSjkk/production-overview",
53+
"slug": "production-overview",
54+
},
55+
},
56+
)
57+
dashboard = self.grafana.dashboard.get_dashboard_by_name("Production Overview")
58+
self.assertEqual(dashboard["dashboard"]["title"], "Production Overview")
3559

3660
@requests_mock.Mocker()
3761
def test_update_dashboard(self, m):

0 commit comments

Comments
 (0)