mirror of
https://github.com/fluent/fluentd-ui.git
synced 2026-05-05 19:06:12 +02:00
Refactor plugin setting
Adding support for some plugins was hard. After this commit, easy to add a plugin that has commonly setting style. Before: - Add model, controller, and views for it. After: - Add model and controller. view is shared.
This commit is contained in:
parent
646f290404
commit
3c7786f262
@ -4,10 +4,13 @@ module SettingConcern
|
||||
included do
|
||||
before_action :login_required
|
||||
before_action :find_fluentd
|
||||
helper_method :target_plugin_name, :plugin_setting_form_action_url
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@setting = target_class.new(initial_params)
|
||||
render "shared/settings/show"
|
||||
end
|
||||
|
||||
def finish
|
||||
@ -31,4 +34,16 @@ module SettingConcern
|
||||
def setting_params
|
||||
params.require(target_class.to_s.underscore.gsub("/", "_")).permit(*target_class.const_get(:KEYS))
|
||||
end
|
||||
|
||||
def initial_params
|
||||
target_class.initial_params
|
||||
end
|
||||
|
||||
def target_plugin_name
|
||||
target_class.to_s.split("::").last.underscore
|
||||
end
|
||||
|
||||
def plugin_setting_form_action_url(*args)
|
||||
send("finish_daemon_setting_#{target_plugin_name}_path", *args)
|
||||
end
|
||||
end
|
||||
|
||||
@ -6,11 +6,4 @@ class Fluentd::Settings::InSyslogController < ApplicationController
|
||||
def target_class
|
||||
Fluentd::Setting::InSyslog
|
||||
end
|
||||
|
||||
def initial_params
|
||||
{
|
||||
bind: "0.0.0.0",
|
||||
port: 5140,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@ -6,16 +6,4 @@ class Fluentd::Settings::OutElasticsearchController < ApplicationController
|
||||
def target_class
|
||||
Fluentd::Setting::OutElasticsearch
|
||||
end
|
||||
|
||||
def initial_params
|
||||
{
|
||||
host: "127.0.0.1",
|
||||
port: 9200,
|
||||
index_name: "via_fluentd",
|
||||
type_name: "via_fluentd",
|
||||
logstash_format: true,
|
||||
include_tag_key: false,
|
||||
utc_index: true,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@ -15,14 +15,4 @@ class Fluentd::Settings::OutForwardController < ApplicationController
|
||||
),
|
||||
)
|
||||
end
|
||||
|
||||
def initial_params
|
||||
{
|
||||
secondary: {
|
||||
"0" => {
|
||||
type: "file",
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@ -6,13 +6,4 @@ class Fluentd::Settings::OutMongoController < ApplicationController
|
||||
def target_class
|
||||
Fluentd::Setting::OutMongo
|
||||
end
|
||||
|
||||
def initial_params
|
||||
{
|
||||
host: "127.0.0.1",
|
||||
port: 27017,
|
||||
capped: true,
|
||||
capped_size: "100m",
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,34 +1,12 @@
|
||||
class Fluentd::Settings::OutS3Controller < ApplicationController
|
||||
before_action :login_required
|
||||
before_action :find_fluentd
|
||||
|
||||
def show
|
||||
@setting = Fluentd::Setting::OutS3.new({
|
||||
s3_endpoint: "s3-us-west-1.amazonaws.com",
|
||||
output_tag: true,
|
||||
output_time: true,
|
||||
use_ssl: true,
|
||||
})
|
||||
end
|
||||
|
||||
def finish
|
||||
@setting = Fluentd::Setting::OutS3.new(setting_params)
|
||||
unless @setting.valid?
|
||||
return render "show"
|
||||
end
|
||||
|
||||
@fluentd.agent.config_append @setting.to_config
|
||||
if @fluentd.agent.running?
|
||||
unless @fluentd.agent.restart
|
||||
@setting.errors.add(:base, @fluentd.agent.log_tail(1).first)
|
||||
return render "show"
|
||||
end
|
||||
end
|
||||
redirect_to daemon_setting_path(@fluentd)
|
||||
end
|
||||
include SettingConcern
|
||||
|
||||
private
|
||||
|
||||
def target_class
|
||||
Fluentd::Setting::OutS3
|
||||
end
|
||||
|
||||
def setting_params
|
||||
params.require(:fluentd_setting_out_s3).permit(*Fluentd::Setting::OutS3::KEYS)
|
||||
end
|
||||
|
||||
@ -11,6 +11,23 @@ class Fluentd
|
||||
attr_accessor(*KEYS)
|
||||
|
||||
validates :tag, presence: true
|
||||
|
||||
def self.initial_params
|
||||
{
|
||||
bind: "0.0.0.0",
|
||||
port: 5140,
|
||||
}
|
||||
end
|
||||
|
||||
def common_options
|
||||
[
|
||||
:tag, :bind, :port, :types,
|
||||
]
|
||||
end
|
||||
|
||||
def advanced_options
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -19,6 +19,32 @@ class Fluentd
|
||||
validates :port, presence: true
|
||||
validates :index_name, presence: true
|
||||
validates :type_name, presence: true
|
||||
|
||||
def self.initial_params
|
||||
{
|
||||
host: "127.0.0.1",
|
||||
port: 9200,
|
||||
index_name: "via_fluentd",
|
||||
type_name: "via_fluentd",
|
||||
logstash_format: true,
|
||||
include_tag_key: false,
|
||||
utc_index: true,
|
||||
}
|
||||
end
|
||||
|
||||
def common_options
|
||||
[
|
||||
:match, :host, :port, :logstash_format,
|
||||
:index_name, :type_name,
|
||||
]
|
||||
end
|
||||
|
||||
def advanced_options
|
||||
[
|
||||
:hosts, :logstash_prefix, :logstash_dateformat,
|
||||
:utc_index, :request_timeout, :include_tag_key,
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -65,6 +65,29 @@ class Fluentd
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def self.initial_params
|
||||
{
|
||||
secondary: {
|
||||
"0" => {
|
||||
type: "file",
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def common_options
|
||||
[
|
||||
:match, :server, :secondary,
|
||||
]
|
||||
end
|
||||
|
||||
def advanced_options
|
||||
[
|
||||
:send_timeout, :recover_wait, :heartbeat_type, :heartbeat_interval,
|
||||
:phi_threshold, :hard_timeout,
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -30,6 +30,29 @@ class Fluentd
|
||||
errors.add(:collection, :blank)
|
||||
end
|
||||
end
|
||||
|
||||
def self.initial_params
|
||||
{
|
||||
host: "127.0.0.1",
|
||||
port: 27017,
|
||||
capped: true,
|
||||
capped_size: "100m",
|
||||
}
|
||||
end
|
||||
|
||||
def common_options
|
||||
[
|
||||
:match, :host, :port, :database, :collection,
|
||||
:tag_mapped, :user, :password,
|
||||
]
|
||||
end
|
||||
|
||||
def advanced_options
|
||||
[
|
||||
:capped, :capped_size, :capped_max, :buffer_type, :buffer_queue_limit, :buffer_chunk_limit,
|
||||
:flush_interval, :retry_wait, :retry_limit, :max_retry_wait, :num_threads,
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -24,6 +24,31 @@ class Fluentd
|
||||
|
||||
validates :match, presence: true
|
||||
validates :s3_bucket, presence: true
|
||||
|
||||
def self.initial_params
|
||||
{
|
||||
s3_endpoint: "s3-us-west-1.amazonaws.com",
|
||||
output_tag: true,
|
||||
output_time: true,
|
||||
use_ssl: true,
|
||||
}
|
||||
end
|
||||
|
||||
def common_options
|
||||
[
|
||||
:match, :aws_key_id, :aws_sec_key,
|
||||
:s3_endpoint, :s3_bucket, :use_ssl, :path,
|
||||
]
|
||||
end
|
||||
|
||||
def advanced_options
|
||||
[
|
||||
:format, :output_tag, :output_time, :include_time_key, :time_key, :delimiter, :label_delimiter,
|
||||
:utc, :time_slice_format, :time_slice_wait, :store_as, :proxy_uri,
|
||||
:buffer_type, :buffer_queue_limit, :buffer_chunk_limit, :flush_interval,
|
||||
:retry_wait, :retry_limit, :max_retry_wait, :num_threads,
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -21,6 +21,27 @@ class Fluentd
|
||||
def plugin_name
|
||||
"tdlog"
|
||||
end
|
||||
|
||||
def self.initial_params
|
||||
{
|
||||
buffer_type: "file",
|
||||
buffer_path: "/var/log/td-agent/buffer/td",
|
||||
auto_create_table: true,
|
||||
match: "td.*.*",
|
||||
}
|
||||
end
|
||||
|
||||
def common_options
|
||||
[
|
||||
:match, :apikey, :auto_create_table, :database, :table,
|
||||
]
|
||||
end
|
||||
|
||||
def advanced_options
|
||||
[
|
||||
:flush_interval, :buffer_type, :buffer_path,
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
= render "shared/setting_errors"
|
||||
|
||||
= form_for(@setting, url: finish_daemon_setting_in_syslog_path(@fluentd), html: {class: "ignore-rails-error-div"}) do |f|
|
||||
= field(f, :tag)
|
||||
= field(f, :bind)
|
||||
= field(f, :port)
|
||||
= field(f, :types)
|
||||
= f.submit t('fluentd.common.finish'), class: "btn btn-lg btn-primary pull-right"
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
- page_title t(".page_title")
|
||||
|
||||
.well
|
||||
= raw t('fluentd.settings.in_syslog.option_guide')
|
||||
|
||||
= render "form"
|
||||
@ -1,23 +0,0 @@
|
||||
= render "shared/setting_errors"
|
||||
|
||||
= form_for(@setting, url: finish_daemon_setting_out_elasticsearch_path(@fluentd), html: {class: "ignore-rails-error-div"}) do |f|
|
||||
= field(f, :match)
|
||||
= field(f, :host)
|
||||
= field(f, :port)
|
||||
= field(f, :logstash_format)
|
||||
= field(f, :index_name)
|
||||
= field(f, :type_name)
|
||||
|
||||
.well.well-sm
|
||||
%h4{"data-toggle" => "collapse", "href" => "#advanced-setting"}
|
||||
= icon('fa-caret-down')
|
||||
= t('terms.advanced_setting')
|
||||
#advanced-setting.collapse
|
||||
= field(f, :hosts)
|
||||
= field(f, :logstash_prefix)
|
||||
= field(f, :logstash_dateformat)
|
||||
= field(f, :utc_index)
|
||||
= field(f, :request_timeout)
|
||||
= field(f, :include_tag_key)
|
||||
= f.submit t('fluentd.common.finish'), class: "btn btn-lg btn-primary pull-right"
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
- page_title t(".page_title")
|
||||
|
||||
.well
|
||||
= raw t('fluentd.settings.out_elasticsearch.option_guide')
|
||||
|
||||
= render "form"
|
||||
@ -1,22 +0,0 @@
|
||||
= render "shared/setting_errors"
|
||||
|
||||
= form_for(@setting, url: finish_daemon_setting_out_forward_path(@fluentd), html: {class: "ignore-rails-error-div"}) do |f|
|
||||
= field(f, :match)
|
||||
= field(f, :server)
|
||||
= field(f, :secondary)
|
||||
%p= t('fluentd.settings.out_forward.secondary_note')
|
||||
|
||||
.well.well-sm
|
||||
%h4{"data-toggle" => "collapse", "href" => "#advanced-setting"}
|
||||
= icon('fa-caret-down')
|
||||
= t('terms.advanced_setting')
|
||||
#advanced-setting.collapse
|
||||
= field(f, :send_timeout)
|
||||
= field(f, :recover_wait)
|
||||
= field(f, :heartbeat_type)
|
||||
= field(f, :heartbeat_interval)
|
||||
= field(f, :phi_threshold)
|
||||
= field(f, :hard_timeout)
|
||||
= f.submit t('fluentd.common.finish'), class: "btn btn-lg btn-primary pull-right"
|
||||
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
- page_title t(".page_title")
|
||||
|
||||
.well
|
||||
= raw t('fluentd.settings.out_forward.option_guide')
|
||||
|
||||
= render "form"
|
||||
@ -1,30 +0,0 @@
|
||||
= render "shared/setting_errors"
|
||||
|
||||
= form_for(@setting, url: finish_daemon_setting_out_mongo_path(@fluentd), html: {class: "ignore-rails-error-div"}) do |f|
|
||||
= field(f, :match)
|
||||
= field(f, :host)
|
||||
= field(f, :port)
|
||||
= field(f, :database)
|
||||
= field(f, :collection)
|
||||
= field(f, :tag_mapped)
|
||||
= field(f, :user)
|
||||
= field(f, :password)
|
||||
|
||||
.well.well-sm
|
||||
%h4{"data-toggle" => "collapse", "href" => "#advanced-setting"}
|
||||
= icon('fa-caret-down')
|
||||
= t('terms.advanced_setting')
|
||||
#advanced-setting.collapse
|
||||
= field(f, :capped)
|
||||
= field(f, :capped_size)
|
||||
= field(f, :capped_max)
|
||||
= field(f, :buffer_type)
|
||||
= field(f, :buffer_queue_limit)
|
||||
= field(f, :buffer_chunk_limit)
|
||||
= field(f, :flush_interval)
|
||||
= field(f, :retry_wait)
|
||||
= field(f, :retry_limit)
|
||||
= field(f, :max_retry_wait)
|
||||
= field(f, :num_threads)
|
||||
= f.submit t('fluentd.common.finish'), class: "btn btn-lg btn-primary pull-right"
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
- page_title t(".page_title")
|
||||
|
||||
= render "form"
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
- page_title t(".page_title")
|
||||
|
||||
.well
|
||||
= raw t('fluentd.settings.out_mongo.option_guide')
|
||||
|
||||
= render "form"
|
||||
@ -1,39 +0,0 @@
|
||||
= render "shared/setting_errors"
|
||||
|
||||
= form_for(@setting, url: finish_daemon_setting_out_s3_path(@fluentd), html: {class: "ignore-rails-error-div"}) do |f|
|
||||
= field(f, :match)
|
||||
= field(f, :aws_key_id)
|
||||
= field(f, :aws_sec_key)
|
||||
= field(f, :s3_endpoint)
|
||||
= field(f, :s3_bucket)
|
||||
= field(f, :use_ssl)
|
||||
= field(f, :path)
|
||||
|
||||
.well.well-sm
|
||||
%h4{"data-toggle" => "collapse", "href" => "#advanced-setting"}
|
||||
= icon('fa-caret-down')
|
||||
= t('terms.advanced_setting')
|
||||
#advanced-setting.collapse
|
||||
= field(f, :format)
|
||||
= field(f, :output_tag)
|
||||
= field(f, :output_time)
|
||||
= field(f, :include_time_key)
|
||||
= field(f, :time_key)
|
||||
= field(f, :delimiter)
|
||||
= field(f, :label_delimiter)
|
||||
= field(f, :utc)
|
||||
= field(f, :time_slice_format)
|
||||
= field(f, :time_slice_wait)
|
||||
= field(f, :store_as)
|
||||
= field(f, :proxy_uri)
|
||||
= field(f, :buffer_type)
|
||||
= field(f, :buffer_queue_limit)
|
||||
= field(f, :buffer_chunk_limit)
|
||||
= field(f, :flush_interval)
|
||||
= field(f, :retry_wait)
|
||||
= field(f, :retry_limit)
|
||||
= field(f, :max_retry_wait)
|
||||
= field(f, :num_threads)
|
||||
= f.submit t('fluentd.common.finish'), class: "btn btn-lg btn-primary pull-right"
|
||||
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
- page_title t(".page_title")
|
||||
|
||||
.well
|
||||
= raw t('fluentd.settings.out_s3.option_guide')
|
||||
|
||||
= render "form"
|
||||
@ -1,18 +0,0 @@
|
||||
= render "shared/setting_errors"
|
||||
|
||||
= form_for(@setting, url: finish_daemon_setting_out_td_path(@fluentd), html: {class: "ignore-rails-error-div"}) do |f|
|
||||
= field(f, :match)
|
||||
= field(f, :apikey)
|
||||
= field(f, :auto_create_table)
|
||||
= field(f, :database)
|
||||
= field(f, :table)
|
||||
|
||||
.well.well-sm
|
||||
%h4{"data-toggle" => "collapse", "href" => "#advanced-setting"}
|
||||
= icon('fa-caret-down')
|
||||
= t('terms.advanced_setting')
|
||||
#advanced-setting.collapse
|
||||
= field(f, :flush_interval)
|
||||
= field(f, :buffer_type)
|
||||
= field(f, :buffer_path)
|
||||
= f.submit t('fluentd.common.finish'), class: "btn btn-lg btn-primary pull-right"
|
||||
@ -1,6 +0,0 @@
|
||||
- page_title t(".page_title")
|
||||
|
||||
.well
|
||||
= raw t('fluentd.settings.out_td.option_guide')
|
||||
|
||||
= render "form"
|
||||
17
app/views/shared/settings/_form.html.haml
Normal file
17
app/views/shared/settings/_form.html.haml
Normal file
@ -0,0 +1,17 @@
|
||||
= render "shared/setting_errors"
|
||||
|
||||
- # NOTE: plugin_setting_form_action_url is defined at SettingConcern
|
||||
= form_for(@setting, url: plugin_setting_form_action_url(@fluentd), html: {class: "ignore-rails-error-div"}) do |f|
|
||||
- @setting.common_options.each do |key|
|
||||
= field(f, key)
|
||||
|
||||
- if @setting.advanced_options.present?
|
||||
.well.well-sm
|
||||
%h4{"data-toggle" => "collapse", "href" => "#advanced-setting"}
|
||||
= icon('fa-caret-down')
|
||||
= t('terms.advanced_setting')
|
||||
#advanced-setting.collapse
|
||||
- @setting.advanced_options.each do |key|
|
||||
= field(f, key)
|
||||
= f.submit t('fluentd.common.finish'), class: "btn btn-lg btn-primary pull-right"
|
||||
|
||||
6
app/views/shared/settings/show.html.haml
Normal file
6
app/views/shared/settings/show.html.haml
Normal file
@ -0,0 +1,6 @@
|
||||
- page_title t("fluentd.settings.#{target_plugin_name}.show.page_title")
|
||||
|
||||
.well
|
||||
= raw t("fluentd.settings.#{target_plugin_name}.option_guide")
|
||||
|
||||
= render "shared/settings/form"
|
||||
Loading…
x
Reference in New Issue
Block a user