diff --git a/app/controllers/fluentd/settings/in_tail_controller.rb b/app/controllers/fluentd/settings/in_tail_controller.rb new file mode 100644 index 0000000..90489cd --- /dev/null +++ b/app/controllers/fluentd/settings/in_tail_controller.rb @@ -0,0 +1,58 @@ +class Fluentd::Settings::InTailController < ApplicationController + before_action :login_required + before_action :find_fluentd + + def after_file_choose + @setting = Fluentd::Setting::InTail.new({ + :path => params[:path], + :tag => nil, + }) + end + + def after_format + @setting = Fluentd::Setting::InTail.new(setting_params) + end + + def confirm + @setting = Fluentd::Setting::InTail.new(setting_params) + if params[:back] + return render :after_file_choose + end + unless @setting.valid? + return render :after_format + end + end + + def finish + @setting = Fluentd::Setting::InTail.new(setting_params) + if params[:back] + return render :after_format + end + + unless @setting.valid? + return render "after_format" + end + + if @fluentd.agent.configuration.to_s.include?(@setting.to_conf.strip) + @setting.errors.add(:base, :duplicated_conf) + return render "after_format" + end + + File.open(@fluentd.agent.config_file, "a") do |f| # TODO: should update by agent class + f.write "\n" + f.write @setting.to_conf + end + @fluentd.agent.restart if @fluentd.agent.running? + redirect_to fluentd_setting_path(@fluentd) + end + + private + + def setting_params + setting_params = params.require(:setting).permit(:path, :format, :regexp, *Fluentd::Setting::InTail.known_formats, :tag, :rotate_wait, :pos_file, :read_from_head, :refresh_interval) + { + :pos_file => "/tmp/fluentd-#{@fluentd.id}-#{Time.now.to_i}.pos", + }.merge setting_params + end + +end diff --git a/app/views/fluentd/settings/in_tail/_form.html.haml b/app/views/fluentd/settings/in_tail/_form.html.haml new file mode 100644 index 0000000..8e1c488 --- /dev/null +++ b/app/views/fluentd/settings/in_tail/_form.html.haml @@ -0,0 +1,43 @@ + +- @setting.errors.full_messages.each do |e| + %div.alert.alert-danger= e + +%div.form-group + = f.label :path + = f.hidden_field :path + = f.text_field :path, class: "form-control", disabled: true +%div.form-group + = f.label :format + = f.hidden_field :format + = f.text_field :format, class: "form-control", disabled: true +- if @setting.known_formats[@setting.format.to_sym] + - @setting.known_formats[@setting.format.to_sym].each do |key| + %label= key + = f.hidden_field key + = @setting.send(key) + %br +- else + %label= @setting.format + = f.hidden_field :regexp + = @setting.regexp +%div.form-group + = f.label :tag + = f.text_field :tag, class: "form-control" +%div.form-group + = f.label :pos_file + = f.text_field :pos_file, class: "form-control" +.well.well-sm + %h4{"data-toggle" => "collapse", "href" => "#advanced-setting"} + = icon('fa-caret-down') + = t('terms.advanced_setting') + #advanced-setting.collapse + %div.form-group + = f.label :rotate_wait + = f.text_field :rotate_wait, class: "form-control" + %div.form-group + = f.label :read_from_head + = f.check_box :read_from_head, class: "form-control" + %div.form-group + = f.label :refresh_interval + = f.text_field :refresh_interval, class: "form-control" + diff --git a/app/views/fluentd/settings/in_tail_after_file_choose.html.haml b/app/views/fluentd/settings/in_tail/after_file_choose.html.haml similarity index 63% rename from app/views/fluentd/settings/in_tail_after_file_choose.html.haml rename to app/views/fluentd/settings/in_tail/after_file_choose.html.haml index d1747f2..feb2c4b 100644 --- a/app/views/fluentd/settings/in_tail_after_file_choose.html.haml +++ b/app/views/fluentd/settings/in_tail/after_file_choose.html.haml @@ -1,8 +1,8 @@ - page_title t(".page_title") -= link_to t('fluentd.settings.restart_from_first'), in_tail_fluentd_setting_path += link_to t('fluentd.settings.in_tail.restart_from_first'), fluentd_setting_in_tail_path(@fluentd) -= form_for(@setting, as: "setting", url: in_tail_after_format_fluentd_setting_path(@fluentd)) do |f| += form_for(@setting, as: "setting", url: after_format_fluentd_setting_in_tail_path(@fluentd)) do |f| - @setting.errors.full_messages.each do |e| %div.alert.alert-danger= e @@ -16,4 +16,4 @@ %p = f.submit t('terms.next'), class: "btn btn-lg btn-primary pull-right" - = link_to t('terms.prev'), in_tail_fluentd_setting_path, class: "btn btn-lg btn-default" + = link_to t('terms.prev'), fluentd_setting_in_tail_path(@fluentd), class: "btn btn-lg btn-default" diff --git a/app/views/fluentd/settings/in_tail_after_format.html.haml b/app/views/fluentd/settings/in_tail/after_format.html.haml similarity index 54% rename from app/views/fluentd/settings/in_tail_after_format.html.haml rename to app/views/fluentd/settings/in_tail/after_format.html.haml index 20adb39..61f3ba2 100644 --- a/app/views/fluentd/settings/in_tail_after_format.html.haml +++ b/app/views/fluentd/settings/in_tail/after_format.html.haml @@ -1,8 +1,8 @@ - page_title t(".page_title") -= link_to t('fluentd.settings.restart_from_first'), in_tail_fluentd_setting_path += link_to t('fluentd.settings.in_tail.restart_from_first'), fluentd_setting_in_tail_path(@fluentds) -= form_for(@setting, as: "setting", url: in_tail_confirm_fluentd_setting_path(@fluentd)) do |f| += form_for(@setting, as: "setting", url: confirm_fluentd_setting_in_tail_path(@fluentd)) do |f| = render partial: "form", locals: { f: f } %p diff --git a/app/views/fluentd/settings/in_tail/confirm.html.haml b/app/views/fluentd/settings/in_tail/confirm.html.haml new file mode 100644 index 0000000..d5e9a6f --- /dev/null +++ b/app/views/fluentd/settings/in_tail/confirm.html.haml @@ -0,0 +1,13 @@ +- page_title t(".page_title") + += link_to t('fluentd.settings.in_tail.restart_from_first'), fluentd_setting_in_tail_path(@fluentd) + += form_for(@setting, as: "setting", url: finish_fluentd_setting_in_tail_path(@fluentd)) do |f| + = render partial: "form", locals: { f: f } + + %pre= @setting.to_conf + + %p + = 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" + .clearfix.pull-right= t('terms.notice_restart_for_config_edit') diff --git a/app/views/fluentd/settings/in_tail.html.haml b/app/views/fluentd/settings/in_tail/show.html.haml similarity index 67% rename from app/views/fluentd/settings/in_tail.html.haml rename to app/views/fluentd/settings/in_tail/show.html.haml index ff3ee55..e1cdfa9 100644 --- a/app/views/fluentd/settings/in_tail.html.haml +++ b/app/views/fluentd/settings/in_tail/show.html.haml @@ -1,4 +1,4 @@ - page_title t(".page_title") -= render partial: "shared/vue/treeview", locals: {name: "path", action: in_tail_after_file_choose_fluentd_setting_path(@fluentd), submit_button: t('terms.next')} += render partial: "shared/vue/treeview", locals: {name: "path", action: after_file_choose_fluentd_setting_in_tail_path(@fluentd), submit_button: t('terms.next')} diff --git a/app/views/fluentd/settings/in_tail_confirm.html.haml b/app/views/fluentd/settings/in_tail_confirm.html.haml deleted file mode 100644 index c2e7a35..0000000 --- a/app/views/fluentd/settings/in_tail_confirm.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -- page_title t(".page_title") - -= link_to t('fluentd.settings.restart_from_first'), in_tail_fluentd_setting_path - -= form_for(@setting, as: "setting", url: in_tail_finish_fluentd_setting_path(@fluentd)) do |f| - = render partial: "form", locals: { f: f } - - %pre= @setting.to_conf - - %p - = f.submit t('.finish') , class: "btn btn-lg btn-primary pull-right" - = f.submit t('terms.prev'), class: "btn btn-lg btn-default", name: "back" - .clearfix.pull-right= t('.notice_restart_for_config_edit') diff --git a/app/views/fluentd/settings/show.html.haml b/app/views/fluentd/settings/show.html.haml index fe5628d..2f0a0ca 100644 --- a/app/views/fluentd/settings/show.html.haml +++ b/app/views/fluentd/settings/show.html.haml @@ -10,5 +10,6 @@ .row .col-lg-4.well - = link_to icon('fa-file-text-o fa-lg'), in_tail_fluentd_setting_path(@fluentd) - = link_to t(".setup_in_tail"), in_tail_fluentd_setting_path(@fluentd) + = link_to(fluentd_setting_in_tail_path(@fluentd)) do + = icon('fa-file-text-o fa-lg') + = t("fluentd.common.setup_in_tail") diff --git a/config/locales/translation_en.yml b/config/locales/translation_en.yml index b68238a..88156bc 100644 --- a/config/locales/translation_en.yml +++ b/config/locales/translation_en.yml @@ -106,62 +106,64 @@ en: <<: *fluentd_common page_title: fluentd | Log settings: - restart_from_first: Restart from first - grok_manual: | -
- Grok syntax, for example, %{INT:foo}
pattern given then translate to /(?<foo>(?:[+-]?(?:[0-9]+)))/
regexp.
-
- Available key/value are here. -
- -
- Nov 29 17:02:55 MacBook-Pro-2.local UserEventAgent[239] : cannot find fw daemon port 1102
the log you have,
- %{MONTH:month}%{SPACE}%{MONTHDAY:day} %{TIME:time} %{DATA} \[%{INT:pid}\]
for matching that, you will gain following result.
-
Key | -Value | -
---|---|
month | Nov | -
day | 29 | -
time | 17:02:55 | -
pid | 239 | -
+ Grok syntax, for example, %{INT:foo}
pattern given then translate to /(?<foo>(?:[+-]?(?:[0-9]+)))/
regexp.
+
+ Available key/value are here. +
+ +
+ Nov 29 17:02:55 MacBook-Pro-2.local UserEventAgent[239] : cannot find fw daemon port 1102
the log you have,
+ %{MONTH:month}%{SPACE}%{MONTHDAY:day} %{TIME:time} %{DATA} \[%{INT:pid}\]
for matching that, you will gain following result.
+
Key | +Value | +
---|---|
month | Nov | +
day | 29 | +
time | 17:02:55 | +
pid | 239 | +
- Grokの記法が使えます。例えば%{INT:foo}
とすると、/(?<foo>(?:[+-]?(?:[0-9]+)))/
という正規表現に変換されます。
-
- 使えるキー・値についてはリファレンスをご確認ください。 -
--
Nov 29 17:02:55 MacBook-Pro-2.local UserEventAgent[239] : cannot find fw daemon port 1102
というログに対し、%{MONTH:month}%{SPACE}%{MONTHDAY:day} %{TIME:time} %{DATA} \[%{INT:pid}\]
というパターンを適用すると以下の結果が得られます。
-
- キー名 | -値 | -
---|---|
month | Nov | -
day | 29 | -
time | 17:02:55 | -
pid | 239 | -
+ Grokの記法が使えます。例えば%{INT:foo}
とすると、/(?<foo>(?:[+-]?(?:[0-9]+)))/
という正規表現に変換されます。
+
+ 使えるキー・値についてはリファレンスをご確認ください。 +
++
Nov 29 17:02:55 MacBook-Pro-2.local UserEventAgent[239] : cannot find fw daemon port 1102
というログに対し、%{MONTH:month}%{SPACE}%{MONTHDAY:day} %{TIME:time} %{DATA} \[%{INT:pid}\]
というパターンを適用すると以下の結果が得られます。
+
+ キー名 | +値 | +
---|---|
month | Nov | +
day | 29 | +
time | 17:02:55 | +
pid | 239 | +