fluent-plugin-zabbix 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e840411e29db42fc60e77d0b56235e8012bb9e6
4
- data.tar.gz: 1ed7a4df13454605e0c1a9dd00003353db7d5aac
3
+ metadata.gz: 35423c2cf732ed7048b36bb6c4c5882fb2526110
4
+ data.tar.gz: 46dbb7031bfb41f3ea4d7a9acd87dcef14714f3b
5
5
  SHA512:
6
- metadata.gz: 27c58fc74df1d1d0ba806ec89586588eb63d236bf4c35edf638986f4e06aa8d305005e5845800206a090b9a53dc8a6d246f0b770b85fd92543931b3130f20bd8
7
- data.tar.gz: 1a18cfb1ba839c90ec7908fe820f564ddfb75ec20fcfa5c517e16c855417a5b1e93e5b479e008bf8b3649ac079779521ea49556d61390ebd61870c6943e62777
6
+ metadata.gz: 33cfd15134ba66af5163ec247b4696708d89960b86fb3a5a67f9ec9dffb33c7db8eabba8b8c8f55542f22e0601452af684fd27e6d134ad640949f955dddaf29e
7
+ data.tar.gz: bab731439abad3a3a7242ff35840d29a305ab9d529aa83f7fe75ba4ee9b5ee5fc811368bebf0b5117478b81987f5d552b2c2c9bd6fe022588ec63588b040318f
@@ -3,6 +3,7 @@ rvm:
3
3
  - 2.1
4
4
  - 2.2
5
5
  - 2.3
6
+ - 2.4.0
6
7
  gemfile:
7
8
  - Gemfile
8
9
  before_install:
data/Rakefile CHANGED
@@ -9,4 +9,4 @@ Rake::TestTask.new(:test) do |test|
9
9
  test.verbose = true
10
10
  end
11
11
 
12
- task :default => :test
12
+ task default: :test
@@ -14,9 +14,9 @@ Gem::Specification.new do |gem|
14
14
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
15
  gem.name = "fluent-plugin-zabbix"
16
16
  gem.require_paths = ["lib"]
17
- gem.version = "0.2.3"
17
+ gem.version = "0.3.0"
18
18
 
19
- gem.add_runtime_dependency "fluentd", [">= 0.10", "< 2"]
19
+ gem.add_runtime_dependency "fluentd", [">= 0.14.8", "< 2"]
20
20
  gem.add_runtime_dependency "yajl-ruby", "~> 1.0"
21
21
  gem.add_runtime_dependency "fluent-mixin-config-placeholders", "~> 0.3"
22
22
  gem.add_development_dependency "rake", ">= 0.9.2"
@@ -1,40 +1,28 @@
1
+ require 'socket'
2
+ require 'yajl'
3
+ require 'fluent/plugin/output'
1
4
  require 'fluent/mixin/config_placeholders'
2
5
 
3
- class Fluent::ZabbixOutput < Fluent::Output
6
+ class Fluent::Plugin::ZabbixOutput < Fluent::Plugin::Output
4
7
  Fluent::Plugin.register_output('zabbix', self)
5
8
 
6
9
  ZBXD = "ZBXD\x01"
7
10
  ZBX_PROTO_VALUE_SENDER_DATA = 'sender data'
8
11
 
9
- def initialize
10
- super
11
- require 'socket'
12
- require 'yajl'
13
- end
14
-
15
12
  config_param :zabbix_server, :string
16
- config_param :port, :integer, :default => 10051
17
- config_param :host, :string, :default => Socket.gethostname
18
- config_param :host_key, :string, :default => nil
19
- config_param :name_keys, :string, :default => nil
20
- config_param :name_key_pattern, :string, :default => nil
21
- config_param :add_key_prefix, :string, :default => nil
22
- config_param :prefix_key, :string, :default => nil
13
+ config_param :port, :integer, default: 10051
14
+ config_param :host, :string, default: Socket.gethostname
15
+ config_param :host_key, :string, default: nil
16
+ config_param :name_keys, :string, default: nil
17
+ config_param :name_key_pattern, :string, default: nil
18
+ config_param :add_key_prefix, :string, default: nil
19
+ config_param :prefix_key, :string, default: nil
23
20
 
24
21
  include Fluent::Mixin::ConfigPlaceholders
