mirror of
https://github.com/fluent/fluentd-ui.git
synced 2026-05-05 10:56:11 +02:00
Support grok format (still work in progress)
This commit is contained in:
parent
53b70ce356
commit
c5096bf86e
@ -65,8 +65,9 @@ class Fluentd::SettingsController < ApplicationController
|
||||
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 params.require(:setting).permit(:path, :format, *Fluentd::Setting::InTail.known_formats, :tag, :rotate_wait, :pos_file, :read_from_head, :refresh_interval)
|
||||
}.merge setting_params
|
||||
end
|
||||
end
|
||||
|
||||
@ -2,7 +2,7 @@ class Fluentd
|
||||
module Setting
|
||||
class InTail
|
||||
include ActiveModel::Model
|
||||
attr_accessor :path, :tag, :format, :time_format, :rotate_wait, :pos_file, :read_from_head, :refresh_interval
|
||||
attr_accessor :path, :tag, :format, :regexp, :time_format, :rotate_wait, :pos_file, :read_from_head, :refresh_interval
|
||||
|
||||
validates :path, presence: true
|
||||
validates :tag, presence: true
|
||||
@ -10,7 +10,6 @@ class Fluentd
|
||||
|
||||
def self.known_formats
|
||||
{
|
||||
:regexp => [],
|
||||
:apache2 => [:time_format],
|
||||
:nginx => [:time_format],
|
||||
:syslog => [:time_format],
|
||||
@ -18,6 +17,7 @@ class Fluentd
|
||||
:csv => [:keys, :time_key],
|
||||
:ltsv => [:delimiter, :time_key],
|
||||
:json => [:time_key],
|
||||
:grok => [:grok_str],
|
||||
}
|
||||
end
|
||||
attr_accessor *known_formats.values.flatten.compact
|
||||
@ -43,21 +43,51 @@ class Fluentd
|
||||
when %r|/var/log|
|
||||
:syslog
|
||||
else
|
||||
:regexp
|
||||
:grok
|
||||
end
|
||||
end
|
||||
|
||||
def extra_format_options
|
||||
self.class.known_formats[format.to_sym] || []
|
||||
end
|
||||
|
||||
def format_specific_conf
|
||||
return "" if %w(grok regexp).include?(format)
|
||||
|
||||
indent = " " * 2
|
||||
format_specific_conf = ""
|
||||
extra_format_options.each do |key|
|
||||
format_specific_conf << "#{indent}#{key} #{send(key)}\n"
|
||||
end
|
||||
format_specific_conf
|
||||
end
|
||||
|
||||
def certain_format_line
|
||||
case format
|
||||
when "grok"
|
||||
"format #{grok_str} # grok: #{grok_str}" # TODO: convert to regexp
|
||||
when "regexp"
|
||||
"format #{regexp}"
|
||||
else
|
||||
"format #{format}"
|
||||
end
|
||||
end
|
||||
|
||||
def to_conf
|
||||
<<-XML.strip_heredoc.gsub(/^[ ]+\n/m, "")
|
||||
<source>
|
||||
type tail
|
||||
path #{path}
|
||||
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}" : ""}
|
||||
</source>
|
||||
# NOTE: Using strip_heredoc makes more complex for format_specific_conf indent
|
||||
<<-XML.gsub(/^[ ]*\n/m, "")
|
||||
<source>
|
||||
type tail
|
||||
path #{path}
|
||||
tag #{tag}
|
||||
#{certain_format_line}
|
||||
#{format_specific_conf}
|
||||
|
||||
#{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}" : ""}
|
||||
</source>
|
||||
XML
|
||||
end
|
||||
end
|
||||
|
||||
@ -10,11 +10,16 @@
|
||||
= 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
|
||||
- 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"
|
||||
|
||||
@ -1,13 +1,35 @@
|
||||
<div id="in_tail_format" class="form-group" formatOptions="<%= formats.to_json %>" initialSelected="<%= initialSelected %>">
|
||||
<div class="form-group">
|
||||
<label>format(TODO: use Glok?)</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>
|
||||
<label>
|
||||
<input type="radio" v-model="formatType" value="bundled">bundled
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" v-model="formatType" value="regexp">regexp
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group" v-repeat="options">
|
||||
<label>{{ $value }} </label>
|
||||
<input type="text" name="setting[{{ $value }}]" />
|
||||
|
||||
<div v-if="formatType == 'bundled'">
|
||||
<div class="form-group">
|
||||
<label>format</label>
|
||||
<select name="setting[format]" v-model="format">
|
||||
<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 }}]" size="100%" />
|
||||
</div>
|
||||
<div v-if="format == 'grok'" class="well well-sm">
|
||||
TODO: grok reference
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="formatType == 'regexp'">
|
||||
<div class="form-group">
|
||||
<label>regexp</label>
|
||||
<input type="hidden" name="setting[format]" value="regexp" />
|
||||
<input type="text" name="setting[regexp]" v-model="regexp" size="100%" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="well well-sm">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user