mirror of
https://github.com/fluent/fluentd-ui.git
synced 2025-08-11 16:57:11 +02:00
Refactoring for commonly setting controllers to be concern
This commit is contained in:
parent
b2a6f0e9dc
commit
6551280ba0
34
app/controllers/concerns/setting_concern.rb
Normal file
34
app/controllers/concerns/setting_concern.rb
Normal file
@ -0,0 +1,34 @@
|
||||
module SettingConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_action :login_required
|
||||
before_action :find_fluentd
|
||||
end
|
||||
|
||||
def show
|
||||
@setting = target_class.new(initial_params)
|
||||
end
|
||||
|
||||
def finish
|
||||
@setting = target_class.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
|
||||
|
||||
private
|
||||
|
||||
def setting_params
|
||||
params.require(target_class.to_s.underscore.gsub("/", "_")).permit(*target_class.const_get(:KEYS))
|
||||
end
|
||||
end
|
@ -1,34 +1,16 @@
|
||||
class Fluentd::Settings::InSyslogController < ApplicationController
|
||||
before_action :login_required
|
||||
before_action :find_fluentd
|
||||
|
||||
def show
|
||||
@setting = Fluentd::Setting::InSyslog.new({
|
||||
bind: "0.0.0.0",
|
||||
port: 5140,
|
||||
})
|
||||
end
|
||||
|
||||
def finish
|
||||
@setting = Fluentd::Setting::InSyslog.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 setting_params
|
||||
params.require(:fluentd_setting_in_syslog).permit(*Fluentd::Setting::InSyslog::KEYS)
|
||||
def target_class
|
||||
Fluentd::Setting::InSyslog
|
||||
end
|
||||
|
||||
def initial_params
|
||||
{
|
||||
bind: "0.0.0.0",
|
||||
port: 5140,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -1,35 +1,12 @@
|
||||
class Fluentd::Settings::OutForwardController < ApplicationController
|
||||
before_action :login_required
|
||||
before_action :find_fluentd
|
||||
|
||||
def show
|
||||
@setting = Fluentd::Setting::OutForward.new({
|
||||
secondary: {
|
||||
"0" => {
|
||||
type: "file",
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
def finish
|
||||
@setting = Fluentd::Setting::OutForward.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::OutForward
|
||||
end
|
||||
|
||||
def setting_params
|
||||
params.require(:fluentd_setting_out_forward).permit(*Fluentd::Setting::OutForward::KEYS).merge(
|
||||
params.require(:fluentd_setting_out_forward).permit(
|
||||
@ -39,4 +16,13 @@ class Fluentd::Settings::OutForwardController < ApplicationController
|
||||
)
|
||||
end
|
||||
|
||||
def initial_params
|
||||
{
|
||||
secondary: {
|
||||
"0" => {
|
||||
type: "file",
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -1,36 +1,18 @@
|
||||
class Fluentd::Settings::OutMongoController < ApplicationController
|
||||
before_action :login_required
|
||||
before_action :find_fluentd
|
||||
include SettingConcern
|
||||
|
||||
def show
|
||||
@setting = Fluentd::Setting::OutMongo.new({
|
||||
private
|
||||
|
||||
def target_class
|
||||
Fluentd::Setting::OutMongo
|
||||
end
|
||||
|
||||
def initial_params
|
||||
{
|
||||
host: "127.0.0.1",
|
||||
port: 27017,
|
||||
capped: true,
|
||||
capped_size: "100m",
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
def finish
|
||||
@setting = Fluentd::Setting::OutMongo.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
|
||||
|
||||
private
|
||||
|
||||
def setting_params
|
||||
params.require(:fluentd_setting_out_mongo).permit(*Fluentd::Setting::OutMongo::KEYS)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,36 +1,18 @@
|
||||
class Fluentd::Settings::OutTdController < ApplicationController
|
||||
before_action :login_required
|
||||
before_action :find_fluentd
|
||||
include SettingConcern
|
||||
|
||||
def show
|
||||
@setting = Fluentd::Setting::OutTd.new({
|
||||
private
|
||||
|
||||
def target_class
|
||||
Fluentd::Setting::OutTd
|
||||
end
|
||||
|
||||
def initial_params
|
||||
{
|
||||
buffer_type: "file",
|
||||
buffer_path: "/var/log/td-agent/buffer/td",
|
||||
auto_create_table: true,
|
||||
match: "td.*.*",
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
def finish
|
||||
@setting = Fluentd::Setting::OutTd.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
|
||||
|
||||
private
|
||||
|
||||
def setting_params
|
||||
params.require(:fluentd_setting_out_td).permit(*Fluentd::Setting::OutTd::KEYS)
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user