fluent-mixin-config-placeholders 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7cf47545aa0315f25907042c77498e98fed3b4a9
4
+ data.tar.gz: b5f57c7a7781cfa19b654c3e7e144bb48473908e
5
+ SHA512:
6
+ metadata.gz: 5f0e041fb2cb87f82c98944ed033842ffbefd6ce16073ba55843e1c2f3b15550c4001d3158416b226de5ba42bbe41fc7cf40b502c20666781882da735c22f413
7
+ data.tar.gz: 4176165b3c8645705be7e46ce6b34b391aae31d45eae9d152e715e4969b61faf4531a1dbb6216fb21bac8ee06b336bdad28956b913e462768fa7766331c05bd1
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
@@ -1,12 +1,13 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "fluent-mixin-config-placeholders"
4
- gem.version = "0.2.3"
4
+ gem.version = "0.2.4"
5
5
  gem.authors = ["TAGOMORI Satoshi"]
6
6
  gem.email = ["tagomoris@gmail.com"]
7
7
  gem.description = %q{to add various placeholders for plugin configurations}
8
8
  gem.summary = %q{Configuration syntax extension mixin for fluentd plugin}
9
9
  gem.homepage = "https://github.com/tagomoris/fluent-mixin-config-placeholders"
10
+ gem.license = "APLv2"
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -15,4 +16,5 @@ Gem::Specification.new do |gem|
15
16
 
16
17
  gem.add_runtime_dependency "fluentd"
17
18
  gem.add_runtime_dependency "uuidtools"
19
+ gem.add_development_dependency "rake"
18
20
  end
@@ -38,9 +38,21 @@ module Fluent
38
38
  map.reduce(value){|r,p| r.gsub(p[0], p[1].call())}
39
39
  end
40
40
 
41
+ def has_replace_pattern?(value)
42
+ value =~ /\$\{(?:hostname|uuid:[a-z]+)\}/ ||
43
+ value =~ /\%\{(?:hostname|uuid:[a-z]+)\}/ ||
44
+ value =~ /__(?:HOSTNAME|UUID_[A-Z]+)__/
45
+ end
46
+
41
47
  def configure(conf)
42
- # Element#has_key? inserts key name into 'used' list, so we should escape that method...
43
- hostname = conf.keys.include?('hostname') ? conf['hostname'] : `hostname`.chomp
48
+ # Element#has_key? inserts key name into 'used' list, so we should not use that method...
49
+ hostname = if conf.keys.include?('hostname') && has_replace_pattern?( conf.fetch('hostname') )
50
+ `hostname`.chomp
51
+ elsif conf.keys.include?('hostname')
52
+ conf['hostname']
53
+ else
54
+ `hostname`.chomp
55
+ end
44
56
 
45
57
  placeholders = self.respond_to?(:placeholders) ? self.placeholders : PLACEHOLDERS_DEFAULT
46
58
 
@@ -8,26 +8,27 @@ class ConfigPlaceholdersTest < Test::Unit::TestCase
8
8
  end
9
9
 
10
10
  def test_unused
11
+ # 'id' used by Fluentd core as plugin id...
11
12
  conf = %[
12
13
  tag HOGE
13
14
  path POSPOSPOS
14
15
  ]
15
16
  p = Fluent::Test::InputTestDriver.new(Fluent::ConfigPlaceholdersTest2Input).configure(conf).instance
16
- assert_equal ['tag','path'], p.conf.used
17
+ assert_equal [], p.conf.unused
17
18
 
18
19
  conf = %[
19
20
  tag HOGE
20
21
  path POSPOSPOS
21
22
  ]
22
23
  p = Fluent::Test::InputTestDriver.new(Fluent::ConfigPlaceholdersTestXInput).configure(conf).instance
23
- assert_equal [], p.conf.used
24
+ assert_equal ['tag', 'path'], p.conf.unused
24
25
 
25
26
  conf = %[
26
27
  tag HOGE
27
28
  path POSPOSPOS ${hostname} MOGEMOGE
28
29
  ]
29
30
  p = Fluent::Test::InputTestDriver.new(Fluent::ConfigPlaceholdersTestXInput).configure(conf).instance
30
- assert_equal [], p.conf.used
31
+ assert_equal ['tag', 'path'], p.conf.unused
31
32
  end
32
33
 
33
34
  def test_default
@@ -220,4 +221,51 @@ path /path/to/file.log
220
221
  assert_equal "value.1." + uuid, p3.conf.elements.first.elements[0]['field']
221
222
  assert_equal "value.2." + uuid, p3.conf.elements.first.elements[1]['field']
222
223
  end
