Class: Fluent::Plugin::LdapEnrichFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::Plugin::LdapEnrichFilter
- Defined in:
- lib/fluent/plugin/filter_ldap_enrich.rb
Constant Summary collapse
- NAME =
'ldap_enrich'- DEFAULT_LDAP_HOST =
'localhost'- DEFAULT_LDAP_PORT =
389- DEFAULT_LDAP_ENCRYPTION =
false- DEFAULT_LDAP_BASE_DN =
''- DEFAULT_LDAP_USERNAME =
nil- DEFAULT_LDAP_PASSWORD =
nil- DEFAULT_LDAP_ATTRIBUTES =
{}.freeze
- DEFAULT_CACHE_ENABLE =
true- DEFAULT_CACHE_SIZE =
1000- DEFAULT_CACHE_TTL_POSITIVE =
24 * 3600
- DEFAULT_CACHE_TTL_NEGATIVE =
3600
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #filter(_tag, _time, record) ⇒ Object
- #interpolate_ldap_query(record) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/fluent/plugin/filter_ldap_enrich.rb', line 76 def configure(conf) super raise Fluent::ConfigError, 'ldap_query should be defined' if !ldap_query || ldap_query.empty? raise Fluent::ConfigError, 'ldap_attributes should be defined' if !ldap_attributes || ldap_attributes.empty? true end |
#filter(_tag, _time, record) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/fluent/plugin/filter_ldap_enrich.rb', line 116 def filter(_tag, _time, record) return record if !ldap_query || ldap_query.empty? return record if !ldap_attributes || ldap_attributes.empty? query_string = interpolate_ldap_query(record) return record unless query_string ldap_result = @cache.get(query_string) do |ldap_query_string| @ldap_client.search_query(ldap_query_string) end if ldap_result ldap_attributes.each do |key, record_key| record[record_key] = (ldap_result[key.to_sym] || ldap_result[key])&.join(', ') end end record end |
#interpolate_ldap_query(record) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/fluent/plugin/filter_ldap_enrich.rb', line 135 def interpolate_ldap_query(record) ldap_query % record.transform_keys(&:to_sym) rescue StandardError => e log.warn("#{NAME}: while interpolating ldap_query \"#{ldap_query}\", #{e.message}") nil end |
#shutdown ⇒ Object
110 111 112 113 114 |
# File 'lib/fluent/plugin/filter_ldap_enrich.rb', line 110 def shutdown @ldap_client.close super end |
#start ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/fluent/plugin/filter_ldap_enrich.rb', line 85 def start super @ldap_client = Fluent::Plugin::LdapClient::LdapClient.new( host: ldap_host, port: ldap_port, base_dn: ldap_base_dn, username: ldap_username, password: ldap_password, encryption: ldap_encryption, ca_cert: ldap_ca_cert, log: log ) @cache = if cache_enable Fluent::Plugin::LdapClient::CacheTTL.new( size: cache_size, ttl_positive: cache_ttl_positive, ttl_negative: cache_ttl_negative ) else Fluent::Plugin::LdapClient::NoCache.new end end |