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 +5 -5
- data/.travis.yml +1 -0
- data/Rakefile +1 -1
- data/fluent-plugin-zabbix.gemspec +3 -4
- data/lib/fluent/plugin/out_zabbix.rb +25 -42
- data/{mockserver → test}/mockserver.go +1 -2
- data/test/plugin/test_out_zabbix.rb +39 -39
- metadata +12 -27
- data/Gemfile.fluentd.lt.0.10.43 +0 -5
- data/mockserver/go.mod +0 -5
- data/mockserver/go.sum +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
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,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.
|
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"
|
23
|
-
gem.add_development_dependency "glint", "= 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, :
|
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
|
@@ -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\
|
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 "
|
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, { :
|
15
|
-
exec "./mockserver
|
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
|
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
|
-
now = Time.now.to_i
|
35
35
|
if ENV['LIVE_TEST']
|
36
|
-
d.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
47
|
-
host:test_host key:test.bar value:test value of bar
|
48
|
-
host:test_host key:test.baz value:123.4567
|
49
|
-
host:test_host key:test.foo value:yyy
|
50
|
-
host:test_host key:test.f1 value:0.0
|
51
|
-
host:test_host key:test.f2 value:0.01
|
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
|
65
|
-
Fluent::Test::
|
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
|
76
|
-
Fluent::Test::
|
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.
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
91
|
-
host:alternative-hostname key:test.foo value:BBB
|
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.
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
107
|
-
host:test_host key:p.foo value:BBB
|
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.
|
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,20 +16,20 @@ 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
|
-
version: '
|
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:
|
29
|
+
version: 0.14.8
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
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.
|
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.
|
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
|
-
|
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
|
data/Gemfile.fluentd.lt.0.10.43
DELETED
data/mockserver/go.mod
DELETED
data/mockserver/go.sum
DELETED