fluent-plugin-zabbix 0.2.3 → 0.3.0
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 +4 -4
- data/.travis.yml +1 -0
- data/Rakefile +1 -1
- data/fluent-plugin-zabbix.gemspec +2 -2
- data/lib/fluent/plugin/out_zabbix.rb +25 -42
- data/test/plugin/test_out_zabbix.rb +27 -23
- metadata +4 -5
- data/Gemfile.fluentd.lt.0.10.43 +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 35423c2cf732ed7048b36bb6c4c5882fb2526110
|
|
4
|
+
data.tar.gz: 46dbb7031bfb41f3ea4d7a9acd87dcef14714f3b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33cfd15134ba66af5163ec247b4696708d89960b86fb3a5a67f9ec9dffb33c7db8eabba8b8c8f55542f22e0601452af684fd27e6d134ad640949f955dddaf29e
|
|
7
|
+
data.tar.gz: bab731439abad3a3a7242ff35840d29a305ab9d529aa83f7fe75ba4ee9b5ee5fc811368bebf0b5117478b81987f5d552b2c2c9bd6fe022588ec63588b040318f
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
|
@@ -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.
|
|
17
|
+
gem.version = "0.3.0"
|
|
18
18
|
|
|
19
|
-
gem.add_runtime_dependency "fluentd", [">= 0.
|
|
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, :
|
|
17
|
-
config_param :host, :string, :
|
|
18
|
-
config_param :host_key, :string, :
|
|
19
|
-
config_param :name_keys, :string, :
|
|
20
|
-
config_param :name_key_pattern, :string, :
|
|
21
|
-
config_param :add_key_prefix, :string, :
|
|
22
|
-
config_param :prefix_key, :string, :
|
|
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
|
|
53
|
-
|
|
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
|
|
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({ :
|
|
87
|
-
:
|
|
88
|
-
:
|
|
89
|
-
:
|
|
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({ :
|
|
102
|
-
:
|
|
103
|
-
:
|
|
104
|
-
:
|
|
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
|
-
:
|
|
159
|
-
:
|
|
160
|
-
:
|
|
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, { :
|
|
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
|
|
29
|
-
Fluent::Test::
|
|
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.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
64
|
-
Fluent::Test::
|
|
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
|
|
75
|
-
Fluent::Test::
|
|
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.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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.
|
|
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:
|
|
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:
|
|
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:
|
|
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
|