mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Fix consistency issue in grafana_dashboard module. (#47459)
* Move check for 'dashboard' key to before the create/update if statement. * Add changelog fragment for PR #47459
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- Fix consistency issue in grafana_dashboard module where the module would detect absence of 'dashboard' key on dashboard create but not dashboard update.
|
||||||
@@ -225,6 +225,10 @@ def grafana_create_dashboard(module, data):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise GrafanaAPIException("Can't load json file %s" % to_native(e))
|
raise GrafanaAPIException("Can't load json file %s" % to_native(e))
|
||||||
|
|
||||||
|
# Check that the dashboard JSON is nested under the 'dashboard' key
|
||||||
|
if 'dashboard' not in payload:
|
||||||
|
payload = {'dashboard': payload}
|
||||||
|
|
||||||
# define http header
|
# define http header
|
||||||
headers = grafana_headers(module, data)
|
headers = grafana_headers(module, data)
|
||||||
|
|
||||||
@@ -277,8 +281,6 @@ def grafana_create_dashboard(module, data):
|
|||||||
raise GrafanaAPIException('Unable to update the dashboard %s : %s' % (uid, body['message']))
|
raise GrafanaAPIException('Unable to update the dashboard %s : %s' % (uid, body['message']))
|
||||||
else:
|
else:
|
||||||
# create
|
# create
|
||||||
if 'dashboard' not in payload:
|
|
||||||
payload = {'dashboard': payload}
|
|
||||||
r, info = fetch_url(module, '%s/api/dashboards/db' % data['grafana_url'], data=json.dumps(payload), headers=headers, method='POST')
|
r, info = fetch_url(module, '%s/api/dashboards/db' % data['grafana_url'], data=json.dumps(payload), headers=headers, method='POST')
|
||||||
if info['status'] == 200:
|
if info['status'] == 200:
|
||||||
result['msg'] = "Dashboard %s created" % uid
|
result['msg'] = "Dashboard %s created" % uid
|
||||||
|
|||||||
Reference in New Issue
Block a user