-1

I use my custom fluentd plugin and it does not work with ubuntu20 but for other ubuntu version is no problem.

Here is my error

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

I try to use my custom plugins for fluentd. I want to write an additional in_tail plugin feature.

Here is the code I try:

root@test0044:/etc/td-agent/plugin# cat in_tail_asis_alternative.rb # Fluent::AsisAlternativeInput # Fluent::AsisParser module 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>
leanghy
  • 50
  • 6
  • How is your definition of `TailInput`, and how do you use it? Obviously, this constant is not defined, at least not inside `Fluent`. – user1934428 May 20 '21 at 07:29
  • Thank you for your answer actually I try to use a custom plugin for fluentd. I want to write an additional in_tail plugin feature. – leanghy May 20 '21 at 07:38
  • Rather than just including the error, can you include a minimal example of the code you used to get the error? – Jad May 20 '21 at 07:42
  • Thank you I just edit my question with example below – leanghy May 20 '21 at 07:43
  • @leanghy : I don't see any definition for `Fluent::TailInput`, so of course you get a "not defined" error. – user1934428 May 20 '21 at 08:04
  • @user1934428 I'm sorry because ruby is very new for me. So How can I fix it? – leanghy May 20 '21 at 08:06
  • You need to load the definition of `TailInput`. I have never worked with `Fluent`, but according to the [Fluent plugin guide](https://docs.fluentd.org/plugin-development), a `require 'fluent/plugin/input'` could be a good start. Otherwise, I would search the fluent source files for the definition of `TailInput`. – user1934428 May 20 '21 at 08:12
  • @user1934428 Thank you for your answer. But actually, my custom plugin just inherited from TailInput class, and those class also already require 'fluent/plugin/input'. But still see the error message. One more thing I try with other ubuntu version is no problem except only ubuntu20. – leanghy May 20 '21 at 08:23
  • But if you do not have a `require` statement, how should Ruby process the inheritance? Or do you have one, and just did not post the whole code? I guess that the NameError is shown for exactly the line in which you define `AsisAlternativeInput`, isn't it? – user1934428 May 20 '21 at 09:33
  • @user1934428 Yes the error is the line that I define class AsisAlternativeInput < TailInput – leanghy May 20 '21 at 10:11
  • And, do you have the appropriate `require` statement??? – user1934428 May 20 '21 at 11:34
  • @user1934428 actually before I already require 'fluent/plugin/input but seems still not working. So is correct? – leanghy May 20 '21 at 11:38
  • Did you check, whether `TailInput` is defined in this file? – user1934428 May 20 '21 at 12:00
  • @user1934428 I put my full code in the answer section. Could you help me take a look? – leanghy May 20 '21 at 12:05

1 Answers1

0

I fixed this problem because it need require class 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
leanghy
  • 50
  • 6
  • As I said already: You are using `TailInput` but don't provide a definition for it. – user1934428 May 20 '21 at 13:44
  • Plus (once you have fixed this), you will likely run into problems because `Configurable` is not defined. – user1934428 May 20 '21 at 13:46
  • `Plugin` does not seem to be defined either, neither is `Engine`. Are you sure that you are showing the complete code? – user1934428 May 20 '21 at 13:50
  • @user1934428 Actually this full code is inherited from class TailInput and the class location is in /opt/td-agent/lib/ruby/gems/2.7.0/gems/fluentd-1.12.3/lib/fluent/plugin/in_tail.rb – leanghy May 20 '21 at 14:00
  • @user1934428 And more detail is this URL https://www.rubydoc.info/gems/fluentd/1.12.3/Fluent/Plugin/TailInput#initialize-instance_method – leanghy May 20 '21 at 14:02
  • 1
    code can't be inherited, and classes are not located in a file. Sorry, but what you are writing, does not make sense to me. – user1934428 May 20 '21 at 14:02
  • 1
    I don't deny that the source code for the classes mentioned are defined in **some** file, but just because a class definition exists in some arbitrary file, it does not mean that Ruby knows about it. This applies only to Ruby core classes. – user1934428 May 20 '21 at 14:04
  • Show how you include the information in lib/fluent/plugin/in_tail.rb into your code! – user1934428 May 20 '21 at 14:05
  • @user1934428 By the way I really thank you so much for your help me out I will try more to understand this programming flow. if have any update I will comment in here to let you know. – leanghy May 20 '21 at 14:06
  • @user1934428 Thank you so much for your help. Now my problem has been solved. I had edited my answer section. – leanghy May 28 '21 at 04:55