fluent-plugin-zabbix 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fluent-plugin-zabbix.gemspec +2 -2
- data/lib/fluent/plugin/out_zabbix.rb +36 -7
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e11da95c4e09044e40845f2292db90a2d1ca7ea8
|
4
|
+
data.tar.gz: 54def51b590808ba75f6e6ad65532f83b2c36f3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
16
|
+
gem.version = "0.0.6"
|
17
17
|
|
18
18
|
gem.add_runtime_dependency "fluentd", "~> 0.10"
|
19
|
-
gem.add_runtime_dependency "
|
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
|
-
|
58
|
-
log.debug("zabbix: #{
|
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 =
|
65
|
+
status = send_to_zabbix(sock, host, name, value.round(4).to_s, time)
|
65
66
|
else
|
66
|
-
status =
|
67
|
+
status = send_to_zabbix(sock, host, name, value.to_s, time)
|
67
68
|
end
|
68
69
|
rescue => e
|
69
|
-
log.warn "plugin-zabbix:
|
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.
|
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-
|
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:
|
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
|
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
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|