25
22
 
26
- # Define `log` method for v0.10.42 or earlier
27
- unless method_defined?(:log)
28
- define_method("log") { $log }
29
- end
30
-
31
23
  def configure(conf)
32
24
  super
33
25
 
34
- if @zabbix_server.nil?
35
- raise Fluent::ConfigError, "missing zabbix_server"
36
- end
37
-
38
26
  if @name_keys.nil? and @name_key_pattern.nil?
39
27
  raise Fluent::ConfigError, "missing both of name_keys and name_key_pattern"
40
28
  end
@@ -49,12 +37,8 @@ class Fluent::ZabbixOutput < Fluent::Output
49
37
  end
50
38
  end
51
39
 
52
- def start
53
- super
54
- end
55
-
56
- def shutdown
57
- super
40
+ def multi_workers_ready?
41
+ true
58
42
  end
59
43
 
60
44
  def bulk_send(time, bulk)
@@ -76,17 +60,17 @@ class Fluent::ZabbixOutput < Fluent::Output
76
60
  end
77
61
  end
78
62
 
79
- def emit(tag, es, chain)
63
+ def process(tag, es)
80
64
  if @name_keys
81
65
  es.each {|time,record|
82
66
  host = gen_host(record)
83
67
  bulk = []
84
68
  @name_keys.each {|key|
85
69
  if record[key]
86
- bulk.push({ :key => format_key(tag, key, record),
87
- :value => format_value(record[key]),
88
- :host => host,
89
- :time => time.to_i,
70
+ bulk.push({ key: format_key(tag, key, record),
71
+ value: format_value(record[key]),
72
+ host: host,
73
+ time: time.to_i,
90
74
  })
91
75
  end
92
76
  }
@@ -98,17 +82,16 @@ class Fluent::ZabbixOutput < Fluent::Output
98
82
  bulk = []
99
83
  record.keys.each {|key|
100
84
  if @name_key_pattern.match(key) && record[key]
101
- bulk.push({ :key => format_key(tag, key, record),
102
- :value => format_value(record[key]),
103
- :host => host,
104
- :time => time.to_i,
85
+ bulk.push({ key: format_key(tag, key, record),
86
+ value: format_value(record[key]),
87
+ host: host,
88
+ time: time.to_i,
105
89
  })
106
90
  end
107
91
  }
108
92
  bulk_send(time, bulk) if bulk.size > 0
109
93
  }
110
94
  end
111
- chain.next
112
95
  end
113
96
 
114
97
  def gen_host(record)
@@ -155,9 +138,9 @@ class Fluent::ZabbixOutput < Fluent::Output
155
138
 
156
139
  def send_to_zabbix(sock, time, bulk)
157
140
  req = Yajl::Encoder.encode({
158
- :request => ZBX_PROTO_VALUE_SENDER_DATA,
159
- :clock => time.to_i,
160
- :data => bulk,
141
+ request: ZBX_PROTO_VALUE_SENDER_DATA,
142
+ clock: time.to_i,
143
+ data: bulk,
161
144
  })
162
145
  sock.write(ZBXD + [ req.size ].pack('q') + req)
163
146
  sock.flush
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'fluent/test/driver/output'
2
3
 
3
4
  if ENV['LIVE_TEST']
4
5
  require "glint"
@@ -11,7 +12,7 @@ class ZabbixOutputTest < Test::Unit::TestCase
11
12
  Fluent::Test.setup
12
13
  if ENV['LIVE_TEST']
13
14
  $dir = Dir.mktmpdir
14
- $server = Glint::Server.new(10051, { :timeout => 3 }) do |port|
15
+ $server = Glint::Server.new(10051, { timeout: 3 }) do |port|
15
16
  exec "./mockserver", $dir.to_s + "/trapper.log"
16
17
  end
17
18
  $server.start
@@ -25,21 +26,22 @@ class ZabbixOutputTest < Test::Unit::TestCase
25
26
  name_keys foo, bar, baz, f1, f2
26
27
  ]
27
28
 
28
- def create_driver(conf = CONFIG, tag='test')
29
- Fluent::Test::OutputTestDriver.new(Fluent::ZabbixOutput, tag).configure(conf)
29
+ def create_driver(conf = CONFIG)
30
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::ZabbixOutput).configure(conf)
30
31
  end
31
32
 
32
33
  def test_write
33
34
  d = create_driver
34
35
  if ENV['LIVE_TEST']
35
- d.emit({"foo" => "test value of foo"})
36
- d.emit({"bar" => "test value of bar"})
37
- d.emit({"baz" => 123.4567 })
38
- d.emit({"foo" => "yyy", "zabbix_host" => "alternative-hostname"})
39
- d.emit({"f1" => 0.000001})
40
- d.emit({"f2" => 0.01})
41
- d.run
42
- sleep 1
36
+ d.run(default_tag: 'test') do
37
+ d.feed({"foo" => "test value of foo"})
38
+ d.feed({"bar" => "test value of bar"})
39
+ d.feed({"baz" => 123.4567 })
40
+ d.feed({"foo" => "yyy", "zabbix_host" => "alternative-hostname"})
41
+ d.feed({"f1" => 0.000001})
42
+ d.feed({"f2" => 0.01})
43
+ sleep 1
44
+ end
43
45
  $server.stop
44
46
  assert_equal open($dir + "/trapper.log").read, <<END
45
47
  host:test_host key:test.foo value:test value of foo
@@ -60,8 +62,8 @@ END
60
62
  name_keys foo, bar, baz
61
63
  ]
62
64
 
63
- def create_driver_host_key(conf = CONFIG_HOST_KEY, tag='test')
64
- Fluent::Test::OutputTestDriver.new(Fluent::ZabbixOutput, tag).configure(conf)
65
+ def create_driver_host_key(conf = CONFIG_HOST_KEY)
66
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::ZabbixOutput).configure(conf)
65
67
  end
