Class: OpenldapMonitorExtractor::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/openldap_monitor_extractor/core.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, options = { }) ⇒ Core

Returns a new instance of Core.



10
11
12
13
14
15
16
17
18
# File 'lib/openldap_monitor_extractor/core.rb', line 10

def initialize(config, options={ })

  options     = { :mapper =>Mapper }.merge(options)
  
  @connection = Connection.new(config).connection
  @mapper     = options[:mapper]

  self
end

Instance Method Details

#get(key = :all) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/openldap_monitor_extractor/core.rb', line 32

def get(key=:all)

  raise ArgumentError.new("Monitor invalid key: #{key}") unless @mapper.validate_key(key)

  result   = MonitorData.new()
  key_list = (key == :all) ? @mapper::dns() : [key]

  key_list.each do |k|

    dn        = @mapper.dn(k)
    attribute = @mapper.attribute(k)
    entry     = get_monitor_parameter(dn, attribute)
    
    raise StandardError.new("Problems getting Monitor for data: #{dn}") unless entry
  
    result.add(k, entry)
  end

  result
end

#get_monitor_parameter(dn, attribute, options = { }) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/openldap_monitor_extractor/core.rb', line 21

def get_monitor_parameter(dn, attribute, options={ })
  
  options = { :filter =>Net::LDAP::Filter.eq("objectClass", "*") }.merge(options)

  @connection.search(
    :filter     =>options[:filter],
    :base       =>dn, 
    :attributes =>[attribute]) 
end