How to Write Base Plugin
require 'fluent/plugin/input' # This may be input, filter, output, parser, formatter, storage or buffer.
module Fluent::Plugin
class MyExampleInput < Input
# Plugins should be registered by calling `Fluent::Plugin.register_TYPE` method with name and `self`.
# The first argument String is to identify the plugin in the configuration file.
# The second argument is class of the plugin itself, `self` in most cases.
Fluent::Plugin.register_input('my_example', self)
desc 'The port number'
# `config_param` Defines a parameter. You can refer the following parameter via @port instance variable.
# Without `:default`, a parameter is required.
config_param :port, :integer
config_section :user, param_name: :users, multi: true, required: false do
desc 'Username for authentication'
config_param :username, :string
desc 'Password for authentication'
config_param :password, :string, secret: true
end
def configure(conf)
super
# If the configuration is invalid, raise `Fluent::ConfigError`.
if @port <= 1024
raise Fluent::ConfigError, "port number is too small: #{@port}"
end
@users.each do |user|
if user.password.length < 5
raise Fluent::ConfigError, "password is too short for user '#{user.username}'"
end
end
end
def start
super
# ...
end
def shutdown
# ...
super
end
end
endClass Methods
.config_param(name, type = nil, **options, &block)
.config_param(name, type = nil, **options, &block).config_set_default(name, default_value)
.config_set_default(name, default_value).config_set_desc(name, description)
.config_set_desc(name, description).desc(description)
.desc(description).config_section(name, **options, &block)
.config_section(name, **options, &block).configured_in(section_name)
.configured_in(section_name).system_config
.system_config.system_config_override(options = {})
.system_config_override(options = {})Instance Methods
#initialize
#initialize#configure(conf)
#configure(conf)#log
#log#has_router?
#has_router?#start
#start#stop
#stop#before_shutdown
#before_shutdown#shutdown
#shutdown#after_shutdown
#after_shutdown#close
#close#terminate
#terminateMethods for Input/Filter/Output
.helpers(*symbols)
.helpers(*symbols)#plugin_id
#plugin_id#plugin_id_configured?
#plugin_id_configured?Last updated
Was this helpful?