class Fluent::OpenLDAPMonitorInput
Constants
- SUPPRESS_ATTRIBUTES
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_openldap_monitor.rb, line 11 def initialize super require 'net/ldap' end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_openldap_monitor.rb, line 16 def configure(conf) super auth = { method: :simple, username: @bind_dn, password: @bind_password, } @ldap = Net::LDAP.new(host: @host, port: @port, auth: auth) end
convert_entries(entries)
click to toggle source
# File lib/fluent/plugin/in_openldap_monitor.rb, line 50 def convert_entries(entries) result = {} entries.each do |entry| values_of = {} entry.each do |attribute, values| next if SUPPRESS_ATTRIBUTES.include?(attribute.to_s) values_of[attribute] = convert_values_type(values) end dn = entry[:dn].first # e.g.) cn=Current,cn=Connections,cn=Monitor dn = dn.split(',').map { |d| d.sub(/cn\=/,'').gsub(/\s+/,'_').downcase.to_sym }.reverse # e.g.) [:monitor, :connections, :current] case dn.size when 1 result[dn[0]] ||= values_of when 2 result[dn[0]][dn[1]] ||= values_of when 3 result[dn[0]][dn[1]][dn[2]] ||= values_of when 4 result[dn[0]][dn[1]][dn[2]][dn[3]] ||= values_of else raise dn.size.to_s end end result end
convert_values_type(values)
click to toggle source
# File lib/fluent/plugin/in_openldap_monitor.rb, line 77 def convert_values_type(values) values = [values].flatten.map { |v| if v == 'TRUE' true elsif v == 'FALSE' false elsif v.match(/^\d+$/) v.to_i else v end } values.size == 1 ? values.first : values end
ldapsearch()
click to toggle source
# File lib/fluent/plugin/in_openldap_monitor.rb, line 41 def ldapsearch entries = @ldap.search(attributes: ['+'], base: 'cn=Monitor') result = convert_entries(entries.flatten) Fluent::Engine.emit(@tag, Fluent::Engine.now, result) rescue => e log.warn("#{e.message} (#{e.class.to_s}) #{e.backtrace.to_s}") end
shutdown()
click to toggle source
# File lib/fluent/plugin/in_openldap_monitor.rb, line 35 def shutdown @watcher.detach @loop.stop @thread.join end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_openldap_monitor.rb, line 27 def start super @watcher = TimerWatcher.new(@check_interval, true, &method(:ldapsearch)) @loop = Coolio::Loop.new @watcher.attach(@loop) @thread = Thread.new(@loop.run) end