fluent-plugin-zabbix 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3549d1035d720adf10906025533a6b300b78cb91
4
- data.tar.gz: 4217a75b549c6b3d104872c6fa81d6132028f321
3
+ metadata.gz: e11da95c4e09044e40845f2292db90a2d1ca7ea8
4
+ data.tar.gz: 54def51b590808ba75f6e6ad65532f83b2c36f3c
5
5
  SHA512:
6
- metadata.gz: 2b8ca5659fa7e75dbdc0ce85ce24f53fe09578a0fe5491aa3795040c520f06f5c25665df6dbab0006aa3c17c758378988eda89813a77aed789ce5e46daedd296
7
- data.tar.gz: 9f69b428aafca5e82a7e2baaa0711228fbc3a4aab0d23e152d5378634ec0ef77512672c476d8ae2f926edf8acc6bbc2061b6e3040d4ad927bc1dace47bdb6066
6
+ metadata.gz: 38e28be96f3102f1598705e0151c408ff6d90f4613b3a0364eaf45f3e140d15f001bae1b0dbb362c335a0a07a8405ca4e7a17697302c12f3a34e4b0263200c50
7
+ data.tar.gz: abdbcc01fc4a6a6a2771e9a61744ceb55bf29aad25f881c821df2f60795cf7567bcf6da247f34ec6316f473f31c242f5499f569ba165b7d4d8720d892a79bb26
@@ -13,10 +13,10 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "fluent-plugin-zabbix"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = "0.0.5"
16
+ gem.version = "0.0.6"
17
17
 
18
18
  gem.add_runtime_dependency "fluentd", "~> 0.10"
19
- gem.add_runtime_dependency "zabbix", ">= 0.4"
19
+ gem.add_runtime_dependency "yajl-ruby", "~> 1.0"
20
20
  gem.add_development_dependency "rake", ">= 0.9.2"
21
21
  gem.add_development_dependency "glint", "= 0.0.2"
22
22
  end
@@ -1,10 +1,12 @@
1
1
  class Fluent::ZabbixOutput < Fluent::Output
2
2
  Fluent::Plugin.register_output('zabbix', self)
3
3
 
4
+ ZBXD = "ZBXD\x01"
5
+
4
6
  def initialize
5
7
  super
6
- require 'zabbix'
7
8
  require 'socket'
9
+ require 'yajl'
8
10
  end
9
11
 
10
12
  config_param :zabbix_server, :string
@@ -54,21 +56,23 @@ class Fluent::ZabbixOutput < Fluent::Output
54
56
  name = "#{@add_key_prefix}.#{name}"
55
57
  end
56
58
  begin
57
- zbx = Zabbix::Sender.new(:host => @zabbix_server, :port => @port)
58
- log.debug("zabbix: #{zbx}, #{name}: #{value}, host: #{host}, ts: #{time}")
59
- opts = { :host => host, :ts => time }
59
+ sock = TCPSocket.open(@zabbix_server, @port)
60
+ log.debug("zabbix: #{sock} #{name}: #{value}, host: #{host}, ts: #{time}")
60
61
  if value.kind_of? Float
61
62
  # https://www.zabbix.com/documentation/2.4/manual/config/items/item
62
63
  # > Allowed range (for MySQL): -999999999999.9999 to 999999999999.9999 (double(16,4)).
63
64
  # > Starting with Zabbix 2.2, receiving values in scientific notation is also supported. E.g. 1e+70, 1e-70.
64
- status = zbx.send_data(name, value.round(4).to_s, opts)
65
+ status = send_to_zabbix(sock, host, name, value.round(4).to_s, time)
65
66
  else
66
- status = zbx.send_data(name, value.to_s, opts)
67
+ status = send_to_zabbix(sock, host, name, value.to_s, time)
67
68
  end
68
69
  rescue => e
69
- log.warn "plugin-zabbix: Zabbix::Sender.send_data raises exception: #{e}"
70
+ log.warn "plugin-zabbix: raises exception: #{e}"
70
71
  status = false
72
+ ensure
73
+ sock.close if sock
71
74
  end
75
+
72
76
  unless status
73
77
  log.warn "plugin-zabbix: failed to send to zabbix_server: #{@zabbix_server}:#{@port}, host:#{host} '#{name}': #{value}"
74
78
  end
@@ -110,4 +114,29 @@ class Fluent::ZabbixOutput < Fluent::Output
110
114
  end
111
115
  return host
112
116
  end
117
+
118
+ def send_to_zabbix(sock, host, key, value, time)
119
+ data = {
120
+ :host => host,
121
+ :key => key,
122
+ :value => value.to_s,
123
+ :time => time.to_i,
124
+ }
125
+ req = Yajl::Encoder.encode({
126
+ :request => 'agent data',
127
+ :clock => time.to_i,
128
+ :data => [ data ],
129
+ })
130
+ sock.write(ZBXD + [ req.size ].pack('q') + req)
131
+ sock.flush
132
+
133
+ header = sock.read(5)
134
+ if header != ZBXD
135
+ return false
136
+ end
137
+ len = sock.read(8).unpack('q')[0]
138
+ res = Yajl::Parser.parse(sock.read(len))
139
+ return res['response'] == "success"
140
+ end
141
+
113
142
  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.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - FUJIWARA Shunichiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-05 00:00:00.000000000 Z
11
+ date: 2015-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.10'
27
27
  - !ruby/object:Gem::Dependency
28
- name: zabbix
28
+ name: yajl-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.4'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.4'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement