mirror of
https://github.com/fluent/fluentd-ui.git
synced 2025-08-12 01:07:09 +02:00
Add transport section config definitions
Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
parent
6da22693c2
commit
5f10c5618b
@ -22,27 +22,8 @@ class Api::ConfigDefinitionsController < ApplicationController
|
|||||||
target_class = Fluentd::Setting.const_get("#{prefix}_#{name}".classify)
|
target_class = Fluentd::Setting.const_get("#{prefix}_#{name}".classify)
|
||||||
target = target_class.new
|
target = target_class.new
|
||||||
|
|
||||||
common_options = target.common_options.map do |key|
|
common_options = build_options(target, target.common_options)
|
||||||
h = {
|
advanced_options = build_options(target, target.advanced_options)
|
||||||
name: key,
|
|
||||||
type: target.column_type(key),
|
|
||||||
desc: target.desc(key),
|
|
||||||
default: target.default(key)
|
|
||||||
}
|
|
||||||
h[:list] = target.list_of(key) if target.column_type(key) == :enum
|
|
||||||
h
|
|
||||||
end
|
|
||||||
|
|
||||||
advanced_options = target.advanced_options.map do |key|
|
|
||||||
h = {
|
|
||||||
name: key,
|
|
||||||
type: target.column_type(key),
|
|
||||||
desc: target.desc(key),
|
|
||||||
default: target.default(key)
|
|
||||||
}
|
|
||||||
h[:list] = target.list_of(key) if target.column_type(key) == :enum
|
|
||||||
h
|
|
||||||
end
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
type: type,
|
type: type,
|
||||||
@ -50,6 +31,31 @@ class Api::ConfigDefinitionsController < ApplicationController
|
|||||||
commonOptions: common_options,
|
commonOptions: common_options,
|
||||||
advancedOptions: advanced_options
|
advancedOptions: advanced_options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if type == "input" && ["forward", "syslog"].include?(name)
|
||||||
|
transport = target.class._sections[:transport]
|
||||||
|
transport_common_options = build_options(transport, target.transport_common_options)
|
||||||
|
transport_advanced_options = build_options(transport, target.transport_advanced_options)
|
||||||
|
options[:transport] = {
|
||||||
|
commonOptions: transport_common_options,
|
||||||
|
advancedOptions: transport_advanced_options
|
||||||
|
}
|
||||||
|
end
|
||||||
render json: options
|
render json: options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def build_options(target, keys)
|
||||||
|
keys.map do |key|
|
||||||
|
h = {
|
||||||
|
name: key,
|
||||||
|
type: target.column_type(key),
|
||||||
|
desc: target.desc(key),
|
||||||
|
default: target.default(key)
|
||||||
|
}
|
||||||
|
h[:list] = target.list_of(key) if target.column_type(key) == :enum
|
||||||
|
h
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,6 +89,7 @@ class Fluentd
|
|||||||
else
|
else
|
||||||
attribute(name, :section)
|
attribute(name, :section)
|
||||||
section_class = Class.new(::Fluentd::Setting::Section)
|
section_class = Class.new(::Fluentd::Setting::Section)
|
||||||
|
section_class.include(Fluentd::Setting::PluginParameter)
|
||||||
section_class.section_name = name
|
section_class.section_name = name
|
||||||
section_class.required = options[:required]
|
section_class.required = options[:required]
|
||||||
section_class.multi = options[:multi]
|
section_class.multi = options[:multi]
|
||||||
|
@ -6,19 +6,19 @@ class Fluentd
|
|||||||
include Fluentd::Setting::Configurable
|
include Fluentd::Setting::Configurable
|
||||||
|
|
||||||
def column_type(name)
|
def column_type(name)
|
||||||
self.class._types[name]
|
self.class.column_type(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_of(name)
|
def list_of(name)
|
||||||
self.class._list[name]
|
self.class.list_of(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def desc(name)
|
def desc(name)
|
||||||
self.class._descriptions[name]
|
self.class.desc(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def default(name)
|
def default(name)
|
||||||
reformat_value(name, self.class._defaults[name])
|
self.class.reformat_value(name, self.class.default(name))
|
||||||
end
|
end
|
||||||
|
|
||||||
def common_options
|
def common_options
|
||||||
@ -77,19 +77,6 @@ class Fluentd
|
|||||||
formatter_class.new(format["0"].except("type"))
|
formatter_class.new(format["0"].except("type"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def reformat_value(name, value)
|
|
||||||
type = column_type(name)
|
|
||||||
return value if type.nil? # name == :time_key
|
|
||||||
return value if type == :enum
|
|
||||||
return value if type == :regexp
|
|
||||||
type_name = if type.is_a?(Fluentd::Setting::Type::Time)
|
|
||||||
:time
|
|
||||||
else
|
|
||||||
type
|
|
||||||
end
|
|
||||||
Fluent::Config::REFORMAT_VALUE.call(type_name, value)
|
|
||||||
end
|
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def column_type(name)
|
def column_type(name)
|
||||||
self._types[name]
|
self._types[name]
|
||||||
@ -99,6 +86,14 @@ class Fluentd
|
|||||||
self._list[name]
|
self._list[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def desc(name)
|
||||||
|
self._descriptions[name]
|
||||||
|
end
|
||||||
|
|
||||||
|
def default(name)
|
||||||
|
reformat_value(name, self._defaults[name])
|
||||||
|
end
|
||||||
|
|
||||||
def have_buffer_section?
|
def have_buffer_section?
|
||||||
self._sections.key?(:buffer)
|
self._sections.key?(:buffer)
|
||||||
end
|
end
|
||||||
@ -137,6 +132,19 @@ class Fluentd
|
|||||||
end
|
end
|
||||||
keys
|
keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reformat_value(name, value)
|
||||||
|
type = column_type(name)
|
||||||
|
return value if type.nil? # name == :time_key
|
||||||
|
return value if type == :enum
|
||||||
|
return value if type == :regexp
|
||||||
|
type_name = if type.is_a?(Fluentd::Setting::Type::Time)
|
||||||
|
:time
|
||||||
|
else
|
||||||
|
type
|
||||||
|
end
|
||||||
|
Fluent::Config::REFORMAT_VALUE.call(type_name, value)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user