diff --git a/app/assets/stylesheets/common.css.scss b/app/assets/stylesheets/common.css.scss index d2c7418..7a5a9cd 100644 --- a/app/assets/stylesheets/common.css.scss +++ b/app/assets/stylesheets/common.css.scss @@ -103,4 +103,6 @@ label { } } - +*[data-toggle] { + cursor: pointer; +} diff --git a/app/controllers/fluentd/settings_controller.rb b/app/controllers/fluentd/settings_controller.rb index 6ac4486..0d870e9 100644 --- a/app/controllers/fluentd/settings_controller.rb +++ b/app/controllers/fluentd/settings_controller.rb @@ -19,9 +19,35 @@ class Fluentd::SettingsController < ApplicationController end def in_tail_after_file_choose - @file = params[:file] + @setting = Fluentd::Setting::InTail.new({ + :file => params[:file], + :tag => nil, + }) end def in_tail_confirm + @setting = Fluentd::Setting::InTail.new(setting_params) + unless @setting.valid? + return render "in_tail_after_file_choose" + end + end + + def in_tail_finish + @setting = Fluentd::Setting::InTail.new(setting_params) + unless @setting.valid? + return render "in_tail_after_file_choose" + 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 + params.require(:setting).permit(:file, :tag, :rotate_wait, :pos_file, :read_from_head, :refresh_interval) end end diff --git a/app/models/fluentd/setting.rb b/app/models/fluentd/setting.rb new file mode 100644 index 0000000..8b9dfcf --- /dev/null +++ b/app/models/fluentd/setting.rb @@ -0,0 +1,25 @@ +class Fluentd + module Setting + class InTail + include ActiveModel::Model + attr_accessor :file, :tag, :rotate_wait, :pos_file, :read_from_head, :refresh_interval + + validates :file, presence: true + validates :tag, presence: true + + def to_conf + <<-XML.strip_heredoc.gsub(/^[ ]+\n/m, "") + + type tail + file #{file} + tag #{tag} + #{read_from_head.to_i.zero? ? "" : "read_from_head true"} + #{pos_file.present? ? "pos_file #{pos_file}" : ""} + #{rotate_wait.present? ? "rotate_wait #{rotate_wait}" : ""} + #{refresh_interval.present? ? "refresh_interval #{refresh_interval}" : ""} + + XML + end + end + end +end diff --git a/app/views/fluentd/settings/in_tail.html.haml b/app/views/fluentd/settings/in_tail.html.haml index db6fb6b..41f7d1f 100644 --- a/app/views/fluentd/settings/in_tail.html.haml +++ b/app/views/fluentd/settings/in_tail.html.haml @@ -1,4 +1,4 @@ -- page_title "TODO: 監視したいファイルをえらんでください" +- page_title t(".page_title") -= render partial: "shared/vue/treeview", locals: {name: "file", action: in_tail_after_file_choose_fluentd_setting_path(@fluentd), submit_button: "(TODO)次へ"} += render partial: "shared/vue/treeview", locals: {name: "file", action: in_tail_after_file_choose_fluentd_setting_path(@fluentd), submit_button: t('terms.next')} 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 index 37ada87..fa4cb48 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,3 +1,36 @@ -- page_title "TODO: 監視したいファイルをえらんでください" +- page_title t(".page_title") -= @file += link_to t('fluentd.settings.restart_from_first'), in_tail_fluentd_setting_path + += form_for(@setting, as: "setting", url: in_tail_confirm_fluentd_setting_path(@fluentd)) do |f| + - @setting.errors.full_messages.each do |e| + %div.alert.alert-danger= e + + %div.form-group + = f.label :file + = f.hidden_field :file + = f.text_field :file, class: "form-control", disabled: true + %div.form-group + = f.label :tag + = f.text_field :tag, 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 :pos_file + = f.text_field :pos_file, 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" + + + %p + = f.submit t('terms.next'), class: "btn btn-primary" 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..0b4b588 --- /dev/null +++ b/app/views/fluentd/settings/in_tail_confirm.html.haml @@ -0,0 +1,38 @@ +- 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| + - @setting.errors.full_messages.each do |e| + %div.alert.alert-danger= e + + %div.form-group + = f.label :file + = f.hidden_field :file + = f.text_field :file, class: "form-control", disabled: true + %div.form-group + = f.label :tag + = f.text_field :tag, 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 :pos_file + = f.text_field :pos_file, 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" + + %pre= @setting.to_conf + + %p + = f.submit t('.finish'), class: "btn btn-primary" + = 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 8b3af7d..d544b3a 100644 --- a/app/views/fluentd/settings/show.html.haml +++ b/app/views/fluentd/settings/show.html.haml @@ -6,4 +6,4 @@ = link_to t(".edit"), edit_fluentd_setting_path(@fluentd) -= link_to "TODO: in_tailセットアップ", in_tail_fluentd_setting_path(@fluentd) += link_to t(".setup_in_tail"), in_tail_fluentd_setting_path(@fluentd) diff --git a/config/locales/translation_en.yml b/config/locales/translation_en.yml index 2389837..c21fef6 100644 --- a/config/locales/translation_en.yml +++ b/config/locales/translation_en.yml @@ -33,6 +33,9 @@ en: Really %{action}? reload_log: Reload fluend log auto_reload: "Auto Reload(every %{seconds} seconds)" + next: Next + advanced_setting: Advanced Setting + notice_restart_for_config_edit: "NOTICE: fluentd will restart after update config" plugins: notice_restart_for_config_edit: "NOTICE: fluentd will restart after update config" @@ -81,6 +84,7 @@ en: setting: Setting config_file: Config file page_title: "%{label}" + setup_in_tail: Setup in_tail form: <<: *fluentd_common index: @@ -102,6 +106,16 @@ en: <<: *fluentd_common edit: <<: *fluentd_common + in_tail: + <<: *fluentd_common + page_title: "Setup in_tail | Choosing File" + in_tail_after_file_choose: + <<: *fluentd_common + page_title: "Setup in_tail | Other config" + in_tail_confirm: + <<: *fluentd_common + page_title: "Setup in_tail | Confirmation" + finish: Update config misc: common: &misc_common diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index 18eaaa7..c8d17b9 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -33,6 +33,9 @@ ja: %{action}しますか? reload_log: fluentdのログを更新 auto_reload: "自動更新(%{seconds}秒ごと)" + next: 次へ + advanced_setting: 高度な設定 + notice_restart_for_config_edit: ※更新するとfluentdが再起動されます plugins: notice_restart_for_config_edit: ※更新するとfluentdが再起動されます @@ -98,10 +101,21 @@ ja: fluentd_info: 設定情報 recent_errors: "最新 %{count}件のエラー" settings: + restart_from_first: 最初からやり直す show: <<: *fluentd_common edit: <<: *fluentd_common + in_tail: + <<: *fluentd_common + page_title: "in_tailセットアップ | ファイルの選択" + in_tail_after_file_choose: + <<: *fluentd_common + page_title: "in_tailセットアップ | その他の設定" + in_tail_confirm: + <<: *fluentd_common + page_title: "in_tailセットアップ | 確認" + finish: 設定する misc: common: &misc_common diff --git a/config/routes.rb b/config/routes.rb index c011778..19be54a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,6 +12,8 @@ Rails.application.routes.draw do resource :setting, only: [:show, :edit, :update], module: :fluentd do get "in_tail" post "in_tail_after_file_choose" + post "in_tail_confirm" + post "in_tail_finish" end end