fluent-plugin-zabbix 0.2.4 → 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
- SHA256:
3
- metadata.gz: 497e57af1beaf3860ad81af6bc382b98c0cd214df32e41135619f157a263a1f0
4
- data.tar.gz: 2c7936b561ea53f172898bffe21223846659d7ec5b58c5b4cb1db1a7feb3692c
2
+ SHA1:
3
+ metadata.gz: 35423c2cf732ed7048b36bb6c4c5882fb2526110
4
+ data.tar.gz: 46dbb7031bfb41f3ea4d7a9acd87dcef14714f3b
5
5
  SHA512:
6
- metadata.gz: a57dabda7d0bd4d72e581eccd029edfd8d54421df0efb8f934a40dc98df2fbe7a83f98527d65c2a9c6b3a5cbffe351dbbca1390d941b5c06dbb56a64184c678c
7
- data.tar.gz: aef02a1016229ec9b75503bd7e0fcebb4c356496e78f6850deec5e1fe1c774c1aedc2267b0b2676231bb6e23de8a6144a12770e9a09cde9db21b97f2bb4c6ed2
6
+ metadata.gz: 33cfd15134ba66af5163ec247b4696708d89960b86fb3a5a67f9ec9dffb33c7db8eabba8b8c8f55542f22e0601452af684fd27e6d134ad640949f955dddaf29e
7
+ data.tar.gz: bab731439abad3a3a7242ff35840d29a305ab9d529aa83f7fe75ba4ee9b5ee5fc811368bebf0b5117478b81987f5d552b2c2c9bd6fe022588ec63588b040318f
data/.travis.yml CHANGED
@@ -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,13 +14,12 @@ 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.4"
17
+ gem.version = "0.3.0"
18
18
 
19
- gem.add_runtime_dependency "fluentd", [">= 0.10", "< 0.14"]
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"
23
- gem.add_development_dependency "glint", "= 0.1.0"
23
+ gem.add_development_dependency "glint", "= 0.0.2"
24
24
  gem.add_development_dependency "test-unit", ">= 3.1.0"
25
- gem.add_development_dependency "webrick"
26
25
  end
@@ -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
- :clock => 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
- :clock => 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
@@ -31,11 +31,10 @@ func main() {
31
31
  func handler(req zabbix.TrapperRequest) (res zabbix.TrapperResponse, err error) {
32
32
  for _, d := range req.Data {
33
33
  line := fmt.Sprintf(
34
- "host:%s\tkey:%s\tvalue:%s\tclock:%d\n",
34
+ "host:%s\tkey:%s\tvalue:%s\n",
35
35
  d.Host,
36
36
  d.Key,
37
37
  d.Value,
38
- d.Clock,
39
38
  )
40
39
  Output.Write([]byte(line))
41
40
  }
@@ -1,9 +1,10 @@
1
1
  require 'helper'
2
+ require 'fluent/test/driver/output'
2
3
 
3
4
  if ENV['LIVE_TEST']
4
5
  require "glint"
5
6
  require "tmpdir"
6
- system "sh -c 'cd mockserver && go build mockserver.go'"
7
+ system "go", "build", "test/mockserver.go"
7
8
  end
8
9
 
9
10
  class ZabbixOutputTest < Test::Unit::TestCase
@@ -11,8 +12,8 @@ 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
- exec "./mockserver/mockserver", $dir.to_s + "/trapper.log"
15
+ $server = Glint::Server.new(10051, { timeout: 3 }) do |port|
16
+ exec "./mockserver", $dir.to_s + "/trapper.log"
16
17
  end
17
18
  $server.start
18
19
  end
@@ -25,30 +26,30 @@ 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
- now = Time.now.to_i
35
35
  if ENV['LIVE_TEST']
36
- d.emit({"foo" => "test value of foo"}, now)
37
- d.emit({"bar" => "test value of bar"}, now)
38
- d.emit({"baz" => 123.4567 }, now)
39
- d.emit({"foo" => "yyy", "zabbix_host" => "alternative-hostname"}, now)
40
- d.emit({"f1" => 0.000001}, now)
41
- d.emit({"f2" => 0.01}, now)
42
- sleep 1
43
-
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
44
45
  $server.stop
45
46
  assert_equal open($dir + "/trapper.log").read, <<END
46
- host:test_host key:test.foo value:test value of foo clock:#{now}
47
- host:test_host key:test.bar value:test value of bar clock:#{now}
48
- host:test_host key:test.baz value:123.4567 clock:#{now}
49
- host:test_host key:test.foo value:yyy clock:#{now}
50
- host:test_host key:test.f1 value:0.0 clock:#{now}
51
- host:test_host key:test.f2 value:0.01 clock:#{now}
47
+ host:test_host key:test.foo value:test value of foo
48
+ host:test_host key:test.bar value:test value of bar
49
+ host:test_host key:test.baz value:123.4567
50
+ host:test_host key:test.foo value:yyy
51
+ host:test_host key:test.f1 value:0.0
52
+ host:test_host key:test.f2 value:0.01
52
53
  END
53
54
  end
54
55
  end
@@ -61,8 +62,8 @@ END
61
62
  name_keys foo, bar, baz
62
63
  ]
63
64
 
64
- def create_driver_host_key(conf = CONFIG_HOST_KEY, tag='test')
65
- 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)
66
67
  end
