Parent

Net::Ping::LDAP

The Ping::LDAP class encapsulates methods for LDAP pings.

Attributes

encryption[RW]

set/get the encryption method. By default nil, but may be set to :simple_tls

password[RW]
uri[RW]

uri contains the URI object for the request

username[RW]

username and password may be set for ping using an authenticated LDAP bind

Public Class Methods

new(uri=nil, timeout=5) click to toggle source

Creates and returns a new Ping::LDAP object. The default timeout is 5 seconds.

uri string is expected to be a full URI with scheme (ldap/ldaps) and optionally the port (else default port is assumed) e.g.

ldap://my.ldap.host.com
ldap://my.ldap.host.com:1389
ldaps://my.ldap.host.com
ldaps://my.ldap.host.com:6636

If a plain hostname is provided as the uri, a default port of 389 is assumed

# File lib/net/ping/ldap.rb, line 42
def initialize(uri=nil, timeout=5)
  host, port = decode_uri(uri)
  super(host, port, timeout)
end

Public Instance Methods

config() click to toggle source

constructs the LDAP configuration structure

# File lib/net/ping/ldap.rb, line 64
def config
  {
    :host => uri.host,
    :port => uri.port,
    :encryption => encryption
  }.merge(
    (username && password) ?
    { :auth => {:method => :simple, :username => username, :password => password} } :
    { :auth => {:method => :anonymous} }
  )
end
decode_uri(value) click to toggle source

method used to decode uri string

# File lib/net/ping/ldap.rb, line 49
def decode_uri(value)
  @uri = URI.parse(value)
  if uri.scheme =~ /ldap/
    p = @port = uri.port
    h = @host = uri.host
    @encryption = uri.scheme=='ldaps' ? :simple_tls : nil
  else
    h = value
    p = 389
  end
  [h, p]
end
encryption=(value) click to toggle source
# File lib/net/ping/ldap.rb, line 26
def encryption=(value)
  @encryption = (value.is_a? Symbol) ? value : value.to_sym
end
ping(host = nil) click to toggle source

perform ping, optionally providing the ping destination uri

# File lib/net/ping/ldap.rb, line 78
def ping(host = nil)
  decode_uri(host) if host
  super(@host)
  
  bool = false

  start_time = Time.now

  begin
    Timeout.timeout(@timeout) do
      Net::LDAP.new( config  ).bind
    end
  rescue Net::LDAP::LdapError => e
    @exception = e.message
  rescue Exception => e
    @exception = e.message
  else
    bool = true
  end

  # There is no duration if the ping failed
  @duration = Time.now - start_time if bool

  bool
end
Also aliased as: ping?, pingecho
ping?(host = nil) click to toggle source
Alias for: ping
pingecho(host = nil) click to toggle source
Alias for: ping

[Validate]

Generated with the Darkfish Rdoc Generator 2.