Skip to content

Commit

Permalink
dashboard: fix issue during import
Browse files Browse the repository at this point in the history
When testing dashboad payload between the test resulted in reverted values
leading to the dashboard not being updated when it should.

Closes: #76
  • Loading branch information
rrey committed Mar 28, 2020
1 parent 6c8bb78 commit bbfce99
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions plugins/modules/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,23 +272,28 @@ def grafana_dashboard_search(module, grafana_url, folder_id, title, headers):
# for comparison, we sometimes need to ignore a few keys
def grafana_dashboard_changed(payload, dashboard):
# you don't need to set the version, but '0' is incremented to '1' by Grafana's API
if payload['dashboard']['version'] == 0:
if 'version' in payload['dashboard']:
del(payload['dashboard']['version'])
if 'version' in dashboard['dashboard']:
del(dashboard['dashboard']['version'])

# the meta key is not part of the 'payload' ever
if 'meta' in dashboard:
del(dashboard['meta'])

# new dashboards don't require an id attribute (or, it can be 'null'), Grafana's API will generate it
if payload['dashboard'].get('id'):
# if folderId is not provided in dashboard, set default folderId
if 'folderId' not in dashboard:
dashboard['folderId'] = 0

# Ignore dashboard ids since real identifier is uuid
if 'id' in dashboard['dashboard']:
del(dashboard['dashboard']['id'])
if 'id' in payload['dashboard']:
del(payload['dashboard']['id'])

if payload == dashboard:
return True

return False
return False
return True


def grafana_create_dashboard(module, data):
Expand Down

0 comments on commit bbfce99

Please sign in to comment.