fluentd 0.14.17-x64-mingw32 → 1.3.1-x64-mingw32

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 (159) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +16 -5
  3. data/ADOPTERS.md +5 -0
  4. data/{ChangeLog → CHANGELOG.md} +495 -6
  5. data/CONTRIBUTING.md +5 -2
  6. data/GOVERNANCE.md +55 -0
  7. data/LICENSE +202 -0
  8. data/MAINTAINERS.md +7 -5
  9. data/README.md +17 -10
  10. data/bin/fluent-ca-generate +6 -0
  11. data/example/counter.conf +18 -0
  12. data/example/secondary_file.conf +3 -2
  13. data/fluentd.gemspec +3 -3
  14. data/lib/fluent/agent.rb +1 -1
  15. data/lib/fluent/command/binlog_reader.rb +11 -2
  16. data/lib/fluent/command/ca_generate.rb +181 -0
  17. data/lib/fluent/command/cat.rb +28 -15
  18. data/lib/fluent/command/debug.rb +4 -4
  19. data/lib/fluent/command/fluentd.rb +2 -2
  20. data/lib/fluent/command/plugin_config_formatter.rb +24 -2
  21. data/lib/fluent/command/plugin_generator.rb +26 -8
  22. data/lib/fluent/config/configure_proxy.rb +7 -1
  23. data/lib/fluent/config/dsl.rb +8 -5
  24. data/lib/fluent/config/element.rb +5 -0
  25. data/lib/fluent/config/literal_parser.rb +7 -1
  26. data/lib/fluent/config/types.rb +28 -2
  27. data/lib/fluent/config/v1_parser.rb +1 -2
  28. data/lib/fluent/configurable.rb +1 -0
  29. data/lib/fluent/counter.rb +23 -0
  30. data/lib/fluent/counter/base_socket.rb +46 -0
  31. data/lib/fluent/counter/client.rb +297 -0
  32. data/lib/fluent/counter/error.rb +86 -0
  33. data/lib/fluent/counter/mutex_hash.rb +163 -0
  34. data/lib/fluent/counter/server.rb +273 -0
  35. data/lib/fluent/counter/store.rb +205 -0
  36. data/lib/fluent/counter/validator.rb +145 -0
  37. data/lib/fluent/env.rb +1 -0
  38. data/lib/fluent/event_router.rb +1 -1
  39. data/lib/fluent/log.rb +119 -29
  40. data/lib/fluent/plugin/base.rb +12 -0
  41. data/lib/fluent/plugin/buf_file.rb +20 -16
  42. data/lib/fluent/plugin/buffer.rb +130 -32
  43. data/lib/fluent/plugin/buffer/file_chunk.rb +23 -4
  44. data/lib/fluent/plugin/compressable.rb +1 -1
  45. data/lib/fluent/plugin/filter_grep.rb +135 -21
  46. data/lib/fluent/plugin/filter_parser.rb +13 -2
  47. data/lib/fluent/plugin/filter_record_transformer.rb +16 -14
  48. data/lib/fluent/plugin/formatter_stdout.rb +3 -2
  49. data/lib/fluent/plugin/formatter_tsv.rb +5 -1
  50. data/lib/fluent/plugin/in_debug_agent.rb +8 -1
  51. data/lib/fluent/plugin/in_forward.rb +1 -1
  52. data/lib/fluent/plugin/in_http.rb +84 -3
  53. data/lib/fluent/plugin/in_monitor_agent.rb +7 -1
  54. data/lib/fluent/plugin/in_syslog.rb +31 -10
  55. data/lib/fluent/plugin/in_tail.rb +142 -53
  56. data/lib/fluent/plugin/in_tcp.rb +5 -6
  57. data/lib/fluent/plugin/in_udp.rb +6 -2
  58. data/lib/fluent/plugin/in_unix.rb +1 -1
  59. data/lib/fluent/plugin/multi_output.rb +1 -0
  60. data/lib/fluent/plugin/out_copy.rb +25 -2
  61. data/lib/fluent/plugin/out_file.rb +26 -7
  62. data/lib/fluent/plugin/out_forward.rb +81 -42
  63. data/lib/fluent/plugin/out_secondary_file.rb +2 -2
  64. data/lib/fluent/plugin/out_stdout.rb +0 -1
  65. data/lib/fluent/plugin/out_stream.rb +1 -1
  66. data/lib/fluent/plugin/output.rb +221 -57
  67. data/lib/fluent/plugin/parser_apache.rb +1 -1
  68. data/lib/fluent/plugin/parser_apache2.rb +5 -1
  69. data/lib/fluent/plugin/parser_apache_error.rb +1 -1
  70. data/lib/fluent/plugin/parser_json.rb +10 -3
  71. data/lib/fluent/plugin/parser_ltsv.rb +7 -0
  72. data/lib/fluent/plugin/parser_multiline.rb +2 -1
  73. data/lib/fluent/plugin/parser_nginx.rb +1 -1
  74. data/lib/fluent/plugin/parser_none.rb +1 -0
  75. data/lib/fluent/plugin/parser_regexp.rb +15 -14
  76. data/lib/fluent/plugin/parser_syslog.rb +9 -5
  77. data/lib/fluent/plugin_helper.rb +2 -0
  78. data/lib/fluent/plugin_helper/cert_option.rb +28 -9
  79. data/lib/fluent/plugin_helper/compat_parameters.rb +3 -1
  80. data/lib/fluent/plugin_helper/counter.rb +51 -0
  81. data/lib/fluent/plugin_helper/event_loop.rb +9 -0
  82. data/lib/fluent/plugin_helper/record_accessor.rb +210 -0
  83. data/lib/fluent/plugin_helper/retry_state.rb +15 -7
  84. data/lib/fluent/plugin_helper/server.rb +87 -25
  85. data/lib/fluent/plugin_helper/socket_option.rb +5 -2
  86. data/lib/fluent/plugin_helper/timer.rb +8 -7
  87. data/lib/fluent/root_agent.rb +18 -9
  88. data/lib/fluent/supervisor.rb +63 -23
  89. data/lib/fluent/system_config.rb +30 -2
  90. data/lib/fluent/test/helpers.rb +1 -1
  91. data/lib/fluent/time.rb +15 -7
  92. data/lib/fluent/timezone.rb +26 -2
  93. data/lib/fluent/version.rb +1 -1
  94. data/templates/new_gem/README.md.erb +2 -2
  95. data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +1 -1
  96. data/templates/new_gem/lib/fluent/plugin/input.rb.erb +1 -1
  97. data/templates/new_gem/lib/fluent/plugin/output.rb.erb +1 -1
  98. data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +4 -4
  99. data/test/command/test_ca_generate.rb +70 -0
  100. data/test/command/test_fluentd.rb +2 -2
  101. data/test/command/test_plugin_config_formatter.rb +8 -7
  102. data/test/command/test_plugin_generator.rb +65 -39
  103. data/test/config/test_config_parser.rb +7 -2
  104. data/test/config/test_configurable.rb +7 -2
  105. data/test/config/test_configure_proxy.rb +41 -3
  106. data/test/config/test_dsl.rb +10 -10
  107. data/test/config/test_element.rb +10 -0
  108. data/test/config/test_literal_parser.rb +8 -0
  109. data/test/config/test_plugin_configuration.rb +56 -0
  110. data/test/config/test_system_config.rb +19 -1
  111. data/test/config/test_types.rb +37 -0
  112. data/test/counter/test_client.rb +559 -0
  113. data/test/counter/test_error.rb +44 -0
  114. data/test/counter/test_mutex_hash.rb +179 -0
  115. data/test/counter/test_server.rb +589 -0
  116. data/test/counter/test_store.rb +258 -0
  117. data/test/counter/test_validator.rb +137 -0
  118. data/test/plugin/test_buf_file.rb +124 -0
  119. data/test/plugin/test_buffer.rb +3 -2
  120. data/test/plugin/test_filter_grep.rb +580 -2
  121. data/test/plugin/test_filter_parser.rb +33 -2
  122. data/test/plugin/test_filter_record_transformer.rb +22 -1
  123. data/test/plugin/test_formatter_ltsv.rb +3 -0
  124. data/test/plugin/test_formatter_tsv.rb +68 -0
  125. data/test/plugin/test_in_debug_agent.rb +21 -0
  126. data/test/plugin/test_in_exec.rb +3 -5
  127. data/test/plugin/test_in_http.rb +178 -0
  128. data/test/plugin/test_in_monitor_agent.rb +1 -1
  129. data/test/plugin/test_in_syslog.rb +64 -0
  130. data/test/plugin/test_in_tail.rb +116 -6
  131. data/test/plugin/test_in_tcp.rb +21 -0
  132. data/test/plugin/test_in_udp.rb +78 -0
  133. data/test/plugin/test_metadata.rb +89 -0
  134. data/test/plugin/test_out_copy.rb +31 -0
  135. data/test/plugin/test_out_file.rb +108 -2
  136. data/test/plugin/test_out_forward.rb +195 -2
  137. data/test/plugin/test_out_secondary_file.rb +14 -0
  138. data/test/plugin/test_output.rb +159 -45
  139. data/test/plugin/test_output_as_buffered.rb +19 -0
  140. data/test/plugin/test_output_as_buffered_backup.rb +307 -0
  141. data/test/plugin/test_output_as_buffered_retries.rb +70 -0
  142. data/test/plugin/test_output_as_buffered_secondary.rb +1 -1
  143. data/test/plugin/test_parser_apache2.rb +1 -0
  144. data/test/plugin/test_parser_labeled_tsv.rb +17 -0
  145. data/test/plugin/test_parser_nginx.rb +40 -0
  146. data/test/plugin/test_parser_regexp.rb +6 -7
  147. data/test/plugin/test_parser_syslog.rb +155 -5
  148. data/test/plugin_helper/test_child_process.rb +4 -4
  149. data/test/plugin_helper/test_compat_parameters.rb +22 -0
  150. data/test/plugin_helper/test_record_accessor.rb +197 -0
  151. data/test/plugin_helper/test_retry_state.rb +20 -0
  152. data/test/plugin_helper/test_server.rb +30 -2
  153. data/test/test_config.rb +3 -3
  154. data/test/test_configdsl.rb +2 -2
  155. data/test/test_log.rb +51 -1
  156. data/test/test_root_agent.rb +33 -0
  157. data/test/test_supervisor.rb +105 -0
  158. metadata +68 -8
  159. data/COPYING +0 -14
