mirror of
https://github.com/fluent/fluentd-ui.git
synced 2026-05-08 12:26:11 +02:00
Add basis out_mongo setting
This commit is contained in:
parent
82adda962d
commit
c833682cc8
@ -116,3 +116,10 @@ label {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.ignore-rails-error-div {
|
||||
.field_with_errors {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
|
||||
36
app/controllers/fluentd/settings/out_mongo_controller.rb
Normal file
36
app/controllers/fluentd/settings/out_mongo_controller.rb
Normal file
@ -0,0 +1,36 @@
|
||||
class Fluentd::Settings::OutMongoController < ApplicationController
|
||||
before_action :login_required
|
||||
before_action :find_fluentd
|
||||
|
||||
def show
|
||||
@setting = Fluentd::Setting::OutMongo.new({
|
||||
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_conf
|
||||
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 fluentd_setting_path(@fluentd)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def setting_params
|
||||
params.require(:fluentd_setting_out_mongo).permit(*Fluentd::Setting::OutMongo::KEYS)
|
||||
end
|
||||
|
||||
end
|
||||
63
app/models/fluentd/setting/out_mongo.rb
Normal file
63
app/models/fluentd/setting/out_mongo.rb
Normal file
@ -0,0 +1,63 @@
|
||||
class Fluentd
|
||||
module Setting
|
||||
class OutMongo
|
||||
include ActiveModel::Model
|
||||
|
||||
KEYS = [
|
||||
:host, :port, :database, :collection, :capped, :capped_size, :capped_max, :user, :password, :tag_mapped,
|
||||
:buffer_type, :buffer_queue_limit, :buffer_chunk_limit, :flush_interval, :retry_wait, :retry_limit, :max_retry_wait, :num_threads,
|
||||
].freeze
|
||||
|
||||
attr_accessor(*KEYS)
|
||||
|
||||
validates :host, presence: true
|
||||
validates :port, presence: true
|
||||
validates :database, presence: true
|
||||
validate :validate_capped
|
||||
validate :validate_collection
|
||||
|
||||
def to_conf
|
||||
<<-XML.strip_heredoc.gsub(/^[ ]*\n/m, "")
|
||||
<match *.*>
|
||||
type mongo
|
||||
#{print_if_present :host}
|
||||
#{print_if_present :port}
|
||||
#{print_if_present :database}
|
||||
#{print_if_present :collection}
|
||||
#{print_if_present :user}
|
||||
#{print_if_present :password}
|
||||
|
||||
#{self.capped.present? ? "capped" : ""}
|
||||
#{print_if_present :capped_size}
|
||||
#{print_if_present :capped_max}
|
||||
|
||||
#{self.tag_mapped.present? ? "tag_mapped" : ""}
|
||||
#{print_if_present :buffer_type}
|
||||
#{print_if_present :buffer_queue_limit}
|
||||
#{print_if_present :buffer_chunk_limit}
|
||||
#{print_if_present :flush_interval}
|
||||
#{print_if_present :retry_wait}
|
||||
#{print_if_present :retry_limit}
|
||||
#{print_if_present :max_retry_wait}
|
||||
#{print_if_present :num_threads}
|
||||
</match>
|
||||
XML
|
||||
end
|
||||
|
||||
def print_if_present(key)
|
||||
send(key).present? ? "#{key} #{send(key)}" : ""
|
||||
end
|
||||
|
||||
def validate_capped
|
||||
return true if capped.blank?
|
||||
errors.add(:capped_size, :blank) if capped_size.blank?
|
||||
end
|
||||
|
||||
def validate_collection
|
||||
if tag_mapped.blank? && collection.blank?
|
||||
errors.add(:collection, :blank)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
- @setting.errors.full_messages.each do |e|
|
||||
%div.alert.alert-danger= e
|
||||
|
||||
|
||||
67
app/views/fluentd/settings/out_mongo/_form.html.haml
Normal file
67
app/views/fluentd/settings/out_mongo/_form.html.haml
Normal file
@ -0,0 +1,67 @@
|
||||
- @setting.errors.full_messages.each do |msg|
|
||||
= msg
|
||||
|
||||
= form_for(@setting, url: finish_fluentd_setting_out_mongo_path(@fluentd), html: {class: "ignore-rails-error-div"}) do |f|
|
||||
.form-group
|
||||
= f.label :host
|
||||
= f.text_field :host
|
||||
.form-group
|
||||
= f.label :port
|
||||
= f.text_field :port
|
||||
.form-group
|
||||
= f.label :database
|
||||
= f.text_field :database
|
||||
.form-group
|
||||
= f.label :collection
|
||||
= f.text_field :collection
|
||||
.form-group
|
||||
= f.label :tag_mapped
|
||||
= f.check_box :tag_mapped, {}, "checked", nil
|
||||
.form-group
|
||||
= f.label :user
|
||||
= f.text_field :user
|
||||
.form-group
|
||||
= f.label :password
|
||||
= f.text_field :password
|
||||
|
||||
.well.well-sm
|
||||
%h4{"data-toggle" => "collapse", "href" => "#advanced-setting"}
|
||||
= icon('fa-caret-down')
|
||||
= t('terms.advanced_setting')
|
||||
#advanced-setting.collapse
|
||||
.form-group
|
||||
= f.label :capped
|
||||
= f.check_box :capped, {}, "checked", nil
|
||||
.form-group
|
||||
= f.label :capped_size
|
||||
= f.text_field :capped_size
|
||||
.form-group
|
||||
= f.label :capped_max
|
||||
= f.text_field :capped_max
|
||||
.form-group
|
||||
= f.label :buffer_type
|
||||
= f.text_field :buffer_type
|
||||
.form-group
|
||||
= f.label :buffer_queue_limit
|
||||
= f.text_field :buffer_queue_limit
|
||||
.form-group
|
||||
= f.label :buffer_chunk_limit
|
||||
= f.text_field :buffer_chunk_limit
|
||||
.form-group
|
||||
= f.label :flush_interval
|
||||
= f.text_field :flush_interval
|
||||
.form-group
|
||||
= f.label :retry_wait
|
||||
= f.text_field :retry_wait
|
||||
.form-group
|
||||
= f.label :retry_limit
|
||||
= f.text_field :retry_limit
|
||||
.form-group
|
||||
= f.label :max_retry_wait
|
||||
= f.text_field :max_retry_wait
|
||||
.form-group
|
||||
= f.label :num_threads
|
||||
= f.text_field :num_threads
|
||||
= f.submit t('fluentd.common.finish') , class: "btn btn-lg btn-primary pull-right"
|
||||
= f.submit t('terms.prev'), class: "btn btn-lg btn-default", name: "back"
|
||||
|
||||
4
app/views/fluentd/settings/out_mongo/finish.html.haml
Normal file
4
app/views/fluentd/settings/out_mongo/finish.html.haml
Normal file
@ -0,0 +1,4 @@
|
||||
- page_title t(".page_title")
|
||||
|
||||
= render "form"
|
||||
|
||||
3
app/views/fluentd/settings/out_mongo/show.html.haml
Normal file
3
app/views/fluentd/settings/out_mongo/show.html.haml
Normal file
@ -0,0 +1,3 @@
|
||||
- page_title t(".page_title")
|
||||
|
||||
= render "form"
|
||||
@ -17,6 +17,10 @@ Rails.application.routes.draw do
|
||||
post "confirm"
|
||||
post "finish"
|
||||
end
|
||||
|
||||
resource :out_mongo, only: ["show"], module: :settings, controller: :out_mongo do
|
||||
post "finish"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user