@@ -88,7 +88,7 @@ def get_notifications(self, from_ts, to_ts, state=None, resolved=None):
8888
8989 def update_notification_resolution (self , notification , resolved ):
9090 if 'id' not in notification :
91- return [False , " Invalid notification format" ]
91+ return [False , ' Invalid notification format' ]
9292
9393 notification ['resolved' ] = resolved
9494 data = {'notification' : notification }
@@ -189,50 +189,39 @@ def create_alert(self, name, description, severity, for_atleast_s, condition, se
189189
190190 def delete_alert (self , alert ):
191191 if 'id' not in alert :
192- return [False , " Invalid alert format" ]
192+ return [False , ' Invalid alert format' ]
193193
194194 res = requests .delete (self .url + '/api/alerts/' + str (alert ['id' ]), headers = self .hdrs )
195195 if not self .__checkResponse (res ):
196196 return [False , self .lasterr ]
197197
198198 return [True , None ]
199199
200- def get_notification_settings (self ):
201- res = requests .get (self .url + '/api/settings/notifications' , headers = self .hdrs )
202- if not self .__checkResponse (res ):
203- return [False , self .lasterr ]
204- return [True , res .json ()]
200+ def create_email_notification_channel (self , channel_name , email_recipients ):
201+ channel_json = {
202+ 'notificationChannel' : {
203+ 'type' : 'EMAIL' ,
204+ 'name' : channel_name ,
205+ 'enabled' : True ,
206+ 'options' : {
207+ 'emailRecipients' : email_recipients
208+ }
209+ }
210+ }
205211
206- def set_notification_settings (self , settings ):
207- res = requests .put (self .url + '/api/settings/notifications' , headers = self .hdrs ,
208- data = json .dumps (settings ))
212+ res = requests .post (self .url + '/api/notificationChannels' , headers = self .hdrs , data = json .dumps (channel_json ))
209213 if not self .__checkResponse (res ):
210214 return [False , self .lasterr ]
211215 return [True , res .json ()]
212216
213- def add_email_notification_recipient (self , email ):
214- #
215- # Retirieve the user's notification settings
216- #
217- res = requests .get (self .url + '/api/settings/notifications' , headers = self .hdrs )
217+ def delete_notification_channel (self , channel ):
218+ if 'id' not in channel :
219+ return [ False , "Invalid channel format" ]
220+
221+ res = requests .delete (self .url + '/api/notificationChannels/' + str ( channel [ 'id' ]) , headers = self .hdrs )
218222 if not self .__checkResponse (res ):
219223 return [False , self .lasterr ]
220- j = res .json ()
221-
222- #
223- # Enable email notifications
224- #
225- j ['userNotification' ]['email' ]['enabled' ] = True
226-
227- #
228- # Add the given recipient
229- #
230- if email not in j ['userNotification' ]['email' ]['recipients' ]:
231- j ['userNotification' ]['email' ]['recipients' ].append (email )
232- else :
233- return [False , 'notification target ' + email + ' already present' ]
234-
235- return self .set_notification_settings (j )
224+ return [True , None ]
236225
237226 def get_explore_grouping_hierarchy (self ):
238227 res = requests .get (self .url + '/api/groupConfigurations' , headers = self .hdrs )
0 commit comments