File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 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 'kini@sysdig.com' ]},
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' : ['kini@sysdig.com' ]},
34+ {'type' : 'SNS' , 'snsTopicARNs' : ['arn:aws:sns:us-east-1:273107874544:alarms-stg' ]}
3535 ]
3636res = sdclient .get_notification_ids (notify_channels )
3737if 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
4141notification_channel_ids = res [1 ]
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments