fluent-plugin-zabbix 0.2.3 → 0.3.1
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 +5 -5
- data/.github/dependabot.yml +8 -0
- data/.github/workflows/test.yml +23 -0
- data/.travis.yml +1 -0
- data/README.md +2 -0
- data/Rakefile +1 -1
- data/fluent-plugin-zabbix.gemspec +3 -3
- data/lib/fluent/plugin/out_zabbix.rb +25 -42
- data/mockserver/go.mod +5 -0
- data/mockserver/go.sum +2 -0
- data/{test → mockserver}/mockserver.go +2 -1
- data/test/plugin/test_out_zabbix.rb +42 -35
- metadata +12 -11
- data/Gemfile.fluentd.lt.0.10.43 +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 97c7b621772f409af613b565d2b734e55786b00618297de55a53ece1949caf9e
|
4
|
+
data.tar.gz: a1e9d865a2bade7536f5c4ba886706640616f3a794066a267bf75971d4da1b38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36a71a4ea7e3b9f3188d976f301b7fbde974d5ccd7580a234332f7f8b0d93cb8848d52b5700cb7bb786539a869daedf617f5b1e4e8f18601cf814b8dea063cfd
|
7
|
+
data.tar.gz: 598ac514f14971ae29a3e7f3d548806dcf7af2649bf8b341fb944a5647b4ead579be81cefd997aaa53c2e706da14e3a9cab57076b3cec45f3684aeebdf3cfd87
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: test
|
2
|
+
on: [push]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
strategy:
|
7
|
+
matrix:
|
8
|
+
ruby: ["2.7", "3.0", "3.1", "3.2"]
|
9
|
+
name: test on Ruby ${{ matrix.ruby }}
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v4
|
12
|
+
- uses: actions/setup-go@v5
|
13
|
+
with:
|
14
|
+
go-version: "1.21"
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby }}
|
18
|
+
bundler-cache: true
|
19
|
+
- run: bundle install
|
20
|
+
- run: |
|
21
|
+
bundle exec rake test
|
22
|
+
env:
|
23
|
+
LIVE_TEST: 1
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -14,12 +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.1"
|
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.0
|
23
|
+
gem.add_development_dependency "glint", "= 0.1.0"
|
24
24
|
gem.add_development_dependency "test-unit", ">= 3.1.0"
|
25
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
|
+
clock: 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
|
+
clock: 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
|
data/mockserver/go.mod
ADDED
data/mockserver/go.sum
ADDED
@@ -31,10 +31,11 @@ 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\n",
|
34
|
+
"host:%s\tkey:%s\tvalue:%s\tclock:%d\n",
|
35
35
|
d.Host,
|
36
36
|
d.Key,
|
37
37
|
d.Value,
|
38
|
+
d.Clock,
|
38
39
|
)
|
39
40
|
Output.Write([]byte(line))
|
40
41
|
}
|
@@ -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 "go
|
7
|
+
system "sh -c 'cd mockserver && go build 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", $dir.to_s + "/trapper.log"
|
15
|
+
$server = Glint::Server.new(10051, { timeout: 3 }) do |port|
|
16
|
+
exec "./mockserver/mockserver", $dir.to_s + "/trapper.log"
|
16
17
|
end
|
17
18
|
$server.start
|
18
19
|
end
|
@@ -25,29 +26,31 @@ 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
|
35
|
+
now = Time.now.to_i
|
34
36
|
if ENV['LIVE_TEST']
|
35
|
-
d.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
d.run() do
|
38
|
+
d.feed('test', now, {"foo" => "test value of foo"})
|
39
|
+
d.feed('test', now, {"bar" => "test value of bar"})
|
40
|
+
d.feed('test', now, {"baz" => 123.4567 })
|
41
|
+
d.feed('test', now, {"foo" => "yyy", "zabbix_host" => "alternative-hostname"})
|
42
|
+
d.feed('test', now, {"f1" => 0.000001})
|
43
|
+
d.feed('test', now, {"f2" => 0.01})
|
44
|
+
sleep 1
|
45
|
+
end
|
43
46
|
$server.stop
|
44
47
|
assert_equal open($dir + "/trapper.log").read, <<END
|
45
|
-
host:test_host key:test.foo value:test value of foo
|
46
|
-
host:test_host key:test.bar value:test value of bar
|
47
|
-
host:test_host key:test.baz value:123.4567
|
48
|
-
host:test_host key:test.foo value:yyy
|
49
|
-
host:test_host key:test.f1 value:0.0
|
50
|
-
host:test_host key:test.f2 value:0.01
|
48
|
+
host:test_host key:test.foo value:test value of foo clock:#{now}
|
49
|
+
host:test_host key:test.bar value:test value of bar clock:#{now}
|
50
|
+
host:test_host key:test.baz value:123.4567 clock:#{now}
|
51
|
+
host:test_host key:test.foo value:yyy clock:#{now}
|
52
|
+
host:test_host key:test.f1 value:0.0 clock:#{now}
|
53
|
+
host:test_host key:test.f2 value:0.01 clock:#{now}
|
51
54
|
END
|
52
55
|
end
|
53
56
|
end
|
@@ -60,8 +63,8 @@ END
|
|
60
63
|
name_keys foo, bar, baz
|
61
64
|
]
|
62
65
|
|
63
|
-
def create_driver_host_key(conf = CONFIG_HOST_KEY
|
64
|
-
Fluent::Test::
|
66
|
+
def create_driver_host_key(conf = CONFIG_HOST_KEY)
|
67
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::ZabbixOutput).configure(conf)
|
65
68
|
end
|
66
69
|
|
67
70
|
CONFIG_PREFIX_KEY = %[
|
@@ -71,36 +74,40 @@ END
|
|
71
74
|
name_keys foo, bar, baz
|
72
75
|
]
|
73
76
|
|
74
|
-
def create_driver_prefix_key(conf = CONFIG_PREFIX_KEY
|
75
|
-
Fluent::Test::
|
77
|
+
def create_driver_prefix_key(conf = CONFIG_PREFIX_KEY)
|
78
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::ZabbixOutput).configure(conf)
|
76
79
|
end
|
77
80
|
|
78
81
|
def test_write_host_key
|
79
82
|
d = create_driver_host_key
|
83
|
+
now = Time.now.to_i
|
80
84
|
if ENV['LIVE_TEST']
|
81
|
-
d.
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
+
d.run() do
|
86
|
+
d.feed('test', now, {"foo" => "AAA" })
|
87
|
+
d.feed('test', now, {"foo" => "BBB", "host" => "alternative-hostname"})
|
88
|
+
sleep 1
|
89
|
+
end
|
85
90
|
$server.stop
|
86
91
|
assert_equal open($dir + "/trapper.log").read, <<END
|
87
|
-
host:test_host key:test.foo value:AAA
|
88
|
-
host:alternative-hostname key:test.foo value:BBB
|
92
|
+
host:test_host key:test.foo value:AAA clock:#{now}
|
93
|
+
host:alternative-hostname key:test.foo value:BBB clock:#{now}
|
89
94
|
END
|
90
95
|
end
|
91
96
|
end
|
92
97
|
|
93
98
|
def test_write_prefix_key
|
94
99
|
d = create_driver_prefix_key
|
100
|
+
now = Time.now.to_i
|
95
101
|
if ENV['LIVE_TEST']
|
96
|
-
d.
|
97
|
-
|
98
|
-
|
99
|
-
|
102
|
+
d.run() do
|
103
|
+
d.feed('test', now, {"foo" => "AAA"})
|
104
|
+
d.feed('test', now, {"foo" => "BBB", "prefix" => "p"})
|
105
|
+
sleep 1
|
106
|
+
end
|
100
107
|
$server.stop
|
101
108
|
assert_equal open($dir + "/trapper.log").read, <<END
|
102
|
-
host:test_host key:foo value:AAA
|
103
|
-
host:test_host key:p.foo value:BBB
|
109
|
+
host:test_host key:foo value:AAA clock:#{now}
|
110
|
+
host:test_host key:p.foo value:BBB clock:#{now}
|
104
111
|
END
|
105
112
|
end
|
106
113
|
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.1
|
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: 2023-12-20 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'
|
@@ -78,14 +78,14 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - '='
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 0.0
|
81
|
+
version: 0.1.0
|
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.0
|
88
|
+
version: 0.1.0
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: test-unit
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,17 +107,20 @@ executables: []
|
|
107
107
|
extensions: []
|
108
108
|
extra_rdoc_files: []
|
109
109
|
files:
|
110
|
+
- ".github/dependabot.yml"
|
111
|
+
- ".github/workflows/test.yml"
|
110
112
|
- ".gitignore"
|
111
113
|
- ".travis.yml"
|
112
114
|
- Gemfile
|
113
|
-
- Gemfile.fluentd.lt.0.10.43
|
114
115
|
- LICENSE
|
115
116
|
- README.md
|
116
117
|
- Rakefile
|
117
118
|
- fluent-plugin-zabbix.gemspec
|
118
119
|
- lib/fluent/plugin/out_zabbix.rb
|
120
|
+
- mockserver/go.mod
|
121
|
+
- mockserver/go.sum
|
122
|
+
- mockserver/mockserver.go
|
119
123
|
- test/helper.rb
|
120
|
-
- test/mockserver.go
|
121
124
|
- test/plugin/test_out_zabbix.rb
|
122
125
|
homepage: https://github.com/fujiwara/fluent-plugin-zabbix
|
123
126
|
licenses:
|
@@ -138,12 +141,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
141
|
- !ruby/object:Gem::Version
|
139
142
|
version: '0'
|
140
143
|
requirements: []
|
141
|
-
|
142
|
-
rubygems_version: 2.6.11
|
144
|
+
rubygems_version: 3.4.10
|
143
145
|
signing_key:
|
144
146
|
specification_version: 4
|
145
147
|
summary: Output data plugin to Zabbix (like zabbix_sender)
|
146
148
|
test_files:
|
147
149
|
- test/helper.rb
|
148
|
-
- test/mockserver.go
|
149
150
|
- test/plugin/test_out_zabbix.rb
|