Skip to content

Commit 66c47e2

Browse files
committed
Fix collecting data information from dashboards w/o targets slots
Some panels on play.grafana.org do not include `targets`.
1 parent 6cde67f commit 66c47e2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ in progress
88

99
- Use 60 minutes as default cache TTL
1010
- Fix wrong ``jq`` commands in documentation. Thanks, @rahulnandan.
11+
- Fix collecting data information from dashboards w/o ``targets`` slots
12+
in panels
1113

1214
2023-10-03 0.16.0
1315
=================

grafana_wtf/model.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
# (c) 2021 Andreas Motl <[email protected]>
33
# License: GNU Affero General Public License, Version 3
44
import dataclasses
5+
import logging
56
from collections import OrderedDict
67
from typing import Dict, List, Optional
78
from urllib.parse import urljoin
89

910
from munch import Munch
1011

12+
logger = logging.getLogger(__name__)
13+
1114

1215
@dataclasses.dataclass
1316
class GrafanaDataModel:
@@ -138,9 +141,10 @@ def collect_data_details(self):
138141
targets = []
139142
for panel in ds_panels:
140143
panel_item = self._format_panel_compact(panel)
141-
for target in panel.targets:
142-
target["_panel"] = panel_item
143-
targets.append(target)
144+
if "targets" in panel:
145+
for target in panel.targets:
146+
target["_panel"] = panel_item
147+
targets.append(target)
144148

145149
response = OrderedDict(targets=targets, annotations=ds_annotations, templating=ds_templating)
146150

0 commit comments

Comments
 (0)