class LogStash::Inputs::NetLdap

Performs a LDAP search using net-ldap.

Usage :

input {

ldap{
  host => "myLdapHost"
  port => 389
  dn => "myDn"
  password => "myPassword"
  base => "ou=people,dc=gouv,dc=fr"
  filter => [{field=>"field1" value=>"value1"}, {field=>"field2" value=>"value2"}
  attrs => ['uid', 'mail', 'sn', 'cn']
}

}

Public Instance Methods

register() click to toggle source
# File lib/logstash/inputs/netldap.rb, line 63
def register
  require "net/ldap"
  require "rufus/scheduler"
  @host = Socket.gethostname
  
  if @anonymous
    auth = { :method => :anonymous}
  else
    if @dn.nil? or @password.nil?
      raise(LogStash::ConfigurationError, ":dn and :password must be set when bind is not anonymous.")
    end
    auth = {
      :method => :simple,
      :username => @dn,
      :password => @password.value  
    }
  end
  @conn = Net::LDAP.new :host => @ldap_host,
  :port => @port,
  :auth => auth
end
run(queue) click to toggle source
# File lib/logstash/inputs/netldap.rb, line 85
def run(queue)
  if @schedule
    @scheduler = Rufus::Scheduler.new(:max_work_threds => 1)
    @scheduler.cron @schedule do
      execute_search(queue)
    end
    @scheduler.join
  else
    execute_search(queue)
  end
end
stop() click to toggle source
# File lib/logstash/inputs/netldap.rb, line 126
def stop
  @scheduler.shutdown(:wait) if @scheduler
end