@@ -0,0 +1,181 @@
1
+ require 'openssl'
2
+ require 'optparse'
3
+ require 'fileutils'
4
+ require 'fluent/version'
5
+
6
+ module Fluent
7
+ class CaGenerate
8
+ DEFAULT_OPTIONS = {
9
+ private_key_length: 2048,
10
+ cert_country: 'US',
11
+ cert_state: 'CA',
12
+ cert_locality: 'Mountain View',
13
+ cert_common_name: 'Fluentd Forward CA',
14
+ }
15
+ HELP_TEXT = <<HELP
16
+ Usage: fluent-ca-generate DIR_PATH PRIVATE_KEY_PASSPHRASE [--country COUNTRY] [--state STATE] [--locality LOCALITY] [--common-name COMMON_NAME]
17
+ HELP
18
+
19
+ def initialize(argv = ARGV)
20
+ @argv = argv
21
+ @options = {}
22
+ @opt_parser = OptionParser.new
23
+ configure_option_parser
24
+ @options.merge!(DEFAULT_OPTIONS)
25
+ parse_options!
26
+ end
27
+
28
+ def usage(msg = nil)
29
+ puts HELP_TEXT
30
+ puts "Error: #{msg}" if msg
31
+ exit 1
32
+ end
33
+
34
+ def call
35
+ ca_dir, passphrase, = @argv[0..1]
36
+
37
+ unless ca_dir && passphrase
38
+ puts "#{HELP_TEXT}"
39
+ puts ''
40
+ exit 1
41
+ end
42
+
43
+ FileUtils.mkdir_p(ca_dir)
44
+
45
+ cert, key = Fluent::CaGenerate.generate_ca_pair(@options)
46
+
47
+ key_data = key.export(OpenSSL::Cipher.new('aes256'), passphrase)
48
+ File.open(File.join(ca_dir, 'ca_key.pem'), 'w') do |file|
49
+ file.write key_data
50
+ end
51
+ File.open(File.join(ca_dir, 'ca_cert.pem'), 'w') do |file|
52
+ file.write cert.to_pem
53
+ end
54
+
55
+ puts "successfully generated: ca_key.pem, ca_cert.pem"
56
+ puts "copy and use ca_cert.pem to client(out_forward)"
57
+ end
58
+
59
+ def self.certificates_from_file(path)
60
+ data = File.read(path)
61
+ pattern = Regexp.compile('-+BEGIN CERTIFICATE-+\n(?:[^-]*\n)+-+END CERTIFICATE-+\n', Regexp::MULTILINE)
62
+ list = []
63
+ data.scan(pattern){|match| list << OpenSSL::X509::Certificate.new(match)}
64
+ list
65
+ end
66
+
67
+ def self.generate_ca_pair(opts={})
68
+ key = OpenSSL::PKey::RSA.generate(opts[:private_key_length])
69
+
70
+ issuer = subject = OpenSSL::X509::Name.new
71
+ subject.add_entry('C', opts[:cert_country])
72
+ subject.add_entry('ST', opts[:cert_state])
73
+ subject.add_entry('L', opts[:cert_locality])
74
+ subject.add_entry('CN', opts[:cert_common_name])
75
+
76
+ digest = OpenSSL::Digest::SHA256.new
77
+
78
+ cert = OpenSSL::X509::Certificate.new
79
+ cert.not_before = Time.at(0)
80
+ cert.not_after = Time.now + 5 * 365 * 86400 # 5 years after
81
+ cert.public_key = key
82
+ cert.serial = 1
83
+ cert.issuer = issuer
84
+ cert.subject = subject
85
+ cert.add_extension OpenSSL::X509::Extension.new('basicConstraints', OpenSSL::ASN1.Sequence([OpenSSL::ASN1::Boolean(true)]))
86
+ cert.sign(key, digest)
87
+
88
+ return cert, key
89
+ end
90
+
91
+ def self.generate_server_pair(opts={})
92
+ key = OpenSSL::PKey::RSA.generate(opts[:private_key_length])
93
+
94
+ ca_key = OpenSSL::PKey::RSA.new(File.read(opts[:ca_key_path]), opts[:ca_key_passphrase])
95
+ ca_cert = OpenSSL::X509::Certificate.new(File.read(opts[:ca_cert_path]))
96
+ issuer = ca_cert.issuer
97
+
98
+ subject = OpenSSL::X509::Name.new
99
+ subject.add_entry('C', opts[:country])
100
+ subject.add_entry('ST', opts[:state])
101
+ subject.add_entry('L', opts[:locality])
102
+ subject.add_entry('CN', opts[:common_name])
103
+
104
+ digest = OpenSSL::Digest::SHA256.new
105
+
106
+ cert = OpenSSL::X509::Certificate.new
107
+ cert.not_before = Time.at(0)
108
+ cert.not_after = Time.now + 5 * 365 * 86400 # 5 years after
109
+ cert.public_key = key
110
+ cert.serial = 2
111
+ cert.issuer = issuer
112
+ cert.subject = subject
113
+
114
+ cert.add_extension OpenSSL::X509::Extension.new('basicConstraints', OpenSSL::ASN1.Sequence([OpenSSL::ASN1::Boolean(false)]))
115
+ cert.add_extension OpenSSL::X509::Extension.new('nsCertType', 'server')
116
+
117
+ cert.sign ca_key, digest
118
+
119
+ return cert, key
120
+ end
121
+
122
+ def self.generate_self_signed_server_pair(opts={})
123
+ key = OpenSSL::PKey::RSA.generate(opts[:private_key_length])
124
+
125
+ issuer = subject = OpenSSL::X509::Name.new
126
+ subject.add_entry('C', opts[:country])
127
+ subject.add_entry('ST', opts[:state])
128
+ subject.add_entry('L', opts[:locality])
129
+ subject.add_entry('CN', opts[:common_name])
130
+
131
+ digest = OpenSSL::Digest::SHA256.new
132
+
133
+ cert = OpenSSL::X509::Certificate.new
134
+ cert.not_before = Time.at(0)
135
+ cert.not_after = Time.now + 5 * 365 * 86400 # 5 years after
136
+ cert.public_key = key
137
+ cert.serial = 1
138
+ cert.issuer = issuer
139
+ cert.subject = subject
140
+ cert.sign(key, digest)
141
+
142
+ return cert, key
143
+ end
144
+
145
+ private
146
+
147
+ def configure_option_parser
148
+ @opt_parser.banner = HELP_TEXT
149
+ @opt_parser.version = Fluent::VERSION
150
+
151
+ @opt_parser.on('--key-length [KEY_LENGTH]',
152
+ "configure key length. (default: #{DEFAULT_OPTIONS[:private_key_length]})") do |v|
153
+ @options[:private_key_length] = v.to_i
154
+ end
155
+
156
+ @opt_parser.on('--country [COUNTRY]',
157
+ "configure country. (default: #{DEFAULT_OPTIONS[:cert_country]})") do |v|
158
+ @options[:cert_country] = v.upcase
159
+ end
160
+
161
+ @opt_parser.on('--state [STATE]',
162
+ "configure state. (default: #{DEFAULT_OPTIONS[:cert_state]})") do |v|
163
+ @options[:cert_state] = v
164
+ end
165
+
166
+ @opt_parser.on('--locality [LOCALITY]',
167
+ "configure locality. (default: #{DEFAULT_OPTIONS[:cert_locality]})") do |v|
168
+ @options[:cert_locality] = v
169
+ end
170
+
171
+ @opt_parser.on('--common-name [COMMON_NAME]',
172
+ "configure common name (default: #{DEFAULT_OPTIONS[:cert_common_name]})") do |v|
173
+ @options[:cert_common_name] = v
174
+ end
175
+ end
176
+
177
+ def parse_options!
178
+ @opt_parser.parse!(@argv)
179
+ end
180
+ end
181
+ end
@@ -18,10 +18,12 @@ require 'optparse'
18
18
  require 'fluent/env'
