fluentd 0.12.43 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (253) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +6 -0
  3. data/.gitignore +2 -0
  4. data/.travis.yml +33 -21
  5. data/CONTRIBUTING.md +1 -0
  6. data/ChangeLog +1239 -0
  7. data/README.md +0 -25
  8. data/Rakefile +2 -1
  9. data/Vagrantfile +17 -0
  10. data/appveyor.yml +35 -0
  11. data/example/filter_stdout.conf +5 -5
  12. data/example/in_forward.conf +2 -2
  13. data/example/in_http.conf +2 -2
  14. data/example/in_out_forward.conf +17 -0
  15. data/example/in_syslog.conf +2 -2
  16. data/example/in_tail.conf +2 -2
  17. data/example/in_tcp.conf +2 -2
  18. data/example/in_udp.conf +2 -2
  19. data/example/out_copy.conf +4 -4
  20. data/example/out_file.conf +2 -2
  21. data/example/out_forward.conf +2 -2
  22. data/example/out_forward_buf_file.conf +23 -0
  23. data/example/v0_12_filter.conf +8 -8
  24. data/fluent.conf +29 -0
  25. data/fluentd.gemspec +18 -11
  26. data/lib/fluent/agent.rb +60 -58
  27. data/lib/fluent/command/cat.rb +1 -1
  28. data/lib/fluent/command/debug.rb +7 -5
  29. data/lib/fluent/command/fluentd.rb +97 -2
  30. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  31. data/lib/fluent/compat/filter.rb +50 -0
  32. data/lib/fluent/compat/formatter.rb +109 -0
  33. data/lib/fluent/compat/input.rb +50 -0
  34. data/lib/fluent/compat/output.rb +617 -0
  35. data/lib/fluent/compat/output_chain.rb +60 -0
  36. data/lib/fluent/compat/parser.rb +163 -0
  37. data/lib/fluent/compat/propagate_default.rb +62 -0
  38. data/lib/fluent/config.rb +23 -20
  39. data/lib/fluent/config/configure_proxy.rb +119 -70
  40. data/lib/fluent/config/dsl.rb +5 -18
  41. data/lib/fluent/config/element.rb +72 -8
  42. data/lib/fluent/config/error.rb +0 -3
  43. data/lib/fluent/config/literal_parser.rb +0 -2
  44. data/lib/fluent/config/parser.rb +4 -4
  45. data/lib/fluent/config/section.rb +39 -28
  46. data/lib/fluent/config/types.rb +2 -13
  47. data/lib/fluent/config/v1_parser.rb +1 -3
  48. data/lib/fluent/configurable.rb +48 -16
  49. data/lib/fluent/daemon.rb +15 -0
  50. data/lib/fluent/engine.rb +26 -52
  51. data/lib/fluent/env.rb +6 -4
  52. data/lib/fluent/event.rb +58 -11
  53. data/lib/fluent/event_router.rb +5 -5
  54. data/lib/fluent/filter.rb +2 -50
  55. data/lib/fluent/formatter.rb +4 -293
  56. data/lib/fluent/input.rb +2 -32
  57. data/lib/fluent/label.rb +2 -2
  58. data/lib/fluent/load.rb +3 -2
  59. data/lib/fluent/log.rb +107 -38
  60. data/lib/fluent/match.rb +0 -36
  61. data/lib/fluent/mixin.rb +117 -7
  62. data/lib/fluent/msgpack_factory.rb +62 -0
  63. data/lib/fluent/output.rb +7 -612
  64. data/lib/fluent/output_chain.rb +23 -0
  65. data/lib/fluent/parser.rb +4 -800
  66. data/lib/fluent/plugin.rb +100 -121
  67. data/lib/fluent/plugin/bare_output.rb +63 -0
  68. data/lib/fluent/plugin/base.rb +121 -0
  69. data/lib/fluent/plugin/buf_file.rb +101 -182
  70. data/lib/fluent/plugin/buf_memory.rb +9 -92
  71. data/lib/fluent/plugin/buffer.rb +473 -0
  72. data/lib/fluent/plugin/buffer/chunk.rb +135 -0
  73. data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
  74. data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
  75. data/lib/fluent/plugin/exec_util.rb +80 -75
  76. data/lib/fluent/plugin/file_util.rb +33 -28
  77. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  78. data/lib/fluent/plugin/filter.rb +51 -0
  79. data/lib/fluent/plugin/filter_grep.rb +13 -40
  80. data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
  81. data/lib/fluent/plugin/formatter.rb +93 -0
  82. data/lib/fluent/plugin/formatter_csv.rb +48 -0
  83. data/lib/fluent/plugin/formatter_hash.rb +32 -0
  84. data/lib/fluent/plugin/formatter_json.rb +47 -0
  85. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  86. data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
  87. data/lib/fluent/plugin/formatter_out_file.rb +45 -0
  88. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  89. data/lib/fluent/plugin/formatter_stdout.rb +39 -0
  90. data/lib/fluent/plugin/in_debug_agent.rb +4 -0
  91. data/lib/fluent/plugin/in_dummy.rb +22 -18
  92. data/lib/fluent/plugin/in_exec.rb +18 -8
  93. data/lib/fluent/plugin/in_forward.rb +36 -79
  94. data/lib/fluent/plugin/in_gc_stat.rb +4 -0
  95. data/lib/fluent/plugin/in_http.rb +21 -18
  96. data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
  97. data/lib/fluent/plugin/in_object_space.rb +6 -1
  98. data/lib/fluent/plugin/in_stream.rb +7 -3
  99. data/lib/fluent/plugin/in_syslog.rb +46 -95
  100. data/lib/fluent/plugin/in_tail.rb +58 -640
  101. data/lib/fluent/plugin/in_tcp.rb +8 -1
  102. data/lib/fluent/plugin/in_udp.rb +8 -18
  103. data/lib/fluent/plugin/input.rb +33 -0
  104. data/lib/fluent/plugin/multi_output.rb +95 -0
  105. data/lib/fluent/plugin/out_buffered_null.rb +59 -0
  106. data/lib/fluent/plugin/out_copy.rb +11 -7
  107. data/lib/fluent/plugin/out_exec.rb +15 -11
  108. data/lib/fluent/plugin/out_exec_filter.rb +18 -10
  109. data/lib/fluent/plugin/out_file.rb +34 -5
  110. data/lib/fluent/plugin/out_forward.rb +25 -19
  111. data/lib/fluent/plugin/out_null.rb +0 -14
  112. data/lib/fluent/plugin/out_roundrobin.rb +11 -7
  113. data/lib/fluent/plugin/out_stdout.rb +5 -7
  114. data/lib/fluent/plugin/out_stream.rb +3 -1
  115. data/lib/fluent/plugin/output.rb +979 -0
  116. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  117. data/lib/fluent/plugin/parser.rb +244 -0
  118. data/lib/fluent/plugin/parser_apache.rb +24 -0
  119. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  120. data/lib/fluent/plugin/parser_apache_error.rb +21 -0
  121. data/lib/fluent/plugin/parser_csv.rb +31 -0
  122. data/lib/fluent/plugin/parser_json.rb +79 -0
  123. data/lib/fluent/plugin/parser_ltsv.rb +50 -0
  124. data/lib/fluent/plugin/parser_multiline.rb +102 -0
  125. data/lib/fluent/plugin/parser_nginx.rb +24 -0
  126. data/lib/fluent/plugin/parser_none.rb +36 -0
  127. data/lib/fluent/plugin/parser_syslog.rb +82 -0
  128. data/lib/fluent/plugin/parser_tsv.rb +37 -0
  129. data/lib/fluent/plugin/socket_util.rb +119 -117
  130. data/lib/fluent/plugin/storage.rb +84 -0
  131. data/lib/fluent/plugin/storage_local.rb +116 -0
  132. data/lib/fluent/plugin/string_util.rb +16 -13
  133. data/lib/fluent/plugin_helper.rb +39 -0
  134. data/lib/fluent/plugin_helper/child_process.rb +298 -0
  135. data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
  136. data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
  137. data/lib/fluent/plugin_helper/event_loop.rb +118 -0
  138. data/lib/fluent/plugin_helper/retry_state.rb +177 -0
  139. data/lib/fluent/plugin_helper/storage.rb +308 -0
  140. data/lib/fluent/plugin_helper/thread.rb +147 -0
  141. data/lib/fluent/plugin_helper/timer.rb +85 -0
  142. data/lib/fluent/plugin_id.rb +63 -0
  143. data/lib/fluent/process.rb +21 -30
  144. data/lib/fluent/registry.rb +21 -9
  145. data/lib/fluent/root_agent.rb +115 -40
  146. data/lib/fluent/supervisor.rb +330 -320
  147. data/lib/fluent/system_config.rb +42 -18
  148. data/lib/fluent/test.rb +6 -1
  149. data/lib/fluent/test/base.rb +23 -3
  150. data/lib/fluent/test/driver/base.rb +247 -0
  151. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  152. data/lib/fluent/test/driver/filter.rb +35 -0
  153. data/lib/fluent/test/driver/input.rb +31 -0
  154. data/lib/fluent/test/driver/output.rb +78 -0
  155. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  156. data/lib/fluent/test/filter_test.rb +0 -1
  157. data/lib/fluent/test/formatter_test.rb +2 -1
  158. data/lib/fluent/test/input_test.rb +23 -17
  159. data/lib/fluent/test/output_test.rb +28 -39
  160. data/lib/fluent/test/parser_test.rb +1 -1
  161. data/lib/fluent/time.rb +104 -1
  162. data/lib/fluent/{status.rb → unique_id.rb} +15 -24
  163. data/lib/fluent/version.rb +1 -1
  164. data/lib/fluent/winsvc.rb +72 -0
  165. data/test/compat/test_calls_super.rb +164 -0
  166. data/test/config/test_config_parser.rb +83 -0
  167. data/test/config/test_configurable.rb +547 -274
  168. data/test/config/test_configure_proxy.rb +146 -29
  169. data/test/config/test_dsl.rb +3 -181
  170. data/test/config/test_element.rb +274 -0
  171. data/test/config/test_literal_parser.rb +1 -1
  172. data/test/config/test_section.rb +79 -7
  173. data/test/config/test_system_config.rb +21 -0
  174. data/test/config/test_types.rb +3 -26
  175. data/test/helper.rb +78 -8
  176. data/test/plugin/test_bare_output.rb +118 -0
  177. data/test/plugin/test_base.rb +75 -0
  178. data/test/plugin/test_buf_file.rb +420 -521
  179. data/test/plugin/test_buf_memory.rb +32 -194
  180. data/test/plugin/test_buffer.rb +981 -0
  181. data/test/plugin/test_buffer_chunk.rb +110 -0
  182. data/test/plugin/test_buffer_file_chunk.rb +770 -0
  183. data/test/plugin/test_buffer_memory_chunk.rb +265 -0
  184. data/test/plugin/test_filter.rb +255 -0
  185. data/test/plugin/test_filter_grep.rb +2 -73
  186. data/test/plugin/test_filter_record_transformer.rb +24 -68
  187. data/test/plugin/test_filter_stdout.rb +6 -6
  188. data/test/plugin/test_in_debug_agent.rb +2 -0
  189. data/test/plugin/test_in_dummy.rb +11 -17
  190. data/test/plugin/test_in_exec.rb +6 -25
  191. data/test/plugin/test_in_forward.rb +112 -151
  192. data/test/plugin/test_in_gc_stat.rb +2 -0
  193. data/test/plugin/test_in_http.rb +106 -157
  194. data/test/plugin/test_in_object_space.rb +21 -5
  195. data/test/plugin/test_in_stream.rb +14 -13
  196. data/test/plugin/test_in_syslog.rb +30 -275
  197. data/test/plugin/test_in_tail.rb +95 -282
  198. data/test/plugin/test_in_tcp.rb +14 -0
  199. data/test/plugin/test_in_udp.rb +21 -67
  200. data/test/plugin/test_input.rb +122 -0
  201. data/test/plugin/test_multi_output.rb +180 -0
  202. data/test/plugin/test_out_buffered_null.rb +79 -0
  203. data/test/plugin/test_out_copy.rb +15 -2
  204. data/test/plugin/test_out_exec.rb +75 -25
  205. data/test/plugin/test_out_exec_filter.rb +74 -8
  206. data/test/plugin/test_out_file.rb +61 -7
  207. data/test/plugin/test_out_forward.rb +92 -15
  208. data/test/plugin/test_out_roundrobin.rb +1 -0
  209. data/test/plugin/test_out_stdout.rb +22 -13
  210. data/test/plugin/test_out_stream.rb +18 -0
  211. data/test/plugin/test_output.rb +515 -0
  212. data/test/plugin/test_output_as_buffered.rb +1540 -0
  213. data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
  214. data/test/plugin/test_output_as_buffered_retries.rb +808 -0
  215. data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
  216. data/test/plugin/test_output_as_standard.rb +362 -0
  217. data/test/plugin/test_owned_by.rb +35 -0
  218. data/test/plugin/test_storage.rb +167 -0
  219. data/test/plugin/test_storage_local.rb +8 -0
  220. data/test/plugin_helper/test_child_process.rb +599 -0
  221. data/test/plugin_helper/test_compat_parameters.rb +175 -0
  222. data/test/plugin_helper/test_event_emitter.rb +51 -0
  223. data/test/plugin_helper/test_event_loop.rb +52 -0
  224. data/test/plugin_helper/test_retry_state.rb +399 -0
  225. data/test/plugin_helper/test_storage.rb +411 -0
  226. data/test/plugin_helper/test_thread.rb +164 -0
  227. data/test/plugin_helper/test_timer.rb +100 -0
  228. data/test/scripts/exec_script.rb +0 -6
  229. data/test/scripts/fluent/plugin/out_test.rb +3 -0
  230. data/test/test_config.rb +13 -4
  231. data/test/test_event.rb +24 -13
  232. data/test/test_event_router.rb +8 -7
  233. data/test/test_event_time.rb +187 -0
  234. data/test/test_formatter.rb +13 -51
  235. data/test/test_input.rb +1 -1
  236. data/test/test_log.rb +239 -16
  237. data/test/test_mixin.rb +1 -1
  238. data/test/test_output.rb +53 -66
  239. data/test/test_parser.rb +105 -323
  240. data/test/test_plugin_helper.rb +81 -0
  241. data/test/test_root_agent.rb +4 -52
  242. data/test/test_supervisor.rb +272 -0
  243. data/test/test_unique_id.rb +47 -0
  244. metadata +181 -55
  245. data/CHANGELOG.md +0 -710
  246. data/lib/fluent/buffer.rb +0 -365
  247. data/lib/fluent/plugin/filter_parser.rb +0 -107
  248. data/lib/fluent/plugin/in_status.rb +0 -76
  249. data/lib/fluent/test/helpers.rb +0 -86
  250. data/test/plugin/data/log/foo/bar2 +0 -0
  251. data/test/plugin/test_filter_parser.rb +0 -744
  252. data/test/plugin/test_in_status.rb +0 -38
  253. data/test/test_buffer.rb +0 -624
