diff --git a/app/controllers/fluentd/settings_controller.rb b/app/controllers/fluentd/settings_controller.rb
index dd45c9f..6ac3a1b 100644
--- a/app/controllers/fluentd/settings_controller.rb
+++ b/app/controllers/fluentd/settings_controller.rb
@@ -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
diff --git a/app/models/fluentd/setting.rb b/app/models/fluentd/setting.rb
index 0c1b718..083489f 100644
--- a/app/models/fluentd/setting.rb
+++ b/app/models/fluentd/setting.rb
@@ -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, "")
-