Class: Fluentd::Setting::InTail
- Inherits:
-
Object
- Object
- Fluentd::Setting::InTail
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/fluentd/setting/in_tail.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#path ⇒ Object
Returns the value of attribute path.
-
#pos_file ⇒ Object
Returns the value of attribute pos_file.
-
#read_from_head ⇒ Object
Returns the value of attribute read_from_head.
-
#refresh_interval ⇒ Object
Returns the value of attribute refresh_interval.
-
#regexp ⇒ Object
Returns the value of attribute regexp.
-
#rotate_wait ⇒ Object
Returns the value of attribute rotate_wait.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#time_format ⇒ Object
Returns the value of attribute time_format.
Class Method Summary collapse
-
.known_formats ⇒ Object
validates :format, presence: true.
Instance Method Summary collapse
- #certain_format_line ⇒ Object
- #extra_format_options ⇒ Object
- #format_specific_conf ⇒ Object
- #grok ⇒ Object
- #guess_format ⇒ Object
- #known_formats ⇒ Object
- #to_conf ⇒ Object
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
5 6 7 |
# File 'app/models/fluentd/setting/in_tail.rb', line 5 def format @format end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'app/models/fluentd/setting/in_tail.rb', line 5 def path @path end |
#pos_file ⇒ Object
Returns the value of attribute pos_file.
5 6 7 |
# File 'app/models/fluentd/setting/in_tail.rb', line 5 def pos_file @pos_file end |
#read_from_head ⇒ Object
Returns the value of attribute read_from_head.
5 6 7 |
# File 'app/models/fluentd/setting/in_tail.rb', line 5 def read_from_head @read_from_head end |
#refresh_interval ⇒ Object
Returns the value of attribute refresh_interval.
5 6 7 |
# File 'app/models/fluentd/setting/in_tail.rb', line 5 def refresh_interval @refresh_interval end |
#regexp ⇒ Object
Returns the value of attribute regexp.
5 6 7 |
# File 'app/models/fluentd/setting/in_tail.rb', line 5 def regexp @regexp end |
#rotate_wait ⇒ Object
Returns the value of attribute rotate_wait.
5 6 7 |
# File 'app/models/fluentd/setting/in_tail.rb', line 5 def rotate_wait @rotate_wait end |
#tag ⇒ Object
Returns the value of attribute tag.
5 6 7 |
# File 'app/models/fluentd/setting/in_tail.rb', line 5 def tag @tag end |
#time_format ⇒ Object
Returns the value of attribute time_format.
5 6 7 |
# File 'app/models/fluentd/setting/in_tail.rb', line 5 def time_format @time_format end |
Class Method Details
.known_formats ⇒ Object
validates :format, presence: true
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/fluentd/setting/in_tail.rb', line 11 def self.known_formats { :apache2 => [:time_format], :nginx => [:time_format], :syslog => [:time_format], :tsv => [:keys, :time_key], :csv => [:keys, :time_key], :ltsv => [:delimiter, :time_key], :json => [:time_key], :regexp => [:time_format], # TODO: Grok could generate Regexp including \d, \s, etc. fluentd config parser raise error with them for escape sequence check. # TBD How to handle Grok/Regexp later, just comment out for hide # :grok => [:grok_str], } end |
Instance Method Details
#certain_format_line ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/fluentd/setting/in_tail.rb', line 68 def certain_format_line case format when "grok" "format /#{grok.convert_to_regexp(grok_str).source.gsub("/", "\\/")}/ # grok: '#{grok_str}'" when "regexp" "format /#{regexp}/" else "format #{format}" end end |
#extra_format_options ⇒ Object
53 54 55 |
# File 'app/models/fluentd/setting/in_tail.rb', line 53 def self.class.known_formats[format.to_sym] || [] end |
#format_specific_conf ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/fluentd/setting/in_tail.rb', line 57 def format_specific_conf return "" if %w(grok regexp).include?(format) indent = " " * 2 format_specific_conf = "" .each do |key| format_specific_conf << "#{indent}#{key} #{send(key)}\n" end format_specific_conf end |
#grok ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'app/models/fluentd/setting/in_tail.rb', line 79 def grok @grok ||= begin grok = GrokConverter.new grok.load_patterns grok end end |
#guess_format ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/fluentd/setting/in_tail.rb', line 32 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 |
#known_formats ⇒ Object
28 29 30 |
# File 'app/models/fluentd/setting/in_tail.rb', line 28 def known_formats self.class.known_formats end |
#to_conf ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/fluentd/setting/in_tail.rb', line 88 def to_conf # 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 |