66
68
 
67
69
  CONFIG_PREFIX_KEY = %[
@@ -71,17 +73,18 @@ END
71
73
  name_keys foo, bar, baz
72
74
  ]
73
75
 
74
- def create_driver_prefix_key(conf = CONFIG_PREFIX_KEY, tag='test')
75
- Fluent::Test::OutputTestDriver.new(Fluent::ZabbixOutput, tag).configure(conf)
76
+ def create_driver_prefix_key(conf = CONFIG_PREFIX_KEY)
77
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::ZabbixOutput).configure(conf)
76
78
  end
77
79
 
78
80
  def test_write_host_key
79
81
  d = create_driver_host_key
80
82
  if ENV['LIVE_TEST']
81
- d.emit({"foo" => "AAA" })
82
- d.emit({"foo" => "BBB", "host" => "alternative-hostname"})
83
- d.run
84
- sleep 1
83
+ d.run(default_tag: 'test') do
84
+ d.feed({"foo" => "AAA" })
85
+ d.feed({"foo" => "BBB", "host" => "alternative-hostname"})
86
+ sleep 1
87
+ end
85
88
  $server.stop
86
89
  assert_equal open($dir + "/trapper.log").read, <<END
87
90
  host:test_host key:test.foo value:AAA
@@ -93,10 +96,11 @@ END
93
96
  def test_write_prefix_key
94
97
  d = create_driver_prefix_key
95
98
  if ENV['LIVE_TEST']
96
- d.emit({"foo" => "AAA"})
97
- d.emit({"foo" => "BBB", "prefix" => "p"})
98
- d.run
99
- sleep 1
99
+ d.run(default_tag: 'test') do
100
+ d.feed({"foo" => "AAA"})
101
+ d.feed({"foo" => "BBB", "prefix" => "p"})
102
+ sleep 1
103
+ end
100
104
  $server.stop
101
105
  assert_equal open($dir + "/trapper.log").read, <<END
102
106
  host:test_host key:foo value:AAA
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-zabbix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - FUJIWARA Shunichiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-30 00:00:00.000000000 Z
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.10'
19
+ version: 0.14.8
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '0.10'
29
+ version: 0.14.8
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'
@@ -110,7 +110,6 @@ files:
110
110
  - ".gitignore"
111
111
  - ".travis.yml"
112
112
  - Gemfile
113
- - Gemfile.fluentd.lt.0.10.43
114
113
  - LICENSE
115
114
  - README.md
116
115
  - Rakefile
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in fluent-plugin-zabbix.gemspec
4
- gem 'fluentd', '= 0.10.42'
5
- gemspec