19
19
  require 'fluent/time'
20
20
  require 'fluent/msgpack_factory'
21
+ require 'fluent/version'
21
22
 
22
23
  op = OptionParser.new
23
24
 
24
25
  op.banner += " <tag>"
26
+ op.version = Fluent::VERSION
25
27
 
26
28
  port = 24224
27
29
  host = '127.0.0.1'
@@ -32,6 +34,7 @@ config_path = Fluent::DEFAULT_CONFIG_PATH
32
34
  format = 'json'
33
35
  message_key = 'message'
34
36
  time_as_integer = false
37
+ retry_limit = 5
35
38
 
36
39
  op.on('-p', '--port PORT', "fluent tcp port (default: #{port})", Integer) {|i|
37
40
  port = i
@@ -73,7 +76,11 @@ op.on('--time-as-integer', "Send time as integer for v0.12 or earlier", TrueClas
73
76
  time_as_integer = true
74
77
  }
75
78
 
76
- (class << self; self; end).module_eval do
79
+ op.on('--retry-limit N', "Specify the number of retry limit (default: #{retry_limit})", Integer) {|n|
80
+ retry_limit = n
81
+ }
82
+
83
+ singleton_class.module_eval do
77
84
  define_method(:usage) do |msg|
78
85
  puts op.to_s
79
86
  puts "error: #{msg}" if msg
@@ -105,6 +112,8 @@ require 'msgpack'
105
112
  class Writer
106
113
  include MonitorMixin
107
114
 
115
+ RetryLimitError = Class.new(StandardError)
116
+
108
117
  class TimerThread
109
118
  def initialize(writer)
110
119
  @writer = writer
@@ -128,7 +137,7 @@ class Writer
128
137
  end
129
138
  end
130
139
 
131
- def initialize(tag, connector, time_as_integer: false)
140
+ def initialize(tag, connector, time_as_integer: false, retry_limit: 5)
132
141
  @tag = tag
133
142
  @connector = connector
134
143
  @socket = false
@@ -140,7 +149,7 @@ class Writer
140
149
  @pending = []
141
150
  @pending_limit = 1024 # TODO
142
151
  @retry_wait = 1
143
- @retry_limit = 5 # TODO
152
+ @retry_limit = retry_limit
144
153
  @time_as_integer = time_as_integer
145
154
 
146
155
  super()
@@ -234,21 +243,24 @@ class Writer
234
243
  end
235
244
 
236
245
  def try_connect
237
- now = Time.now.to_i
238
-
239
- unless @error_history.empty?
240
- # wait before re-connecting
241
- wait = @retry_wait * (2 ** (@error_history.size-1))
242
- if now <= @socket_time + wait
243
- return false
246
+ begin
247
+ now = Time.now.to_i
248
+
249
+ unless @error_history.empty?
250
+ # wait before re-connecting
251
+ wait = 1 #@retry_wait * (2 ** (@error_history.size-1))
252
+ if now <= @socket_time + wait
253
+ sleep(wait)
254
+ try_connect
255
+ end
244
256
  end
245
- end
246
257
 
247
- begin
248
258
  @socket = @connector.call
249
259
  @error_history.clear
250
260
  return true
251
261
 
262
+ rescue RetryLimitError => ex
263
+ raise ex
252
264
  rescue
253
265
  $stderr.puts "connect failed: #{$!}"
254
266
  @error_history << $!
@@ -261,9 +273,10 @@ class Writer
261
273
  }
