Skip to content

Commit 98b8c42

Browse files
author
Phil Rzewski
committed
Make update_alert example more friendly to repeated calling
1 parent d5159e6 commit 98b8c42

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

examples/update_alert.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,21 @@
3737
alert_found = True
3838
print 'Updating alert. Configuration before changing timespan, description, and notification channels:'
3939
print json.dumps(alert, sort_keys=True, indent=4)
40-
alert['notificationChannelIds'] = alert['notificationChannelIds'][0:-1]
41-
alert['description'] = 'this alert has been updated via update_alert in the python Sysdig Monitor library'
42-
alert['timespan'] = 120 * 1000000 # 2 minutes
40+
if 'notificationChannelIds' in alert:
41+
alert['notificationChannelIds'] = alert['notificationChannelIds'][0:-1]
42+
update_txt = ' (changed by update_alert)'
43+
if alert['description'][-len(update_txt):] != update_txt:
44+
alert['description'] = alert['description'] + update_txt
45+
alert['timespan'] = alert['timespan'] * 2 # Note: Expressed in seconds * 1000000
4346
res_update = sdclient.update_alert(alert)
4447

48+
if not res_update[0]:
49+
print res_update[1]
50+
sys.exit(1)
51+
4552
# Validate and print the results
4653
print '\nAlert after modification:'
4754
print json.dumps(res_update[1], sort_keys=True, indent=4)
48-
if not res_update[0]:
49-
sys.exit(1)
5055

5156
if not alert_found:
5257
print 'Alert to be updated not found'

0 commit comments

Comments
 (0)