Skip to content

Commit 09590e1

Browse files
Various improvements (including fix for #2)
1 parent e917a6c commit 09590e1

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

examples/create_alert.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
#
3030
# Find notification channels (you need IDs to create an alert).
3131
#
32-
notify_channels = [ {'type': 'SLACK', 'channel': 'sysdig-demo2-alerts'},
33-
{'type': 'EMAIL', 'emailRecipients': [u'[email protected]']},
34-
{'type': 'SNS', 'snsTopicARNs': [u'arn:aws:sns:us-east-1:273107874544:alarms-stg']}
32+
notify_channels = [ {'type': 'SLACK', 'channel': '#sysdig-demo2-alerts'},
33+
{'type': 'EMAIL', 'emailRecipients': ['[email protected]']},
34+
{'type': 'SNS', 'snsTopicARNs': ['arn:aws:sns:us-east-1:273107874544:alarms-stg']}
3535
]
3636
res = sdclient.get_notification_ids(notify_channels)
3737
if not res[0]:
38-
print "Could not get IDs and hence not creating the alert"
38+
print "Could not get IDs and hence not creating the alert: " + res[1]
3939
sys.exit(-1)
4040

4141
notification_channel_ids = res[1]

sdcclient/_client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,32 @@ def get_notification_ids(self, channels):
110110

111111
# Should try and improve this M * N lookup
112112
ids = []
113-
for ch in res.json()["notificationChannels"]:
114-
for c in channels:
113+
for c in channels:
114+
found = False
115+
for ch in res.json()["notificationChannels"]:
115116
if c['type'] == ch['type']:
116-
print c, ch
117117
if c['type'] == 'SNS':
118118
opt = ch['options']
119119
if set(opt['snsTopicARNs']) == set(c['snsTopicARNs']):
120+
found = True
120121
ids.append(ch['id'])
121122
elif c['type'] == 'EMAIL':
122123
opt = ch['options']
123124
if set(c['emailRecipients']) == set(opt['emailRecipients']):
125+
found = True
124126
ids.append(ch['id'])
125127
elif c['type'] == 'PAGER_DUTY':
126128
opt = ch['options']
127129
if opt['account'] == c['account'] and opt['serviceName'] == c['serviceName']:
130+
found = True
128131
ids.append(ch['id'])
129132
elif c['type'] == 'SLACK':
130133
opt = ch['options']
131-
if opt['channel'] == c['channel']:
134+
if 'channel' in opt and opt['channel'] == c['channel']:
135+
found = True
132136
ids.append(ch['id'])
137+
if not found:
138+
return [False, "Channel not found: " + str(c)]
133139

134140
return [True, ids]
135141

0 commit comments

Comments
 (0)