262
274
  @pending.clear
263
275
  @error_history.clear
276
+ raise RetryLimitError, "exceed retry limit"
277
+ else
278
+ retry
264
279
  end
265
-
266
- return false
267
280
  end
268
281
  end
269
282
 
@@ -283,7 +296,7 @@ else
283
296
  }
284
297
  end
285
298
 
286
- w = Writer.new(tag, connector, time_as_integer: time_as_integer)
299
+ w = Writer.new(tag, connector, time_as_integer: time_as_integer, retry_limit: retry_limit)
287
300
  w.start
288
301
 
289
302
  case format
@@ -34,7 +34,7 @@ op.on('-u', '--unix PATH', "use unix socket instead of tcp") {|b|
34
34
  unix = b
35
35
  }
36
36
 
37
- (class << self; self; end).module_eval do
37
+ singleton_class.module_eval do
38
38
  define_method(:usage) do |msg|
39
39
  puts op.to_s
40
40
  puts "error: #{msg}" if msg
@@ -91,9 +91,9 @@ include Fluent
91
91
 
92
92
  puts "Connected to #{uri}."
93
93
  puts "Usage:"
94
- puts " Fluent::Engine.match('some.tag').output : get an output plugin instance"
95
- puts " Fluent::Engine.sources[i] : get input plugin instances"
96
- puts " Fluent::Plugin.load_plugin(type,name) : load plugin class (use this if you get DRb::DRbUnknown)"
94
+ puts " Fluent::Engine.root_agent.event_router.match('some.tag') : get an output plugin instance"
95
+ puts " Fluent::Engine.root_agent.inputs[i] : get input plugin instances"
96
+ puts " Fluent::Plugin::OUTPUT_REGISTRY.lookup(name) : load output plugin class (use this if you get DRb::DRbUnknown)"
97
97
  puts ""
