Skip to content

Commit

Permalink
updating data sources according to
Browse files Browse the repository at this point in the history
data type changes
  • Loading branch information
peekjef72 committed Sep 11, 2022
1 parent 681f1be commit 321cbee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
10 changes: 7 additions & 3 deletions grafana_snapshots/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,13 @@ def main():
sys.exit(2)

for dtsrc in dtsrcs:
datasources[dtsrc['name']] = dtsrc['id']
if 'isDefault' in dtsrc and dtsrc['isDefault']:
datasources['default'] = dtsrc['id']
if 'uid' not in dtsrc:
datasources[dtsrc['name']] = dtsrc['id']
if 'isDefault' in dtsrc and dtsrc['isDefault']:
datasources['default'] = dtsrc['id']
else:
datasources[dtsrc['uid']] = dtsrc['id']

if args.verbose:
print('datasources OK.')

Expand Down
23 changes: 21 additions & 2 deletions grafana_snapshots/grafanaData.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ def get_dashboard_data(self):
print("target-type is 'row': skipped")
continue

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

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

# check if expr is defined or and unconfigurated query
if 'expr' not in target:
print("target expr is not defined: skipped!")
continue

# check if target expr contains variable ($var)
expr = target['expr']
Expand Down Expand Up @@ -350,8 +358,19 @@ def get_dashboard_data(self):
}
if self.debug:
print("query GET datasource proxy uri: {0}".format(self.api.client.url))
# determine datasource name if global name is 'mixed'
if dtsrc == '-- Mixed --' and 'datasource' in target:
datasource_name = target['datasource']
if isinstance(datasource_name, dict):
datasource_name = datasource_name['uid']
else:
datasource_name = dtsrc
if not datasource_name in self.datasources:
print("datasource '{0}' was not found".format(datasource_name))
continue

try:
content = self.api.datasource.get_datasource_proxy_data( str(self.datasources[dtsrc]), **params )
content = self.api.datasource.get_datasource_proxy_data( str(self.datasources[datasource_name]), **params )
except:
print('invalid results...')
return False
Expand Down

0 comments on commit 321cbee

Please sign in to comment.