Skip to content

Commit

Permalink
PMM-1797 Replace all variants of incorrect data.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored and delgod committed Dec 11, 2017
1 parent 4e3fd29 commit 6729a54
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions import-dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,27 @@ def delete_api_key(upgrade):


def fix_cloudwatch_datasource():
"""
Replaces incorrect CloudWatch datasource stored as JSON string with correct JSON object.
"""

con = sqlite3.connect(GRAFANA_DB_DIR + '/grafana.db')
cur = con.cursor()

# update parameters only if they were not changed
found = False
old = {'defaultRegion': 'us-east-1'}
cur.execute("SELECT id, json_data FROM data_source WHERE name = 'CloudWatch'")
for row in cur.fetchall():
found = True
id, jd = row
if json.loads(jd) == old:
new = {'authType': 'keys', 'timeField': '@timestamp'}
cur.execute("UPDATE data_source SET json_data = ? WHERE id = ?", (json.dumps(new), id))

old = None
try:
old = json.loads(row[1])
except:
pass

if not isinstance(old, dict):
new = {'authType': 'keys'}
cur.execute("UPDATE data_source SET json_data = ? WHERE id = ?", (json.dumps(new), row[0]))

con.commit()
con.close()
Expand Down

0 comments on commit 6729a54

Please sign in to comment.