class AlertLogic::ProtectedHost

AlertLogic ProtectedHost built from a JSON API response.

Public Instance Methods

appliance?(appliance) click to toggle source
# File lib/alert_logic/resources/protected_host.rb, line 14
def appliance?(appliance)
  # sometimes appliance_assigned_to wont exist if the Protected Host isn't
  # already assigned to an appliance.
  if respond_to?(:appliance_assigned_to)
    appliance = find_appliance(appliance) if appliance.is_a?(String)
    appliance.id == appliance_assigned_to
  else
    false
  end
end
appliance_policy_id=(policy_id) click to toggle source
# File lib/alert_logic/resources/protected_host.rb, line 6
def appliance_policy_id=(policy_id)
  update_policy('appliance', policy_id)
end
assign_appliance(appliance) click to toggle source
# File lib/alert_logic/resources/protected_host.rb, line 25
def assign_appliance(appliance)
  if appliance?(appliance)
    AlertLogic.logger.info 'Host is already assigned to that Appliance'
  else
    appliance = find_appliance(appliance) if appliance.is_a?(String)
    policy = AlertLogic::Policy \
      .find('type' => 'appliance_assignment') \
      .select { |pol| pol.appliances.any? { |ap| ap == appliance.id } } \
      .first
    self.appliance_policy_id = policy.id
  end
end
config_policy_id=(policy_id) click to toggle source
# File lib/alert_logic/resources/protected_host.rb, line 10
def config_policy_id=(policy_id)
  update_policy('config', policy_id)
end
reload!() click to toggle source
Calls superclass method AlertLogic::Resource#reload!
# File lib/alert_logic/resources/protected_host.rb, line 38
def reload!
  [:@appliance_assigned_to,
   :@appliance_connected_to,
   :@appliance_policy_id,
   :@config_policy_id
  ].each do |var|
    remove_instance_variable(var) if instance_variable_defined?(var)
  end
  super
end

Private Instance Methods

find_appliance(name) click to toggle source
# File lib/alert_logic/resources/protected_host.rb, line 51
def find_appliance(name)
  msg = "Searching for an appliance with name: #{name}"
  AlertLogic.logger.info msg
  Appliance.find.select { |ap| ap.name == name }.first
end
update_policy(policy_type, policy_id) click to toggle source
# File lib/alert_logic/resources/protected_host.rb, line 57
def update_policy(policy_type, policy_id)
  payload = { 'protectedhost' =>
    { policy_type => { 'policy' => { 'id' => policy_id } } }
  }
  res = AlertLogic.api_client.edit('protectedhost', id, payload)
  AlertLogic.logger.debug res.body.inspect
  reload!
  AlertLogic.logger.info "#{policy_type} policy updated!"
end