98
98
 
99
99
  Encoding.default_internal = nil if Encoding.respond_to?(:default_internal)
@@ -177,7 +177,7 @@ if Fluent.windows?
177
177
  opts[:regwinsvcautostart] = s
178
178
  }
179
179
 
180
- op.on('--reg-winsvc-fluentdopt OPTION', "specify fluentd option paramters for Windows Service. (Windows only)") {|s|
180
+ op.on('--reg-winsvc-fluentdopt OPTION', "specify fluentd option parameters for Windows Service. (Windows only)") {|s|
181
181
  opts[:fluentdopt] = s
182
182
  }
183
183
 
@@ -195,7 +195,7 @@ if Fluent.windows?
195
195
  end
196
196
 
197
197
 
198
- (class << self; self; end).module_eval do
198
+ singleton_class.module_eval do
199
199
  define_method(:usage) do |msg|
200
200
  puts op.to_s
201
201
  puts "error: #{msg}" if msg
@@ -22,6 +22,7 @@ require "fluent/env"
22
22
  require "fluent/engine"
23
23
  require "fluent/system_config"
24
24
  require "fluent/config/element"
25
+ require 'fluent/version'
25
26
 
26
27
  class FluentPluginConfigFormatter
27
28
 
@@ -31,6 +32,8 @@ class FluentPluginConfigFormatter
31
32
  "buffer", "parser", "formatter", "storage"
32
33
  ]
