-1

我使用我的自定义 fluentd 插件,它不适用于 ubuntu20,但对于其他 ubuntu 版本没问题。

这是我的错误

Traceback (most recent call last):
    22: from /usr/sbin/td-agent:15:in `<main>'
    21: from /usr/sbin/td-agent:15:in `load'
    20: from /opt/td-agent/bin/fluentd:23:in `<top (required)>'
    19: from /opt/td-agent/bin/fluentd:23:in `load'
    18: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/bin/fluentd:8:in `<top (required)>'
    17: from /opt/td-agent/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
    16: from /opt/td-agent/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
    15: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/command/fluentd.rb:345:in `<top (required)>'
    14: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/supervisor.rb:648:in `run_supervisor'
    13: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/engine.rb:80:in `run_configure'
    12: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/engine.rb:105:in `configure'
    11: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/root_agent.rb:152:in `configure'
    10: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/root_agent.rb:152:in `each'
     9: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/root_agent.rb:158:in `block in configure'
     8: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/root_agent.rb:312:in `add_source'
     7: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/plugin.rb:105:in `new_input'
     6: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/plugin.rb:160:in `new_impl'
     5: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/registry.rb:44:in `lookup'
     4: from /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/registry.rb:68:in `search'
     3: from /opt/td-agent/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
     2: from /opt/td-agent/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
     1: from /etc/td-agent/plugin/in_tail_asis_alternative.rb:3:in `<top (required)>'
/etc/td-agent/plugin/in_tail_asis_alternative.rb:5:in `<module:Fluent>': uninitialized constant Fluent::TailInput (NameError)
root@test0044:/etc/td-agent/conf.d# vim /etc/td-agent/plugin/in_tail_asis_alternative.rb

我尝试将我的自定义插件用于 fluentd。我想写一个额外的 in_tail 插件功能。

这是我尝试的代码:

root@test0044:/etc/td-agent/plugin# cat in_tail_asis_alternative.rb # Fluent::AsisAlternativeInput # Fluent::AsisParser 模块 Fluent

class AsisAlternativeInput < Fluent::TailInput
 Plugin.register_input('tail_asis_alternative', self)
 def initialize
 super
 @parser = nil
end

def configure(conf)
 super
 host = `hostname -f`.chomp
 @tag += '.' unless @tag.end_with?('.')
 @tag += host
end

def configure_parser(conf)
 @parser = AsisParser.new
 @parser.configure(conf)
end

end

class AsisParser
 include Configurable

 config_param :asis_key, :string, :default => 'message'

def parse(text)
 record = {}
 record[@asis_key] = text
 return Engine.now, record
end

end

end

root@test0044:/etc/td-agent/conf.d# cat syslog.conf
<source>
 @type tail_asis_alternative
 path /var/log/syslog
 pos_file /var/log/td-agent/pos/syslog.pos
 tag raw.syslog
</source>

<source>
 @type tail_asis_alternative
 path /var/log/bashlog
 pos_file /var/log/td-agent/pos/bashlog.pos
 tag raw.bashlog
</source>

<source>
 @type tail_asis_alternative
 path /var/log/auth.log
 pos_file /var/log/td-agent/pos/authlog.pos
 tag raw.authlog
</source>
4

1 回答 1

0

我解决了这个问题,因为它需要需要类 in_tail

require 'fluent/plugin/in_tail' #Need to require fluent/plugin/in_tail 
module Fluent
class AsisAlternativeInput < Fluent::Plugin::TailInput #inherite from class TailInput
 Fluent::Plugin.register_input('tail_asis_alternative', self)
 def initialize
 super
 @parser = nil
end
def configure(conf)
 super
 host = `hostname -f`.chomp
 @tag += '.' unless @tag.end_with?('.')
 @tag += host
end
def configure_parser(conf)
 @parser = AsisParser.new
 @parser.configure(conf)
end
end
class AsisParser
 include Configurable
 config_param :asis_key, :string, :default => 'message'
def parse(text)
 record = {}
 record[@asis_key] = text
 return Engine.now, record
end
end
end
于 2021-05-20T12:04:53.223 回答