67
68
 
68
69
  CONFIG_PREFIX_KEY = %[
@@ -72,39 +73,38 @@ END
72
73
  name_keys foo, bar, baz
73
74
  ]
74
75
 
75
- def create_driver_prefix_key(conf = CONFIG_PREFIX_KEY, tag='test')
76
- 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)
77
78
  end
78
79
 
79
80
  def test_write_host_key
80
81
  d = create_driver_host_key
81
- now = Time.now.to_i
82
82
  if ENV['LIVE_TEST']
83
- d.emit({"foo" => "AAA" }, now)
84
- d.emit({"foo" => "BBB", "host" => "alternative-hostname"}, now)
85
- d.run
86
- sleep 1
87
-
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
88
88
  $server.stop
89
89
  assert_equal open($dir + "/trapper.log").read, <<END
90
- host:test_host key:test.foo value:AAA clock:#{now}
91
- host:alternative-hostname key:test.foo value:BBB clock:#{now}
90
+ host:test_host key:test.foo value:AAA
91
+ host:alternative-hostname key:test.foo value:BBB
92
92
  END
93
93
  end
94
94
  end
95
95
 
96
96
  def test_write_prefix_key
97
97
  d = create_driver_prefix_key
98
- now = Time.now.to_i
99
98
  if ENV['LIVE_TEST']
100
- d.emit({"foo" => "AAA"}, now)
101
- d.emit({"foo" => "BBB", "prefix" => "p"}, now)
102
- d.run
103
- 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
104
104
  $server.stop
105
105
  assert_equal open($dir + "/trapper.log").read, <<END
106
- host:test_host key:foo value:AAA clock:#{now}
107
- host:test_host key:p.foo value:BBB clock:#{now}
106
+ host:test_host key:foo value:AAA
107
+ host:test_host key:p.foo value:BBB
108
108
  END
109
109
  end
110
110
  end
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.4
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: 2023-12-21 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,20 +16,20 @@ 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
- version: '0.14'
22
+ version: '2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
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
- version: '0.14'
32
+ version: '2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: yajl-ruby
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - '='
80
80
  - !ruby/object:Gem::Version
81
- version: 0.1.0
81
+ version: 0.0.2
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - '='
87
87
  - !ruby/object:Gem::Version
88
- version: 0.1.0
88
+ version: 0.0.2
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: test-unit
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -100,20 +100,6 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: 3.1.0
103
- - !ruby/object:Gem::Dependency
104
- name: webrick
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: '0'
117
103
  description: Output data plugin to Zabbix
118
104
  email:
119
105
  - fujiwara.shunichiro@gmail.com
@@ -124,16 +110,13 @@ files:
124
110
  - ".gitignore"
125
111
  - ".travis.yml"
126
112
  - Gemfile
127
- - Gemfile.fluentd.lt.0.10.43
128
113
  - LICENSE
129
114
  - README.md
130
115
  - Rakefile
131
116
  - fluent-plugin-zabbix.gemspec
132
117
  - lib/fluent/plugin/out_zabbix.rb
133
- - mockserver/go.mod
134
- - mockserver/go.sum
135
- - mockserver/mockserver.go
136
118
  - test/helper.rb
119
+ - test/mockserver.go
137
120
  - test/plugin/test_out_zabbix.rb
138
121
  homepage: https://github.com/fujiwara/fluent-plugin-zabbix
139
122
  licenses:
@@ -154,10 +137,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
137
  - !ruby/object:Gem::Version
155
138
  version: '0'
156
139
  requirements: []
157
- rubygems_version: 3.4.10
140
+ rubyforge_project:
141
+ rubygems_version: 2.6.11
158
142
  signing_key:
159
143
  specification_version: 4
160
144
  summary: Output data plugin to Zabbix (like zabbix_sender)
161
145
  test_files:
162
146
  - test/helper.rb
147
+ - test/mockserver.go
163
148
  - test/plugin/test_out_zabbix.rb
@@ -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
data/mockserver/go.mod DELETED
@@ -1,5 +0,0 @@
1
- module github.com/fujiwara/fluent-plugin-zabbix/mockserver
2
-
3
- go 1.18
4
-
5
- require github.com/fujiwara/go-zabbix-get v0.1.0
data/mockserver/go.sum DELETED
@@ -1,2 +0,0 @@
1
- github.com/fujiwara/go-zabbix-get v0.1.0 h1:Aufw3MvWksIc9wCTbHipikkBFX8PD220IrnE9LC7eO8=
2
- github.com/fujiwara/go-zabbix-get v0.1.0/go.mod h1:1C6hUoBE4tOGZFGqHhhIj3NBfU8BJ+/YDDRGjLQhSdA=