33
34
 
35
+ DOCS_BASE_URL = "https://docs.fluentd.org/v1.0/articles/"
36
+
34
37
  def initialize(argv = ARGV)
35
38
  @argv = argv
36
39
 
@@ -134,7 +137,7 @@ class FluentPluginConfigFormatter
134
137
  if plugin_helpers && !plugin_helpers.empty?
135
138
  dumped = "## Plugin helpers\n\n"
136
139
  plugin_helpers.each do |plugin_helper|
137
- dumped << "* #{plugin_helper}\n"
140
+ dumped << "* #{plugin_helper_markdown_link(plugin_helper)}\n"
138
141
  end
139
142
  dumped << "\n"
140
143
  end
@@ -143,7 +146,7 @@ class FluentPluginConfigFormatter
143
146
  dumped << "## #{name}\n\n"
144
147
  dumped << dump_section_markdown(config)
145
148
  else
146
- dumped << "* See also: #{name}\n\n"
149
+ dumped << "* See also: #{plugin_overview_markdown_link(name)}\n\n"
147
150
  end
148
151
  end
149
152
  dumped
@@ -181,6 +184,24 @@ class FluentPluginConfigFormatter
181
184
  end
182
185
  end
183
186
 
187
+ def plugin_helper_url(plugin_helper)
188
+ "#{DOCS_BASE_URL}api-plugin-helper-#{plugin_helper}"
189
+ end
190
+
191
+ def plugin_helper_markdown_link(plugin_helper)
192
+ "[#{plugin_helper}](#{plugin_helper_url(plugin_helper)})"
193
+ end
194
+
195
+ def plugin_overview_url(class_name)
196
+ plugin_type = class_name.slice(/::(\w+)\z/, 1).downcase
197
+ "#{DOCS_BASE_URL}#{plugin_type}-plugin-overview"
198
+ end
199
+
200
+ def plugin_overview_markdown_link(class_name)
201
+ plugin_type = class_name.slice(/::(\w+)\z/, 1)
202
+ "[#{plugin_type} Plugin Overview](#{plugin_overview_url(class_name)})"
203
+ end
204
+
184
205
  def usage(message = nil)
