Class: AlertLogic::ProtectedHost

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/alert_logic/resources/protected_host.rb

Overview

AlertLogic ProtectedHost built from a JSON API response.

Instance Method Summary collapse

Methods included from Resource

filters, #find, #find_by_id, included, #initialize, #name=, #tags=

Instance Method Details

#appliance?(appliance) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
# 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) ⇒ Object



6
7
8
# 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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object



10
11
12
# File 'lib/alert_logic/resources/protected_host.rb', line 10

def config_policy_id=(policy_id)
  update_policy('config', policy_id)
end

#reload!Object



38
39
40
41
42
43
44
45
46
47
# 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