From bd1134f9a9440dfec840bc20cac31c76618a193f Mon Sep 17 00:00:00 2001
From: uu59
Date: Mon, 30 Jun 2014 18:45:27 +0900
Subject: [PATCH] in_tail guide to be fluentd/settings/in_tail
---
.../fluentd/settings/in_tail_controller.rb | 58 ++++++++++
.../fluentd/settings/in_tail/_form.html.haml | 43 ++++++++
.../after_file_choose.html.haml} | 6 +-
.../after_format.html.haml} | 4 +-
.../settings/in_tail/confirm.html.haml | 13 +++
.../show.html.haml} | 2 +-
.../settings/in_tail_confirm.html.haml | 13 ---
app/views/fluentd/settings/show.html.haml | 5 +-
config/locales/translation_en.yml | 102 +++++++++---------
config/locales/translation_ja.yml | 97 +++++++++--------
config/routes.rb | 11 +-
11 files changed, 229 insertions(+), 125 deletions(-)
create mode 100644 app/controllers/fluentd/settings/in_tail_controller.rb
create mode 100644 app/views/fluentd/settings/in_tail/_form.html.haml
rename app/views/fluentd/settings/{in_tail_after_file_choose.html.haml => in_tail/after_file_choose.html.haml} (63%)
rename app/views/fluentd/settings/{in_tail_after_format.html.haml => in_tail/after_format.html.haml} (54%)
create mode 100644 app/views/fluentd/settings/in_tail/confirm.html.haml
rename app/views/fluentd/settings/{in_tail.html.haml => in_tail/show.html.haml} (67%)
delete mode 100644 app/views/fluentd/settings/in_tail_confirm.html.haml
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.
-
-
- Example
-
-
- 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 |
-
-
- in_tail_option_guide: |
- See in_tail Plugin or
- Fluentular for more details.
show:
<<: *fluentd_common
edit:
<<: *fluentd_common
+ in_tail_option_guide: |
+ See in_tail Plugin or
+ Fluentular for more details.
in_tail:
<<: *fluentd_common
- page_title: "File readling | Choosing File"
- in_tail_after_file_choose:
- <<: *fluentd_common
- page_title: "File readling | Setting format"
- in_tail_after_format:
- <<: *fluentd_common
- page_title: "File readling | Other config"
- in_tail_confirm:
- <<: *fluentd_common
- page_title: "File readling | Confirmation"
+ 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.
+
+
+ Example
+
+
+ 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 |
+
+
+ show:
+ <<: *fluentd_common
+ page_title: "File readling | Choosing File"
+ after_file_choose:
+ <<: *fluentd_common
+ page_title: "File readling | Setting format"
+ after_format:
+ <<: *fluentd_common
+ page_title: "File readling | Other config"
+ confirm:
+ <<: *fluentd_common
+ page_title: "File readling | Confirmation"
misc:
common: &misc_common
diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml
index 091312f..a0ee558 100644
--- a/config/locales/translation_ja.yml
+++ b/config/locales/translation_ja.yml
@@ -106,61 +106,60 @@ ja:
<<: *fluentd_common
page_title: fluentd | ログ
settings:
- restart_from_first: 最初からやり直す
- in_tail_option_guide: |
- in_tailプラグインの解説ページや
- Fluentularもご参照ください。
- grok_manual: |
-
- 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 |
-
-
-
+ <<: *fluentd_common
show:
<<: *fluentd_common
edit:
<<: *fluentd_common
+ in_tail_option_guide: |
+ in_tailプラグインの解説ページや
+ Fluentularもご参照ください。
in_tail:
<<: *fluentd_common
- page_title: "ファイル読み込み | ファイルの選択"
- in_tail_after_file_choose:
- <<: *fluentd_common
- page_title: "ファイル読み込み | フォーマットの設定"
- in_tail_after_format:
- <<: *fluentd_common
- page_title: "ファイル読み込み | その他の設定"
- in_tail_confirm:
- <<: *fluentd_common
- page_title: "ファイル読み込み | 確認"
+ restart_from_first: 最初からやり直す
+ grok_manual: |
+
+ 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 |
+
+
+
+ show:
+ page_title: "ファイル読み込み | ファイルの選択"
+ after_file_choose:
+ page_title: "ファイル読み込み | フォーマットの設定"
+ after_format:
+ page_title: "ファイル読み込み | その他の設定"
+ confirm:
+ page_title: "ファイル読み込み | 確認"
misc:
common: &misc_common
diff --git a/config/routes.rb b/config/routes.rb
index db954d2..39a586d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -11,11 +11,12 @@ Rails.application.routes.draw do
get "log_tail"
end
resource :setting, only: [:show, :edit, :update], module: :fluentd do
- get "in_tail"
- post "in_tail_after_file_choose"
- post "in_tail_after_format"
- post "in_tail_confirm"
- post "in_tail_finish"
+ resource :in_tail, only: ["show"], module: :settings, controller: :in_tail do
+ post "after_file_choose"
+ post "after_format"
+ post "confirm"
+ post "finish"
+ end
end
end