in tooling/export-alerts/export-alerts.py [0:0]
def addAlertToSheet(alert, ws, headerRow=1):
# Add general alert paramters
for key in alert:
col = findColumn(ws, key, headerRow)
if col > 0:
value = ''
if key == 'tags' and alert[key] is not None:
value = ', '.join(alert[key])
elif key == 'references':
references = alert['references']
urls = []
if references:
for ref in references:
if 'url' in ref:
urls.append(ref['url'])
else:
print ('No URL in reference: ' + ref['name'])
else:
print ('No references in alert: ' + alert['name'])
value = '\n'.join(urls)
elif type(alert[key]) is str or type(alert[key]) is int or type(alert[key]) is bool:
value = alert[key]
if value != '':
ws.cell(row=ws.max_row, column=col).value = value
# Add the properties
properties = alert['properties']
for key in properties:
col = findColumn(ws, key, headerRow)
if col > 0:
value = ''
# Add the value to the cell
if type(properties[key]) is str:
value = properties[key]
else:
value = ws.cell(row=ws.max_row, column=col).value = json.dumps(properties[key])
if value != '':
ws.cell(row=ws.max_row, column=col).value = value