@@ -0,0 +1,42 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Fluent
18
+ module Plugin
19
+ module OwnedByMixin
20
+ def owner=(plugin)
21
+ @_owner = plugin
22
+
23
+ @_plugin_id = plugin.plugin_id
24
+ @_plugin_id_configured = plugin.plugin_id_configured?
25
+
26
+ @log = plugin.log
27
+ end
28
+
29
+ def owner
30
+ if instance_variable_defined?("@_owner")
31
+ @_owner
32
+ end
33
+ end
34
+
35
+ def log
36
+ if instance_variable_defined?("@log")
37
+ @log
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,244 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/plugin/base'
18
+ require 'fluent/plugin/owned_by_mixin'
19
+
20
+ require 'fluent/mixin' # for TypeConverter
21
+ require 'fluent/time'
22
+ require 'fluent/plugin/string_util'
23
+
24
+ require 'strptime'
25
+
26
+ module Fluent
27
+ module Plugin
28
+ class Parser < Base
29
+ include OwnedByMixin
30
+
31
+ class ParserError < StandardError; end
32
+
33
+ configured_in :parse
34
+
35
+ # SET false BEFORE CONFIGURE, to return nil when time not parsed
36
+ attr_accessor :estimate_current_event
37
+
38
+ config_param :keep_time_key, :bool, default: false
39
+
40
+ def initialize
41
+ super
42
+ @estimate_current_event = true
43
+ end
44
+
45
+ def parse(text)
46
+ raise NotImplementedError, "Implement this method in child class"
47
+ end
48
+
49
+ def call(*a, &b)
50
+ # Keep backward compatibility for existing plugins
51
+ # TODO: warn when deprecated
52
+ parse(*a, &b)
53
+ end
54
+
55
+ class TimeParser
56
+ def initialize(time_format)
57
+ @cache1_key = nil
58
+ @cache1_time = nil
59
+ @cache2_key = nil
60
+ @cache2_time = nil
61
+ @parser =
62
+ if time_format
63
+ begin
64
+ strptime = Strptime.new(time_format)
65
+ Proc.new { |value| Fluent::EventTime.from_time(strptime.exec(value)) }
66
+ rescue
67
+ Proc.new { |value| Fluent::EventTime.from_time(Time.strptime(value, time_format)) }
68
+ end
69
+ else
70
+ Proc.new { |value| Fluent::EventTime.parse(value) }
71
+ end
72
+ end
73
+
74
+ # TODO: new cache mechanism using format string
75
+ def parse(value)
76
+ unless value.is_a?(String)
77
+ raise ParserError, "value must be string: #{value}"
78
+ end
79
+
80
+ if @cache1_key == value
81
+ return @cache1_time
82
+ elsif @cache2_key == value
83
+ return @cache2_time
84
+ else
85
+ begin
86
+ time = @parser.call(value)
87
+ rescue => e
88
+ raise ParserError, "invalid time format: value = #{value}, error_class = #{e.class.name}, error = #{e.message}"
89
+ end
90
+ @cache1_key = @cache2_key
91
+ @cache1_time = @cache2_time
92
+ @cache2_key = value
93
+ @cache2_time = time
94
+ return time
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ class RegexpParser < Parser
101
+ include Fluent::TypeConverter
102
+
103
+ config_param :time_key, :string, default: 'time'
104
+ config_param :time_format, :string, default: nil
105
+
106
+ def initialize(regexp, conf={})
107
+ super()
108
+
109
+ unless conf.empty?
110
+ unless conf.is_a?(Config::Element)
111
+ conf = Config::Element.new('default_regexp_conf', '', conf, [])
112
+ end
113
+ configure(conf)
114
+ end
115
+
116
+ @regexp = regexp
117
+ @time_parser = TimeParser.new(@time_format)
118
+ @mutex = Mutex.new
119
+ end
120
+
121
+ def configure(conf)
122
+ super
123
+ @time_parser = TimeParser.new(@time_format)
124
+ end
125
+
126
+ def patterns
127
+ {'format' => @regexp, 'time_format' => @time_format}
128
+ end
129
+
130
+ def parse(text)
131
+ m = @regexp.match(text)
132
+ unless m
133
+ yield nil, nil
134
+ return
135
+ end
136
+
137
+ time = nil
138
+ record = {}
139
+
140
+ m.names.each do |name|
141
+ if value = m[name]
142
+ if name == @time_key
143
+ time = @mutex.synchronize { @time_parser.parse(value) }
144
+ if @keep_time_key
145
+ record[name] = if @type_converters.nil?
146
+ value
147
+ else
148
+ convert_type(name, value)
149
+ end
150
+ end
151
+ else
152
+ record[name] = if @type_converters.nil?
153
+ value
154
+ else
155
+ convert_type(name, value)
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ if @estimate_current_event
162
+ time ||= Fluent::EventTime.now
163
+ end
164
+
165
+ yield time, record
166
+ end
167
+ end
168
+
169
+ class ValuesParser < Parser
170
+ include Fluent::TypeConverter
171
+
172
+ config_param :keys, :array, default: []
173
+ config_param :time_key, :string, default: nil
174
+ config_param :time_format, :string, default: nil
175
+ config_param :null_value_pattern, :string, default: nil
176
+ config_param :null_empty_string, :bool, default: false
177
+
178
+ def configure(conf)
179
+ super
180
+
181
+ if @time_key && !@keys.include?(@time_key) && @estimate_current_event
182
+ raise ConfigError, "time_key (#{@time_key.inspect}) is not included in keys (#{@keys.inspect})"
183
+ end
184
+
185
+ if @time_format && !@time_key
186
+ raise ConfigError, "time_format parameter is ignored because time_key parameter is not set. at #{conf.inspect}"
187
+ end
188
+
189
+ @time_parser = TimeParser.new(@time_format)
190
+
191
+ if @null_value_pattern
192
+ @null_value_pattern = Regexp.new(@null_value_pattern)
193
+ end
194
+
195
+ @mutex = Mutex.new
196
+ end
197
+
198
+ def values_map(values)
199
+ record = Hash[keys.zip(values.map { |value| convert_value_to_nil(value) })]
200
+
201
+ if @time_key
202
+ value = @keep_time_key ? record[@time_key] : record.delete(@time_key)
203
+ time = if value.nil?
204
+ if @estimate_current_event
205
+ Fluent::EventTime.now
206
+ else
207
+ nil
208
+ end
209
+ else
210
+ @mutex.synchronize { @time_parser.parse(value) }
211
+ end
212
+ elsif @estimate_current_event
213
+ time = Fluent::EventTime.now
214
+ else
215
+ time = nil
216
+ end
217
+
218
+ convert_field_type!(record) if @type_converters
219
+
220
+ return time, record
221
+ end
222
+
223
+ private
224
+
225
+ def convert_field_type!(record)
226
+ @type_converters.each_key { |key|
227
+ if value = record[key]
228
+ record[key] = convert_type(key, value)
229
+ end
230
+ }
231
+ end
232
+
233
+ def convert_value_to_nil(value)
234
+ if value and @null_empty_string
235
+ value = (value == '') ? nil : value
236
+ end
237
+ if value and @null_value_pattern
238
+ value = ::Fluent::StringUtil.match_regexp(@null_value_pattern, value) ? nil : value
239
+ end
240
+ value
241
+ end
242
+ end
243
+ end
244
+ end
@@ -0,0 +1,24 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/plugin/parser'
18
+
19
+ Fluent::Plugin.register_parser('apache', Proc.new{
20
+ Fluent::Plugin::RegexpParser.new(
21
+ /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/,
22
+ {'time_format'=>"%d/%b/%Y:%H:%M:%S %z"}
23
+ )
24
+ })
@@ -0,0 +1,84 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/plugin/parser'
18
+
19
+ module Fluent
20
+ module Plugin
21
+ class Apache2Parser < Parser
22
+ Plugin.register_parser('apache2', self)
23
+
24
+ REGEXP = /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/
25
+ TIME_FORMAT = "%d/%b/%Y:%H:%M:%S %z"
26
+
27
+ def initialize
28
+ super
29
+ @time_parser = TimeParser.new(TIME_FORMAT)
30
+ @mutex = Mutex.new
31
+ end
32
+
33
+ def patterns
34
+ {'format' => REGEXP, 'time_format' => TIME_FORMAT}
35
+ end
36
+
37
+ def parse(text)
38
+ m = REGEXP.match(text)
39
+ unless m
40
+ yield nil, nil
41
+ return
42
+ end
43
+
44
+ host = m['host']
45
+ host = (host == '-') ? nil : host
46
+
47
+ user = m['user']
48
+ user = (user == '-') ? nil : user
49
+
50
+ time = m['time']
51
+ time = @mutex.synchronize { @time_parser.parse(time) }
52
+
53
+ method = m['method']
54
+ path = m['path']
55
+
56
+ code = m['code'].to_i
57
+ code = nil if code == 0
58
+
59
+ size = m['size']
60
+ size = (size == '-') ? nil : size.to_i
61
+
62
+ referer = m['referer']
63
+ referer = (referer == '-') ? nil : referer
64
+
65
+ agent = m['agent']
66
+ agent = (agent == '-') ? nil : agent
67
+
68
+ record = {
69
+ "host" => host,
70
+ "user" => user,
71
+ "method" => method,
72
+ "path" => path,
73
+ "code" => code,
74
+ "size" => size,
75
+ "referer" => referer,
76
+ "agent" => agent,
77
+ }
78
+ record["time"] = m['time'] if @keep_time_key
79
+
80
+ yield time, record
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,21 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/plugin/parser'
18
+
19
+ Fluent::Plugin.register_parser('apache_error', Proc.new {
20
+ Fluent::Plugin::RegexpParser.new(/^\[[^ ]* (?<time>[^\]]*)\] \[(?<level>[^\]]*)\](?: \[pid (?<pid>[^\]]*)\])?( \[client (?<client>[^\]]*)\])? (?<message>.*)$/)
21
+ })
@@ -0,0 +1,31 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/plugin/parser'
18
+
19
+ require 'csv'
20
+
21
+ module Fluent
22
+ module Plugin
23
+ class CSVParser < ValuesParser
24
+ Plugin.register_parser('csv', self)
25
+
26
+ def parse(text)
27
+ yield values_map(CSV.parse_line(text))
28
+ end
29
+ end
30
+ end
31
+ end