Class: Puppet::Util::NetworkDevice::Cudawaf::Facts

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/util/network_device/cudawaf/facts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport, url) ⇒ Facts

Returns a new instance of Facts.



11
12
13
14
15
# File 'lib/puppet/util/network_device/cudawaf/facts.rb', line 11

def initialize(transport, url)
  Puppet.debug(self.class.to_s.split("::").last + ": Inside Initialize of Facts!")
  @transport = transport
  @url = url
end

Instance Attribute Details

#transportObject (readonly)

Returns the value of attribute transport.



9
10
11
# File 'lib/puppet/util/network_device/cudawaf/facts.rb', line 9

def transport
  @transport
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/puppet/util/network_device/cudawaf/facts.rb', line 9

def url
  @url
end

Instance Method Details

#parse_device_factsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/puppet/util/network_device/cudawaf/facts.rb', line 23

def parse_device_facts
  facts = {
    'productType' => 'Cudawaf'
  }

  Puppet.debug(self.class.to_s.split("::").last + ": Parsing facts for device - " + @url.host)
  device_url = @url.scheme + "://" + @url.user + ":" + @url.password + "@" + @url.host + ":" + @url.port.to_s + "/"

  #
  #  Invoke a System API call to retrieve the facts about each device.
  #
  response, status_code = @transport.get(device_url, "System", {})
  if status_code == 200 and items = response['data']['System']
    Puppet.debug(self.class.to_s.split("::").last + ": Response for System API - #{items}")
  else
    Puppet.warning("WARNING: Could not receive device details.")
    return facts
  end

  #
  # These are the facts that are going to be used to identify a particular WAF.
  #         System: {
  #            device-name: Web Application Firewall,
  #            domain: Barracudanetworks.com,
  #            hostname: barracuda,
  #            model: V660,
  #            serial: 557225,
  #            time-zone: America/Los_Angeles
  #        }
  #

  [ 'device_name',
    'hostname',
    'model',
    'serial',
    'domain',
    'time_zone'
  ].each do |fact|
    api_fact_name = fact.to_s.gsub(/_/, "-")
    facts[fact] = items[api_fact_name.to_s]
  end

  Puppet.debug(self.class.to_s.split("::").last + ": Facts - #{facts}")
  return facts
end

#retrieve(url) ⇒ Object



17
18
19
20
21
# File 'lib/puppet/util/network_device/cudawaf/facts.rb', line 17

def retrieve(url)
  Puppet.debug(self.class.to_s.split("::").last + ": Retrieving Facts from facts.rb!")

  facts = parse_device_facts()
end