Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 9280605

Browse files
author
John Dunham
committed
Added UTF-8 string sanitization to archival script.
1 parent 72ff821 commit 9280605

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

csmdb/sql/csm_db_history_archive.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@
4848
# Additional Formatting style
4949
line1 = "---------------------------------------------------------------------------------------------------------"
5050

51+
def sanitize_string(v):
52+
return v.decode('utf-8', 'ignore')
53+
54+
def sanitize_dict(d):
55+
for k, v in d.iteritems():
56+
if isinstance(v, dict):
57+
d[k] = sanitize_dict(v)
58+
elif isinstance(v, str):
59+
d[k] = sanitize_string(v)
60+
else:
61+
d[k] = v
62+
return d
63+
5164
# username defined
5265
username = commands.getoutput("whoami")
5366

@@ -172,7 +185,8 @@ def dump_table( db, user, table_name, count, target_dir, is_ras=False ):
172185
colnames = [desc[0] for desc in cursor.description]
173186
for row in cursor:
174187
file.write('{{ "type":"db-{0}", "data":{1} }}\n'.format(
175-
table_name, json.dumps(dict(zip(colnames, row)), default=str)))
188+
table_name, json.dumps(sanitize_dict(dict(zip(colnames, row))),
189+
default=str)))
176190
except Exception as e:
177191
print "[INFO] Exception caught: {0}".format(e)
178192
logger.info("Exception caught: {0}".format(e))
@@ -262,7 +276,7 @@ def main(args):
262276
entry = dump_table( args.db, args.user, table, args.count, temp_dir, True)
263277
if entry is None:0
264278
else:
265-
print entry args.target
279+
print (entry, args.target)
266280

267281
# After the tables are dumped, it's time to merge them into the weekly report.
268282
rollupDir(temp_dir,"..")

0 commit comments

Comments
 (0)