fluent-plugin-zabbix 0.0.1 → 0.0.2
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 +7 -0
- data/README.rdoc +11 -0
- data/fluent-plugin-zabbix.gemspec +3 -4
- data/lib/fluent/plugin/out_zabbix.rb +24 -8
- data/test/plugin/test_out_zabbix.rb +32 -5
- metadata +44 -58
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf49b619e8d3bcfa0f2e1e456964d19d6a557b66
|
4
|
+
data.tar.gz: 644a96eb558d5b7abd91bf54711bf75a37f2ad0c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed4f648a53075202cabc361d164d6b53091e25acbed2a08b6138d5c102376533fee1225a25700ab3c5534bb64bfd46f22856bc44f5f003404e54c83919927997
|
7
|
+
data.tar.gz: 9bb6bf01b9fe8b0cd5982890b1b2460e68343841e50abcbb1d7795365a4642a5b5c5f42b1e115d366f867f89edd44793a6bd59a2b04902cebbb0ecaf4f0f2c60
|
data/README.rdoc
CHANGED
@@ -41,6 +41,17 @@ or, use "add_keys_prefix"
|
|
41
41
|
name_key_pattern ^field
|
42
42
|
</match>
|
43
43
|
|
44
|
+
If you want to specify the host(on zabbix) from record's value, use "host_key" directive.
|
45
|
+
|
46
|
+
tag:metrics {"zabbix_host":"myhostname", "metrics.field1":300, "metrics.field2":20}
|
47
|
+
|
48
|
+
<match metrics>
|
49
|
+
type zabbix
|
50
|
+
zabbix_server 192.168.0.1
|
51
|
+
host_key zabbix_host
|
52
|
+
name_keys metrics.field1,metrics.field2
|
53
|
+
</match>
|
54
|
+
|
44
55
|
== TODO
|
45
56
|
|
46
57
|
- patches welcome!
|
@@ -13,9 +13,8 @@ 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.2"
|
17
17
|
|
18
|
-
gem.
|
19
|
-
gem.add_runtime_dependency "
|
20
|
-
gem.add_runtime_dependency "zabbix"
|
18
|
+
gem.add_runtime_dependency "fluentd", "~> 0.10"
|
19
|
+
gem.add_runtime_dependency "zabbix", ">= 0.4"
|
21
20
|
end
|
@@ -10,6 +10,7 @@ class Fluent::ZabbixOutput < Fluent::Output
|
|
10
10
|
config_param :zabbix_server, :string
|
11
11
|
config_param :port, :integer, :default => 10051
|
12
12
|
config_param :host, :string, :default => Socket.gethostname
|
13
|
+
config_param :host_key, :string, :default => nil
|
13
14
|
config_param :name_keys, :string, :default => nil
|
14
15
|
config_param :name_key_pattern, :string, :default => nil
|
15
16
|
config_param :add_key_prefix, :string, :default => nil
|
@@ -43,45 +44,60 @@ class Fluent::ZabbixOutput < Fluent::Output
|
|
43
44
|
super
|
44
45
|
end
|
45
46
|
|
46
|
-
def send(tag, name, value, time)
|
47
|
+
def send(host, tag, name, value, time)
|
47
48
|
if @add_key_prefix
|
48
49
|
name = "#{@add_key_prefix}.#{name}"
|
49
50
|
end
|
50
51
|
begin
|
51
52
|
zbx = Zabbix::Sender.new(:host => @zabbix_server, :port => @port)
|
52
|
-
$log.debug("zabbix: #{zbx}, #{name}: #{value}, host: #{
|
53
|
-
|
54
|
-
opts = { :host => @host, :ts => time }
|
53
|
+
$log.debug("zabbix: #{zbx}, #{name}: #{value}, host: #{host}, ts: #{time}")
|
54
|
+
opts = { :host => host, :ts => time }
|
55
55
|
status = zbx.send_data(name, value.to_s, opts)
|
56
56
|
|
57
57
|
rescue IOError, EOFError, SystemCallError
|
58
58
|
# server didn't respond
|
59
|
-
$log.warn "Zabbix::Sender.send_data raises exception: #{$!.class}, '#{$!.message}'"
|
59
|
+
$log.warn "plugin-zabbix: Zabbix::Sender.send_data raises exception: #{$!.class}, '#{$!.message}'"
|
60
60
|
status = false
|
61
61
|
end
|
62
62
|
unless status
|
63
|
-
$log.warn "failed to send to zabbix_server: #{@zabbix_server}:#{@port}, host:#{
|
63
|
+
$log.warn "plugin-zabbix: failed to send to zabbix_server: #{@zabbix_server}:#{@port}, host:#{host} '#{name}': #{value}"
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
def emit(tag, es, chain)
|
68
68
|
if @name_keys
|
69
69
|
es.each {|time,record|
|
70
|
+
host = gen_host(record)
|
70
71
|
@name_keys.each {|name|
|
71
72
|
if record[name]
|
72
|
-
send(tag, name, record[name], time)
|
73
|
+
send(host, tag, name, record[name], time)
|
73
74
|
end
|
74
75
|
}
|
75
76
|
}
|
76
77
|
else # for name_key_pattern
|
77
78
|
es.each {|time,record|
|
79
|
+
host = gen_host(record)
|
78
80
|
record.keys.each {|key|
|
79
81
|
if @name_key_pattern.match(key) and record[key]
|
80
|
-
send(tag, key, record[key], time)
|
82
|
+
send(host, tag, key, record[key], time)
|
81
83
|
end
|
82
84
|
}
|
83
85
|
}
|
84
86
|
end
|
85
87
|
chain.next
|
86
88
|
end
|
89
|
+
|
90
|
+
def gen_host(record)
|
91
|
+
if @host_key
|
92
|
+
if record[@host_key]
|
93
|
+
host = record[@host_key]
|
94
|
+
else
|
95
|
+
$log.warn "plugin-zabbix: host_key is configured '#{@host_key}', but this record has no such key. use host '#{@host}'"
|
96
|
+
host = @host
|
97
|
+
end
|
98
|
+
else
|
99
|
+
host = @host
|
100
|
+
end
|
101
|
+
return host
|
102
|
+
end
|
87
103
|
end
|
@@ -7,7 +7,7 @@ class ZabbixOutputTest < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
CONFIG = %[
|
9
9
|
zabbix_server 127.0.0.1
|
10
|
-
host
|
10
|
+
host test_host
|
11
11
|
add_key_prefix test
|
12
12
|
name_keys foo, bar, baz
|
13
13
|
]
|
@@ -17,9 +17,36 @@ class ZabbixOutputTest < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_write
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
d = create_driver
|
21
|
+
if ENV['LIVE_TEST']
|
22
|
+
d.emit({"foo" => "test value of foo"})
|
23
|
+
d.emit({"bar" => "test value of bar"})
|
24
|
+
d.emit({"baz" => rand * 10 })
|
25
|
+
d.emit({"foo" => "yyy", "zabbix_host" => "alternative-hostname"})
|
26
|
+
d.run
|
27
|
+
end
|
24
28
|
end
|
29
|
+
|
30
|
+
|
31
|
+
CONFIG_HOST_KEY = %[
|
32
|
+
zabbix_server 127.0.0.1
|
33
|
+
host test_host
|
34
|
+
host_key host
|
35
|
+
add_key_prefix test
|
36
|
+
name_keys foo, bar, baz
|
37
|
+
]
|
38
|
+
|
39
|
+
def create_driver_host_key(conf = CONFIG_HOST_KEY, tag='test')
|
40
|
+
Fluent::Test::OutputTestDriver.new(Fluent::ZabbixOutput, tag).configure(conf)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_write_host_key
|
44
|
+
d = create_driver_host_key
|
45
|
+
if ENV['LIVE_TEST']
|
46
|
+
d.emit({"foo" => "AAA" })
|
47
|
+
d.emit({"foo" => "BBB", "host" => "alternative-hostname"})
|
48
|
+
d.run
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
25
52
|
end
|
metadata
CHANGED
@@ -1,61 +1,51 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-zabbix
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- FUJIWARA Shunichiro
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: fluentd
|
17
|
-
prerelease: false
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
24
|
-
type: :development
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
27
14
|
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.10'
|
20
|
+
type: :runtime
|
28
21
|
prerelease: false
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: zabbix
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
32
31
|
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.4'
|
35
34
|
type: :runtime
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: zabbix
|
39
35
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
43
38
|
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version:
|
46
|
-
type: :runtime
|
47
|
-
version_requirements: *id003
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.4'
|
48
41
|
description: Output data plugin to Zabbix
|
49
|
-
email:
|
42
|
+
email:
|
50
43
|
- fujiwara.shunichiro@gmail.com
|
51
44
|
executables: []
|
52
|
-
|
53
45
|
extensions: []
|
54
|
-
|
55
46
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
|
58
|
-
- .gitignore
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
59
49
|
- Gemfile
|
60
50
|
- LICENSE
|
61
51
|
- README.rdoc
|
@@ -66,31 +56,27 @@ files:
|
|
66
56
|
- test/plugin/test_out_zabbix.rb
|
67
57
|
homepage: https://github.com/fujiwara/fluent-plugin-zabbix
|
68
58
|
licenses: []
|
69
|
-
|
59
|
+
metadata: {}
|
70
60
|
post_install_message:
|
71
61
|
rdoc_options: []
|
72
|
-
|
73
|
-
require_paths:
|
62
|
+
require_paths:
|
74
63
|
- lib
|
75
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
|
77
|
-
requirements:
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
78
66
|
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version:
|
81
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
-
|
83
|
-
requirements:
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
84
71
|
- - ">="
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
version:
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
87
74
|
requirements: []
|
88
|
-
|
89
75
|
rubyforge_project:
|
90
|
-
rubygems_version:
|
76
|
+
rubygems_version: 2.2.0
|
91
77
|
signing_key:
|
92
|
-
specification_version:
|
78
|
+
specification_version: 4
|
93
79
|
summary: Output data plugin to Zabbix (like zabbix_sender)
|
94
|
-
test_files:
|
80
|
+
test_files:
|
95
81
|
- test/helper.rb
|
96
82
|
- test/plugin/test_out_zabbix.rb
|