Skip to content

Commit e637886

Browse files
authored
Merge pull request #97 from draios/restore-alerts-bug
Remove Python 3-specific code; improve comments
2 parents 90caf13 + 9c96fa6 commit e637886

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

examples/restore_alerts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@
6969
print('Notification Channel ID ' + str(channel_id) + ' referenced in Alert "' + a['name'] + '" does not exist.\n Restoring without this ID.')
7070
a['notificationChannelIds'].remove(channel_id)
7171

72-
# JSON Alerts from the list_alerts.py example are in epoch time, but ones
73-
# downloaded using the "Export JSON" button of the web interface are ISO
74-
# timestamps in string form. If we see these fields as strings, assume
75-
# they came from the web UI and convert them to epoch.
72+
# The Create/Update APIs will validate but actually ignore these fields;
73+
# to avoid problems, don't submit in the API request
7674
for timefield in ['createdOn', 'modifiedOn']:
77-
if isinstance(a.get(timefield), str):
78-
a[timefield] = calendar.timegm(datetime.datetime.strptime(a[timefield], '%Y-%m-%dT%H:%M:%S.%fZ').timetuple())
75+
del a[timefield]
7976

77+
# NOTE: when exporting alerts that contain deprecated metrics you will
78+
# need to remove them from the source json
79+
# (see https://sysdigdocs.atlassian.net/wiki/spaces/Monitor/pages/205684810/Metrics#Metrics-HeuristicandDeprecatedMetrics)
8080
if a['name'] in existing_alerts:
8181
a['id'] = existing_alerts[a['name']]['id']
8282
a['version'] = existing_alerts[a['name']]['version']

0 commit comments

Comments
 (0)