185
206
  puts @parser.to_s
186
207
  puts
@@ -190,6 +211,7 @@ class FluentPluginConfigFormatter
190
211
 
191
212
  def prepare_option_parser
192
213
  @parser = OptionParser.new
214
+ @parser.version = Fluent::VERSION
193
215
  @parser.banner = <<BANNER
194
216
  Usage: #{$0} [options] <type> <name>
195
217
 
@@ -21,6 +21,7 @@ require "erb"
21
21
  require "open-uri"
22
22
 
23
23
  require "fluent/registry"
24
+ require 'fluent/version'
24
25
 
25
26
  class FluentPluginGenerator
26
27
  attr_reader :type, :name
@@ -91,6 +92,7 @@ class FluentPluginGenerator
91
92
 
92
93
  def prepare_parser
93
94
  @parser = OptionParser.new
95
+ @parser.version = Fluent::VERSION
94
96
  @parser.banner = <<BANNER
95
97
  Usage: fluent-plugin-generate [options] <type> <name>
96
98
 
@@ -137,32 +139,36 @@ BANNER
137
139
  end
138
140
 
139
141
  def gem_name
140
- "fluent-plugin-#{name}"
142
+ "fluent-plugin-#{dash_name}"
143
+ end
144
+
145
+ def plugin_name
146
+ underscore_name
141
147
  end
142
148
 
143
149
  def class_name
144
- "#{name.capitalize}#{type.capitalize}"
150
+ "#{capitalized_name}#{type.capitalize}"
145
151
  end
146
152
 
147
153
  def plugin_filename
148
154
  case type
149
155
  when "input"
150
- "in_#{name}.rb"
156
+ "in_#{underscore_name}.rb"
151
157
  when "output"
152
- "out_#{name}.rb"
158
+ "out_#{underscore_name}.rb"
153
159
  else
154
- "#{type}_#{name}.rb"
160
+ "#{type}_#{underscore_name}.rb"
155
161
  end
156
162
  end
157
163
 
158
164
  def test_filename
159
165
  case type
160
166
  when "input"
161
- "test_in_#{name}.rb"
167
+ "test_in_#{underscore_name}.rb"
162
168
  when "output"
163
- "test_out_#{name}.rb"
169
+ "test_out_#{underscore_name}.rb"
164
170
  else
165
- "test_#{type}_#{name}.rb"
171
+ "test_#{type}_#{underscore_name}.rb"
166
172
  end
167
173
  end
168
174
 
@@ -179,6 +185,18 @@ BANNER
179
185
  end
180
186
  end
181
187
 
188
+ def capitalized_name
189
+ @capitalized_name ||= name.split(/[-_]/).map(&:capitalize).join
190
+ end
191
+
192
+ def underscore_name
193
+ @underscore_name ||= name.tr("-", "_")
194
+ end
195
+
196
+ def dash_name
197
+ @dash_name ||= name.tr("_", "-")
198
+ end
199
+
182
200
  def preamble
183
201
  @license.preamble(user_name)
184
202
  end