@@ -133,6 +133,40 @@ def self.add_network_monitor(server, ip_address, query_type, response_action, wa
133133 end
134134 end
135135
136+ ##
137+ # Add user customers to the list of users notified on monitor failure for the specified server. Accepts a list of UserCustomer
138+ # instances or user customer usernames.
139+ #
140+ def self . add_network_monitor_notification_users ( server , user_customers , options = { } )
141+ softlayer_client = options [ :client ] || Client . default_client
142+ raise "#{ __method__ } requires a client but none was given and Client::default_client is not set" if !softlayer_client
143+ raise "#{ __method__ } requires a server to monitor but none was given" if !server || !server . kind_of? ( Server )
144+ raise "#{ __method__ } requires a list user customers but none was given" if !user_customers || user_customers . empty?
145+
146+ user_customers_data = user_customers . map do |user_customer |
147+ raise "#{ __method__ } requires a user customer but none was given" if !user_customer || ( !user_customer . class . method_defined? ( :username ) && user_customer . empty? )
148+
149+ user_customer_data = user_customer . class . method_defined? ( :username ) ? user_customer : UserCustomer . user_customer_with_username ( user_customer , softlayer_client )
150+
151+ raise "#{ __method__ } user customer with username #{ user_customer . inspect } not found" unless user_customer_data
152+
153+ user_customer_data
154+ end
155+
156+ current_user_customers = server . notified_network_monitor_users . map { |notified_network_monitor_user | notified_network_monitor_user [ 'id' ] }
157+
158+ user_customers_data . delete_if { |user_customer | current_user_customers . include? ( user_customer [ 'id' ] ) }
159+
160+ unless user_customers_data . empty?
161+ notification_monitor_user_service = server . kind_of? ( VirtualServer ) ? :User_Customer_Notification_Virtual_Guest : :User_Customer_Notification_Hardware
162+ server_id_label = server . kind_of? ( VirtualServer ) ? 'guestId' : 'hardwareId'
163+
164+ user_customer_notifications = user_customers_data . map { |user_customer | { server_id_label => server . id , 'userId' => user_customer [ 'id' ] } }
165+
166+ softlayer_client [ notification_monitor_user_service ] . createObjects ( user_customer_notifications )
167+ end
168+ end
169+
136170 ##
137171 # Return the list of available query types (optionally limited to a max query level)
138172 #
@@ -169,6 +203,48 @@ def self.available_response_actions(options = {})
169203 end
170204 end
171205
206+ ##
207+ # Rmove user customers from the list of users notified on monitor failure for the specified server. Accepts a list of UserCustomer
208+ # instances or user customer usernames.
209+ #
210+ def self . remove_network_monitor_notification_users ( server , user_customers , options = { } )
211+ softlayer_client = options [ :client ] || Client . default_client
212+ raise "#{ __method__ } requires a client but none was given and Client::default_client is not set" if !softlayer_client
213+ raise "#{ __method__ } requires a server to monitor but none was given" if !server || !server . kind_of? ( Server )
214+ raise "#{ __method__ } requires a list user customers but none was given" if !user_customers || user_customers . empty?
215+
216+ user_customers_data = user_customers . map do |user_customer |
217+ raise "#{ __method__ } requires a user customer but none was given" if !user_customer || ( !user_customer . kind_of? ( UserCustomer ) && user_customer . empty? )
218+
219+ user_customer_data = user_customer . kind_of? ( UserCustomer ) ? user_customer : UserCustomer . user_customer_with_username ( user_customer , softlayer_client )
220+
221+ raise "#{ __method__ } user customer with username #{ user_customer . inspect } not found" unless user_customer_data
222+
223+ user_customer_data
224+ end
225+
226+ current_user_customers = user_customers_data . map { |user_customer | user_customer [ 'id' ] }
227+
228+ monitor_user_notification_object_filter = ObjectFilter . new ( )
229+
230+ monitor_user_notification_object_filter . set_criteria_for_key_path ( 'monitoringUserNotification.userId' ,
231+ {
232+ 'operation' => 'in' ,
233+ 'options' => [ {
234+ 'name' => 'data' ,
235+ 'value' => current_user_customers . map { |uid | uid . to_s }
236+ } ]
237+ } )
238+
239+ monitor_user_notification_data = server . service . object_filter ( monitor_user_notification_object_filter ) . object_mask ( "mask[id]" ) . getMonitoringUserNotification
240+
241+ unless monitor_user_notification_data . empty?
242+ notification_monitor_user_service = server . kind_of? ( VirtualServer ) ? :User_Customer_Notification_Virtual_Guest : :User_Customer_Notification_Hardware
243+
244+ softlayer_client [ notification_monitor_user_service ] . deleteObjects ( monitor_user_notification_data )
245+ end
246+ end
247+
172248 ##
173249 # Removes the list of network monitors from their associated servers
174250 #
0 commit comments