Skip to content

Commit 4f52c40

Browse files
committed
Be more graceful when decoding Grafana dashboard data structures
1 parent 3f47b95 commit 4f52c40

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ grafana-wtf changelog
66
in progress
77
===========
88

9+
2021-12-10 0.11.1
10+
=================
11+
- Be more graceful when decoding Grafana dashboard data structures. Thanks, @jangaraj!
12+
913
2021-12-10 0.11.0
1014
=================
1115
- Upgrade to ``colored==1.4.3``. Thanks, @dslackw!

grafana_wtf/core.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,12 @@ def index(self):
340340
self.index_datasources()
341341

342342
@staticmethod
343-
def collect_datasource_names(root):
344-
return list(set([item.datasource for item in root if item.datasource]))
343+
def collect_datasource_names(element):
344+
names = []
345+
for node in element:
346+
if "datasource" in node and node["datasource"]:
347+
names.append(node.datasource)
348+
return list(sorted(set(names)))
345349

346350
def index_dashboards(self):
347351

@@ -357,9 +361,10 @@ def index_dashboards(self):
357361
self.dashboard_by_uid[uid] = dashboard
358362

359363
# Map to data source names.
360-
ds_panels = self.collect_datasource_names(dashboard.dashboard.panels)
361-
ds_annotations = self.collect_datasource_names(dashboard.dashboard.annotations.list)
362-
ds_templating = self.collect_datasource_names(dashboard.dashboard.templating.list)
364+
dbdata = dashboard.dashboard
365+
ds_panels = self.collect_datasource_names(dbdata.get("panels", []))
366+
ds_annotations = self.collect_datasource_names(dbdata.get("annotations", {}).get("list", []))
367+
ds_templating = self.collect_datasource_names(dbdata.get("templating", {}).get("list", []))
363368
self.dashboard_datasource_index[uid] = list(sorted(set(ds_panels + ds_annotations + ds_templating)))
364369

365370
def index_datasources(self):

0 commit comments

Comments
 (0)