Skip to content

Commit 321cbee

Browse files
committed
updating data sources according to
data type changes
1 parent 681f1be commit 321cbee

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

grafana_snapshots/cli.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,13 @@ def main():
245245
sys.exit(2)
246246

247247
for dtsrc in dtsrcs:
248-
datasources[dtsrc['name']] = dtsrc['id']
249-
if 'isDefault' in dtsrc and dtsrc['isDefault']:
250-
datasources['default'] = dtsrc['id']
248+
if 'uid' not in dtsrc:
249+
datasources[dtsrc['name']] = dtsrc['id']
250+
if 'isDefault' in dtsrc and dtsrc['isDefault']:
251+
datasources['default'] = dtsrc['id']
252+
else:
253+
datasources[dtsrc['uid']] = dtsrc['id']
254+
251255
if args.verbose:
252256
print('datasources OK.')
253257

grafana_snapshots/grafanaData.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ def get_dashboard_data(self):
310310
print("target-type is 'row': skipped")
311311
continue
312312

313-
if dtsrc in self.datasources and targets is not None:
313+
if isinstance(dtsrc, dict):
314+
dtsrc = dtsrc['uid']
315+
# else:
316+
# ff
317+
if (dtsrc in self.datasources or dtsrc == '-- Mixed --' ) and targets is not None:
314318

315319
# print('dt: {0}'.format(datasources[dtsrc]))
316320
for target in targets:
@@ -323,6 +327,10 @@ def get_dashboard_data(self):
323327
if 'format' in target and target['format'] == 'table':
324328
query_type = 'query'
325329

330+
# check if expr is defined or and unconfigurated query
331+
if 'expr' not in target:
332+
print("target expr is not defined: skipped!")
333+
continue
326334

327335
# check if target expr contains variable ($var)
328336
expr = target['expr']
@@ -350,8 +358,19 @@ def get_dashboard_data(self):
350358
}
351359
if self.debug:
352360
print("query GET datasource proxy uri: {0}".format(self.api.client.url))
361+
# determine datasource name if global name is 'mixed'
362+
if dtsrc == '-- Mixed --' and 'datasource' in target:
363+
datasource_name = target['datasource']
364+
if isinstance(datasource_name, dict):
365+
datasource_name = datasource_name['uid']
366+
else:
367+
datasource_name = dtsrc
368+
if not datasource_name in self.datasources:
369+
print("datasource '{0}' was not found".format(datasource_name))
370+
continue
371+
353372
try:
354-
content = self.api.datasource.get_datasource_proxy_data( str(self.datasources[dtsrc]), **params )
373+
content = self.api.datasource.get_datasource_proxy_data( str(self.datasources[datasource_name]), **params )
355374
except:
356375
print('invalid results...')
357376
return False

0 commit comments

Comments
 (0)