224
+
225
+ def test_value_has_replace_pattern?
226
+ conf1 = %[
227
+ hostname test.host.local
228
+ attr1 ${hostname}
229
+ ]
230
+ p1 = Fluent::Test::InputTestDriver.new(Fluent::ConfigPlaceholdersTest3Input).configure(conf1).instance
231
+
232
+ assert p1.has_replace_pattern?('foo.__HOSTNAME__')
233
+ assert p1.has_replace_pattern?('foo.__UUID_RANDOM__')
234
+ assert p1.has_replace_pattern?('foo.__UUID_HOSTNAME__')
235
+ assert p1.has_replace_pattern?('foo.__UUID_TIMESTAMP__')
236
+ assert p1.has_replace_pattern?('foo.${hostname}.local')
237
+ assert p1.has_replace_pattern?('foo.${uuid:random}.local')
238
+ assert p1.has_replace_pattern?('foo.${uuid:hostname}.local')
239
+ assert p1.has_replace_pattern?('foo.${uuid:timestamp}.local')
240
+ assert p1.has_replace_pattern?('%{hostname}.local')
241
+ assert p1.has_replace_pattern?('%{uuid:random}.local')
242
+ assert p1.has_replace_pattern?('%{uuid:hostname}.local')
243
+ assert p1.has_replace_pattern?('%{uuid:timestamp}.local')
244
+ end
245
+
246
+ def test_attribute_hostname
247
+ # this configuration pattern is to set hostname itself
248
+ # - @hostname should be set as 'test.host.local'
249
+ # - @attr1 should be set as 'test.host.local'
250
+ conf1 = %[
251
+ hostname test.host.local
252
+ attr1 ${hostname}
253
+ ]
254
+ p1 = Fluent::Test::InputTestDriver.new(Fluent::ConfigPlaceholdersTest3Input).configure(conf1).instance
255
+ assert_equal "test.host.local", p1.hostname
256
+ assert_equal "test.host.local", p1.attr1
257
+
258
+ # this configuration pattern is to set hostname-attribute of plugins
259
+ # when 'myhostname' is host name (result of `hostname` shell command),
260
+ # - @hostname is set as 'myhostname.fluentd.local'
261
+ # - @attr1 should be set as 'myhostname' only, it is default of mixin
262
+ conf2 = %[
263
+ hostname ${hostname}.fluentd.local
264
+ attr1 __HOSTNAME__
265
+ ]
266
+ p2 = Fluent::Test::InputTestDriver.new(Fluent::ConfigPlaceholdersTest3Input).configure(conf2).instance
267
+ hostname_cmd = `hostname`.chomp
268
+ assert_equal "#{hostname_cmd}.fluentd.local", p2.hostname
269
+ assert_equal hostname_cmd, p2.attr1
270
+ end
223
271
  end
@@ -62,3 +62,20 @@ class Fluent::ConfigPlaceholdersTest2Input < Fluent::Input
62
62
  @conf = conf
63
63
  end
64
64
  end
65
+
66
+ class Fluent::ConfigPlaceholdersTest3Input < Fluent::Input
67
+ Fluent::Plugin.register_input('config_placeholder_test_2', self)
68
+
69
+ config_param :hostname, :string
70
+ config_param :attr1, :string
71
+
72
+ include Fluent::Mixin::ConfigPlaceholders
73
+
74
+ attr_accessor :conf
75
+
76
+ def placeholders; [:dollar, :percent, :underscore]; end
77
+ def configure(conf)
78
+ super
79
+ @conf = conf
80
+ end
81
+ end
metadata CHANGED
@@ -1,46 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-mixin-config-placeholders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.2.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - TAGOMORI Satoshi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-08 00:00:00.000000000 Z
11
+ date: 2014-02-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: fluentd
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: uuidtools
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  description: to add various placeholders for plugin configurations
@@ -51,6 +60,7 @@ extensions: []
51
60
  extra_rdoc_files: []
52
61
  files:
53
62
  - .gitignore
63
+ - .travis.yml
54
64
  - Gemfile
55
65
  - LICENSE.txt
56
66
  - README.md
@@ -61,30 +71,31 @@ files:
61
71
  - test/mixin/test_config_placeholders.rb
62
72
  - test/plugin.rb
63
73
  homepage: https://github.com/tagomoris/fluent-mixin-config-placeholders
64
- licenses: []
74
+ licenses:
75
+ - APLv2
76
+ metadata: {}
65
77
  post_install_message:
66
78
  rdoc_options: []
67
79
  require_paths:
68
80
  - lib
69
81
  required_ruby_version: !ruby/object:Gem::Requirement
70
- none: false
71
82
  requirements:
72
- - - ! '>='
83
+ - - '>='
73
84
  - !ruby/object:Gem::Version
74
85
  version: '0'
75
86
  required_rubygems_version: !ruby/object:Gem::Requirement
76
- none: false
77
87
  requirements:
78
- - - ! '>='
88
+ - - '>='
79
89
  - !ruby/object:Gem::Version
80
90
  version: '0'
81
91
  requirements: []
82
92
  rubyforge_project:
83
- rubygems_version: 1.8.23
93
+ rubygems_version: 2.0.3
84
94
  signing_key:
85
- specification_version: 3
95
+ specification_version: 4
86
96
  summary: Configuration syntax extension mixin for fluentd plugin
87
97
  test_files:
88
98
  - test/helper.rb
89
99
  - test/mixin/test_config_placeholders.rb
90
100
  - test/plugin.rb
101
+ has_rdoc: