Class: SoftLayer::NetworkMonitor
- Includes:
- DynamicAttribute
- Defined in:
- lib/softlayer/NetworkMonitor.rb
Overview
Each SoftLayer NetworkMonitor instance provides information about network monitors configured to check host ping or host ports of servers.
This class roughly corresponds to the entity SofyLayer_Network_Monitor_Version1_Query_Host in the API.
Constant Summary collapse
- @@available_query_types =
nil
- @@available_response_types =
nil
Instance Attribute Summary
Attributes inherited from ModelBase
Class Method Summary collapse
-
.add_network_monitor(server, ip_address, query_type, response_type, wait_cycles = 0, argument_value = nil, options = {}) ⇒ Object
Add a network monitor for a host ping or port check to a server.
-
.add_network_monitor_notification_users(server, user_customers, options = {}) ⇒ Object
Add user customers to the list of users notified on monitor failure for the specified server.
-
.available_query_types(options = {}) ⇒ Object
Return the list of available query types (optionally limited to a max query level).
-
.available_response_types(options = {}) ⇒ Object
Return the list of available response types (optionally limited to a max response level).
-
.remove_network_monitor_notification_users(server, user_customers, options = {}) ⇒ Object
Rmove user customers from the list of users notified on monitor failure for the specified server.
-
.remove_network_monitors(network_monitors, options = {}) ⇒ Object
Removes the list of network monitors from their associated servers.
Instance Method Summary collapse
-
#argument_value ⇒ Object
:attr_reader: argument_value The argument to be used for this monitor, if necessary.
-
#ip_address ⇒ Object
:attr_reader: ip_address The IP address to be monitored.
-
#last_query_result ⇒ Object
The most recent result for this particular monitoring instance.
-
#query_type ⇒ Object
The type of monitoring query that is executed when this server is monitored.
-
#response_type ⇒ Object
The response action taken when a monitor fails.
-
#service ⇒ Object
Returns the service for interacting with this network monitor component through the network API.
-
#status ⇒ Object
:attr_reader: The status of this monitoring instance.
-
#wait_cycles ⇒ Object
:attr_reader: wait_cycles The number of 5-minute cycles to wait before the “responseAction” is taken.
Methods included from DynamicAttribute
Methods inherited from ModelBase
#[], #has_sl_property?, #initialize, #refresh_details, sl_attr, #to_ary
Constructor Details
This class inherits a constructor from SoftLayer::ModelBase
Class Method Details
.add_network_monitor(server, ip_address, query_type, response_type, wait_cycles = 0, argument_value = nil, options = {}) ⇒ Object
Add a network monitor for a host ping or port check to a server.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/softlayer/NetworkMonitor.rb', line 147 def self.add_network_monitor(server, ip_address, query_type, response_type, wait_cycles = 0, argument_value = nil, = {}) softlayer_client = [:client] || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client raise "#{__method__} requires a server to monitor but none was given" if !server || !server.kind_of?(Server) raise "#{__method__} requires an IP address to monitor but none was given" if !ip_address || ip_address.empty? raise "#{__method__} requires a query type for the monitor but none was given" if !query_type || !query_type.kind_of?(NetworkMonitorQueryType) raise "#{__method__} requires a response type for the monitor but none was given" if !response_type || !response_type.kind_of?(NetworkMonitorResponseType) if available_query_types(:client => softlayer_client, :query_level => server.network_monitor_levels.monitor_level).select{ |query| query.id == query_type.id }.empty? raise "#{__method__} requested monitor query level is not supported for this server" end if available_response_types(:client => softlayer_client, :response_level => server.network_monitor_levels.response_level).select{ |response| response.id == response_type.id }.empty? raise "#{__method__} requested monitor response level is not supported for this server" end network_monitor_object_filter = ObjectFilter.new() server_id_label = server.kind_of?(VirtualServer) ? 'guestId' : 'hardwareId' network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.arg1Value').when_it is(argument_value.to_s) } network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.' + server_id_label).when_it is(server.id) } network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.ipAddress').when_it is(ip_address.to_s) } network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.queryTypeId').when_it is(query_type.id) } network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.responseActionId').when_it is(response_type.id) } network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.waitCycles').when_it is(wait_cycles) } if server.service.object_filter(network_monitor_object_filter).getNetworkMonitors.empty? network_monitor = softlayer_client[:Network_Monitor_Version1_Query_Host].createObject({ 'arg1Value' => argument_value.to_s, server_id_label => server.id, 'ipAddress' => ip_address.to_s, 'queryTypeId' => query_type.id, 'responseActionId' => response_type.id, 'waitCycles' => wait_cycles }) NetworkMonitor.new(softlayer_client, network_monitor) end end |
.add_network_monitor_notification_users(server, user_customers, options = {}) ⇒ Object
Add user customers to the list of users notified on monitor failure for the specified server. Accepts a list of UserCustomer instances or user customer usernames.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/softlayer/NetworkMonitor.rb', line 191 def self.add_network_monitor_notification_users(server, user_customers, = {}) softlayer_client = [:client] || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client raise "#{__method__} requires a server to monitor but none was given" if !server || !server.kind_of?(Server) raise "#{__method__} requires a list user customers but none was given" if !user_customers || user_customers.empty? user_customers_data = user_customers.map do |user_customer| raise "#{__method__} requires a user customer but none was given" if !user_customer || (!user_customer.class.method_defined?(:username) && user_customer.empty?) user_customer_data = user_customer.class.method_defined?(:username) ? user_customer : UserCustomer.user_customer_with_username(user_customer, softlayer_client) raise "#{__method__} user customer with username #{user_customer.inspect} not found" unless user_customer_data user_customer_data end current_user_customers = server.notified_network_monitor_users.map { |notified_network_monitor_user| notified_network_monitor_user['id'] } user_customers_data.delete_if { |user_customer| current_user_customers.include?(user_customer['id']) } unless user_customers_data.empty? notification_monitor_user_service = server.kind_of?(VirtualServer) ? :User_Customer_Notification_Virtual_Guest : :User_Customer_Notification_Hardware server_id_label = server.kind_of?(VirtualServer) ? 'guestId' : 'hardwareId' user_customer_notifications = user_customers_data.map { |user_customer| { server_id_label => server.id, 'userId' => user_customer['id'] } } softlayer_client[notification_monitor_user_service].createObjects(user_customer_notifications) end end |
.available_query_types(options = {}) ⇒ Object
Return the list of available query types (optionally limited to a max query level)
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/softlayer/NetworkMonitor.rb', line 224 def self.available_query_types( = {}) softlayer_client = [:client] || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client unless @@available_query_types available_query_types_data = softlayer_client[:Network_Monitor_Version1_Query_Host_Stratum].getAllQueryTypes @@available_query_types = available_query_types_data.map{ |query_type| NetworkMonitorQueryType.new(query_type) } end if [:query_level] @@available_query_types.select { |query_type| query_type.monitor_level.to_i <= [:query_level].to_i } else @@available_query_types end end |
.available_response_types(options = {}) ⇒ Object
Return the list of available response types (optionally limited to a max response level)
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/softlayer/NetworkMonitor.rb', line 243 def self.available_response_types( = {}) softlayer_client = [:client] || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client unless @@available_response_types available_response_types_data = softlayer_client[:Network_Monitor_Version1_Query_Host_Stratum].getAllResponseTypes @@available_response_types = available_response_types_data.map { |response_type| NetworkMonitorResponseType.new(response_type) } end if [:response_level] @@available_response_types.select { |response_type| response_type.level.to_i <= [:response_level].to_i } else @@available_response_types end end |
.remove_network_monitor_notification_users(server, user_customers, options = {}) ⇒ Object
Rmove user customers from the list of users notified on monitor failure for the specified server. Accepts a list of UserCustomer instances or user customer usernames.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/softlayer/NetworkMonitor.rb', line 263 def self.remove_network_monitor_notification_users(server, user_customers, = {}) softlayer_client = [:client] || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client raise "#{__method__} requires a server to monitor but none was given" if !server || !server.kind_of?(Server) raise "#{__method__} requires a list user customers but none was given" if !user_customers || user_customers.empty? user_customers_data = user_customers.map do |user_customer| raise "#{__method__} requires a user customer but none was given" if !user_customer || (!user_customer.kind_of?(UserCustomer) && user_customer.empty?) user_customer_data = user_customer.kind_of?(UserCustomer) ? user_customer : UserCustomer.user_customer_with_username(user_customer, softlayer_client) raise "#{__method__} user customer with username #{user_customer.inspect} not found" unless user_customer_data user_customer_data end current_user_customers = user_customers_data.map { |user_customer| user_customer['id'] } monitor_user_notification_object_filter = ObjectFilter.new() monitor_user_notification_object_filter.modify { |filter| filter.accept('monitoringUserNotification.userId').when_it is(current_user_customers) } monitor_user_notification_data = server.service.object_filter(monitor_user_notification_object_filter).object_mask("mask[id]").getMonitoringUserNotification unless monitor_user_notification_data.empty? notification_monitor_user_service = server.kind_of?(VirtualServer) ? :User_Customer_Notification_Virtual_Guest : :User_Customer_Notification_Hardware softlayer_client[notification_monitor_user_service].deleteObjects(monitor_user_notification_data) end end |
.remove_network_monitors(network_monitors, options = {}) ⇒ Object
Removes the list of network monitors from their associated servers. Accpets a list of NetworkMonitor instances or id’s.
296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/softlayer/NetworkMonitor.rb', line 296 def self.remove_network_monitors(network_monitors, = {}) softlayer_client = [:client] || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client network_monitors_data = network_monitors.map do |network_monitor| raise "#{__method__} requires a network monitor instance or id but non provided" if !network_monitor || (!network_monitor.kind_of?(NetworkMonitor) && network_monitor.empty?) network_monitor.kind_of?(NetworkMonitor) ? { 'id' => network_monitor['id'] } : { 'id' => network_monitor } end softlayer_client[:Network_Monitor_Version1_Query_Host].deleteObjects(network_monitors_data) end |
Instance Method Details
#argument_value ⇒ Object
:attr_reader: argument_value The argument to be used for this monitor, if necessary. The lowest monitoring levels (like ping) ignore this setting, but higher levels like HTTP custom use it.
81 |
# File 'lib/softlayer/NetworkMonitor.rb', line 81 sl_attr :argument_value, 'arg1Value' |
#ip_address ⇒ Object
:attr_reader: ip_address The IP address to be monitored. Must be attached to the server on this object.
86 |
# File 'lib/softlayer/NetworkMonitor.rb', line 86 sl_attr :ip_address, 'ipAddress' |
#last_query_result ⇒ Object
The most recent result for this particular monitoring instance. :call-seq:
last_query_result(force_update=false)
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/softlayer/NetworkMonitor.rb', line 103 sl_dynamic_attr :last_query_result do |resource| resource.should_update? do #only retrieved once per instance @last_query_result == nil end resource.to_update do NetworkMonitorQueryResult.new(self.service.object_mask("mask[finishTime,responseStatus,responseTime]").getLastResult) end end |
#query_type ⇒ Object
The type of monitoring query that is executed when this server is monitored. :call-seq:
query_type(force_update=false)
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/softlayer/NetworkMonitor.rb', line 118 sl_dynamic_attr :query_type do |resource| resource.should_update? do #only retrieved once per instance @query_type == nil end resource.to_update do NetworkMonitorQueryType.new(self.service.getQueryType) end end |
#response_type ⇒ Object
The response action taken when a monitor fails. :call-seq:
response_type(force_update=false)
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/softlayer/NetworkMonitor.rb', line 133 sl_dynamic_attr :response_type do |resource| resource.should_update? do #only retrieved once per instance @response_type == nil end resource.to_update do NetworkMonitorResponseType.new(self.service.getResponseAction) end end |
#service ⇒ Object
Returns the service for interacting with this network monitor component through the network API
312 313 314 |
# File 'lib/softlayer/NetworkMonitor.rb', line 312 def service softlayer_client[:Network_Monitor_Version1_Query_Host].object_with_id(self.id) end |
#status ⇒ Object
:attr_reader: The status of this monitoring instance. Anything other than “ON” means that the monitor has been disabled.
91 |
# File 'lib/softlayer/NetworkMonitor.rb', line 91 sl_attr :status |
#wait_cycles ⇒ Object
:attr_reader: wait_cycles The number of 5-minute cycles to wait before the “responseAction” is taken. If set to 0, the response action will be taken immediately.
97 |
# File 'lib/softlayer/NetworkMonitor.rb', line 97 sl_attr :wait_cycles, 'waitCycles' |