mirror of
https://github.com/fluent/fluentd-ui.git
synced 2026-01-29 19:11:05 +01:00
Add roughly format and format options for in_tail setup pages
This commit is contained in:
parent
1dec0bcdc0
commit
8a67f00a17
15
app/assets/javascripts/setting_format.js
Normal file
15
app/assets/javascripts/setting_format.js
Normal file
@ -0,0 +1,15 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
$(function(){
|
||||
var $select = $('#setting-format select');
|
||||
if($select.length === 0) return;
|
||||
|
||||
var $options = $('#setting-format-options');
|
||||
console.log($options);
|
||||
debugger;
|
||||
$select.on("change", function(ev){
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
31
app/assets/javascripts/vue/in_tail_format.js
Normal file
31
app/assets/javascripts/vue/in_tail_format.js
Normal file
@ -0,0 +1,31 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
$(function(){
|
||||
if($('#in_tail_format').length === 0) return;
|
||||
|
||||
new Vue({
|
||||
el: "#in_tail_format",
|
||||
paramAttributes: ["formatOptions", "initialSelected"],
|
||||
data: {
|
||||
// v-model: format
|
||||
},
|
||||
|
||||
created: function(){
|
||||
this.formatOptions = JSON.parse(this.formatOptions);
|
||||
this.formats = Object.keys(this.formatOptions);
|
||||
this.format = this.initialSelected;
|
||||
},
|
||||
|
||||
computed: {
|
||||
options: function(){
|
||||
return this.formatOptions[this.format];
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
@ -4,15 +4,7 @@ class ApiController < ApplicationController
|
||||
end
|
||||
|
||||
def file_preview
|
||||
return empty_json unless params[:file]
|
||||
return empty_json unless File.exists? params[:file]
|
||||
file = params[:file]
|
||||
sample = File.read(file, 1024) || ""
|
||||
sample2 = sample.force_encoding('ascii-8bit').encode('us-ascii', :undef => :replace, :invalid => :replace, :replace => "")
|
||||
return empty_json if sample != sample2 # maybe binary file
|
||||
|
||||
reader = FileReverseReader.new(File.open(file))
|
||||
render json: reader.enum_for(:each_line).to_a.first(10).reverse
|
||||
render json: file_tail(params[:file]) || []
|
||||
end
|
||||
|
||||
def empty_json
|
||||
|
||||
@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
|
||||
helper_method :current_user
|
||||
helper_method :current_locale
|
||||
helper_method :installing_gem?, :installing_gems, :uninstalling_gem?, :uninstalling_gems
|
||||
helper_method :file_tail
|
||||
before_action :login_required
|
||||
before_action :set_locale
|
||||
|
||||
@ -72,4 +73,15 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
I18n.locale = prefer
|
||||
end
|
||||
|
||||
def file_tail(path, limit = 10)
|
||||
return unless path
|
||||
return unless File.exists? path
|
||||
sample = File.read(path, 1024) || ""
|
||||
sample2 = sample.force_encoding('ascii-8bit').encode('us-ascii', :undef => :replace, :invalid => :replace, :replace => "")
|
||||
return if sample != sample2 # maybe binary file
|
||||
|
||||
reader = FileReverseReader.new(File.open(path))
|
||||
reader.enum_for(:each_line).to_a.first(limit).reverse
|
||||
end
|
||||
end
|
||||
|
||||
@ -25,17 +25,18 @@ class Fluentd::SettingsController < ApplicationController
|
||||
})
|
||||
end
|
||||
|
||||
def in_tail_after_format
|
||||
@setting = Fluentd::Setting::InTail.new(setting_params)
|
||||
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"
|
||||
return render "in_tail_after_format"
|
||||
end
|
||||
File.open(@fluentd.agent.config_file, "a") do |f| # TODO: should update by agent class
|
||||
f.write "\n"
|
||||
@ -48,6 +49,6 @@ class Fluentd::SettingsController < ApplicationController
|
||||
private
|
||||
|
||||
def setting_params
|
||||
params.require(:setting).permit(:path, :tag, :rotate_wait, :pos_file, :read_from_head, :refresh_interval)
|
||||
params.require(:setting).permit(:path, :format, *Fluentd::Setting::InTail.known_formats, :tag, :rotate_wait, :pos_file, :read_from_head, :refresh_interval)
|
||||
end
|
||||
end
|
||||
|
||||
@ -8,6 +8,46 @@ class Fluentd
|
||||
validates :tag, presence: true
|
||||
#validates :format, presence: true
|
||||
|
||||
def self.known_formats
|
||||
{
|
||||
:regexp => [],
|
||||
:apache2 => [:time_format],
|
||||
:nginx => [:time_format],
|
||||
:syslog => [:time_format],
|
||||
:tsv => [:keys, :time_key],
|
||||
:csv => [:keys, :time_key],
|
||||
:ltsv => [:delimiter, :time_key],
|
||||
:json => [:time_key],
|
||||
:multiline => [:format_firstline, *(1..20).map{|n| "format#{n}".to_sym}],
|
||||
}
|
||||
end
|
||||
attr_accessor *known_formats.values.flatten.compact
|
||||
|
||||
def known_formats
|
||||
self.class.known_formats
|
||||
end
|
||||
|
||||
def guess_format
|
||||
case path
|
||||
when /\.json$/
|
||||
:json
|
||||
when /\.csv$/
|
||||
:csv
|
||||
when /\.tsv$/
|
||||
:tsv
|
||||
when /\.ltsv$/
|
||||
:ltsv
|
||||
when /nginx/
|
||||
:nginx
|
||||
when /apache/
|
||||
:apache2
|
||||
when %r|/var/log|
|
||||
:syslog
|
||||
else
|
||||
:regexp
|
||||
end
|
||||
end
|
||||
|
||||
def to_conf
|
||||
<<-XML.strip_heredoc.gsub(/^[ ]+\n/m, "")
|
||||
<source>
|
||||
|
||||
38
app/views/fluentd/settings/_form.html.haml
Normal file
38
app/views/fluentd/settings/_form.html.haml
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
- @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
|
||||
- @setting.known_formats[@setting.format.to_sym].each do |key|
|
||||
%label= key
|
||||
= f.hidden_field key
|
||||
= @setting.send(key)
|
||||
%br
|
||||
%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"
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
= 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|
|
||||
= form_for(@setting, as: "setting", url: in_tail_after_format_fluentd_setting_path(@fluentd)) do |f|
|
||||
- @setting.errors.full_messages.each do |e|
|
||||
%div.alert.alert-danger= e
|
||||
|
||||
@ -10,27 +10,9 @@
|
||||
= f.label :path
|
||||
= f.hidden_field :path
|
||||
= f.text_field :path, 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"
|
||||
= render partial: "shared/vue/in_tail_format", locals: { formats: @setting.known_formats, initialSelected: f.object.format || @setting.guess_format }
|
||||
|
||||
%pre= file_tail(@setting.path).join("\n")
|
||||
|
||||
%p
|
||||
= f.submit t('terms.next'), class: "btn btn-primary"
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
- 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_confirm_fluentd_setting_path(@fluentd)) do |f|
|
||||
= render partial: "form", locals: { f: f }
|
||||
|
||||
%p
|
||||
= f.submit t('terms.next'), class: "btn btn-primary"
|
||||
@ -3,33 +3,7 @@
|
||||
= 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 :path
|
||||
= f.hidden_field :path
|
||||
= f.text_field :path, 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"
|
||||
= render partial: "form", locals: { f: f }
|
||||
|
||||
%pre= @setting.to_conf
|
||||
|
||||
|
||||
16
app/views/shared/vue/_in_tail_format.html.erb
Normal file
16
app/views/shared/vue/_in_tail_format.html.erb
Normal file
@ -0,0 +1,16 @@
|
||||
<div id="in_tail_format" class="form-group" formatOptions="<%= formats.to_json %>" initialSelected="<%= initialSelected %>">
|
||||
<div class="form-group">
|
||||
<label>format</label>
|
||||
<select name="setting[format]" v-model="format" class="form-control">
|
||||
<option v-repeat="formats" value="{{ $value }}" v-attr="selected: format==$value">{{ $value }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group" v-repeat="options">
|
||||
<label>{{ $value }} </label>
|
||||
<input type="text" name="setting[{{ $value }}]" />
|
||||
</div>
|
||||
|
||||
<div class="well well-sm">
|
||||
<%= raw t('fluentd.settings.in_tail_option_guide') %>
|
||||
</div>
|
||||
</div>
|
||||
@ -85,6 +85,7 @@ en:
|
||||
config_file: Config file
|
||||
page_title: "%{label}"
|
||||
setup_in_tail: Setup in_tail
|
||||
finish: Update config
|
||||
form:
|
||||
<<: *fluentd_common
|
||||
index:
|
||||
@ -102,6 +103,10 @@ en:
|
||||
fluentd_info: Setting info
|
||||
recent_errors: "Recent %{count} Errors"
|
||||
settings:
|
||||
restart_from_first: Restart from first
|
||||
in_tail_option_guide: |
|
||||
See <a target="_blank" href="http://docs.fluentd.org/articles/in_tail">in_tail Plugin</a> or
|
||||
<a target="_blank" href="http://fluentular.herokuapp.com/">Fluentular</a> for more details.
|
||||
show:
|
||||
<<: *fluentd_common
|
||||
edit:
|
||||
@ -112,10 +117,11 @@ en:
|
||||
in_tail_after_file_choose:
|
||||
<<: *fluentd_common
|
||||
page_title: "Setup in_tail | Other config"
|
||||
in_tail_after_format:
|
||||
<<: *fluentd_common
|
||||
in_tail_confirm:
|
||||
<<: *fluentd_common
|
||||
page_title: "Setup in_tail | Confirmation"
|
||||
finish: Update config
|
||||
|
||||
misc:
|
||||
common: &misc_common
|
||||
|
||||
@ -84,6 +84,8 @@ ja:
|
||||
setting: 設定
|
||||
config_file: 設定ファイル
|
||||
page_title: "%{label}"
|
||||
setup_in_tail: in_tailセットアップ
|
||||
finish: 設定する
|
||||
form:
|
||||
<<: *fluentd_common
|
||||
index:
|
||||
@ -102,6 +104,9 @@ ja:
|
||||
recent_errors: "最新 %{count}件のエラー"
|
||||
settings:
|
||||
restart_from_first: 最初からやり直す
|
||||
in_tail_option_guide: |
|
||||
<a target="_blank" href="http://docs.fluentd.org/ja/articles/in_tail">in_tailプラグインの解説ページ</a>や
|
||||
<a target="_blank" href="http://fluentular.herokuapp.com/">Fluentular</a>もご参照ください。
|
||||
show:
|
||||
<<: *fluentd_common
|
||||
edit:
|
||||
@ -112,10 +117,11 @@ ja:
|
||||
in_tail_after_file_choose:
|
||||
<<: *fluentd_common
|
||||
page_title: "in_tailセットアップ | その他の設定"
|
||||
in_tail_after_format:
|
||||
<<: *fluentd_common
|
||||
in_tail_confirm:
|
||||
<<: *fluentd_common
|
||||
page_title: "in_tailセットアップ | 確認"
|
||||
finish: 設定する
|
||||
|
||||
misc:
|
||||
common: &misc_common
|
||||
|
||||
@ -12,6 +12,7 @@ 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_after_format"
|
||||
post "in_tail_confirm"
|
||||
post "in_tail_finish"
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user