fluent-plugin-zabbix 0.0.7 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 778dffb330bf90f5e65b9bab2b57ca3fb29bbee6
4
- data.tar.gz: 26d030c79c0680a76a387e0edb61e2ddd9ecf5d5
3
+ metadata.gz: 75f72ffcfce03e77cff9b5181a4ebacc94d7db7b
4
+ data.tar.gz: 048a1130e81d421c05de2a97b81cfeeacfdef764
5
5
  SHA512:
6
- metadata.gz: bb3f14d22487dc1b29002b447da2459ec2905e4ab46ab98a2ae779bae45fe4544444b0f2619dbca70f9a40a81bebd03ea1c08903546f41e62368761cdd2fd860
7
- data.tar.gz: a198b9002377c9adb801dab673193c12f2a29964e3d3bf04bcb9eeed40cb7e5de86d3100748b8bd9ee31a55b47d28414185695271f51efc009675b29dad1e578
6
+ metadata.gz: 2e6ae91ae3b89670755efc4fb6393262f92b69fc102e82b012546f41eac873f638fd8e0a24feef5f5dc6218a7ec0d959b3230fe42cba34d4ead309905694e83d
7
+ data.tar.gz: bb5192c9d7e75aaacacba47880c1cb87d869c88ccb622a0ef73cb83e75d768eaa0606ecc5bbb911bd62858e8c7675a739a77f4bb100bbf85b6cfb7b11cd7066f
data/.travis.yml CHANGED
@@ -2,7 +2,12 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.1
5
+ - 2.1
6
+ - 2.2
6
7
  gemfile:
7
8
  - Gemfile
8
9
  - Gemfile.fluentd.lt.0.10.43
10
+ matrix:
11
+ exclude:
12
+ - rvm: 2.2
13
+ - gemfile: Gemfile.fluentd.lt.0.10.43
@@ -13,11 +13,12 @@ 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.7"
16
+ gem.version = "0.1.0"
17
17
 
18
18
  gem.add_runtime_dependency "fluentd", "~> 0.10"
19
19
  gem.add_runtime_dependency "yajl-ruby", "~> 1.0"
20
20
  gem.add_runtime_dependency "fluent-mixin-config-placeholders", "~> 0.3"
21
21
  gem.add_development_dependency "rake", ">= 0.9.2"
22
22
  gem.add_development_dependency "glint", "= 0.0.2"
23
+ gem.add_development_dependency "test-unit", ">= 3.1.0"
23
24
  end
@@ -55,25 +55,13 @@ class Fluent::ZabbixOutput < Fluent::Output
55
55
  super
56
56
  end
57
57
 
58
- def send(host, tag, name, value, time)
59
- if @add_key_prefix
60
- if @add_key_prefix == '${tag}'
61
- name = "#{tag}.#{name}"
62
- else
63
- name = "#{@add_key_prefix}.#{name}"
64
- end
58
+ def send(time, bulk)
59
+ bulk.each do |d|
65
60
  end
66
61
  begin
67
62
  sock = TCPSocket.open(@zabbix_server, @port)
68
- log.debug("zabbix: #{sock} #{name}: #{value}, host: #{host}, ts: #{time}")
69
- if value.kind_of? Float
70
- # https://www.zabbix.com/documentation/2.4/manual/config/items/item
71
- # > Allowed range (for MySQL): -999999999999.9999 to 999999999999.9999 (double(16,4)).
72
- # > Starting with Zabbix 2.2, receiving values in scientific notation is also supported. E.g. 1e+70, 1e-70.
73
- status = send_to_zabbix(sock, host, name, value.round(4).to_s, time)
74
- else
75
- status = send_to_zabbix(sock, host, name, value.to_s, time)
76
- end
63
+ log.debug("zabbix: #{sock} #{bulk}, ts: #{time}")
64
+ status = send_to_zabbix(sock, time, bulk)
77
65
  rescue => e
78
66
  log.warn "plugin-zabbix: raises exception: #{e}"
79
67
  status = false
@@ -82,7 +70,7 @@ class Fluent::ZabbixOutput < Fluent::Output
82
70
  end
83
71
 
84
72
  unless status
85
- log.warn "plugin-zabbix: failed to send to zabbix_server: #{@zabbix_server}:#{@port}, host:#{host} '#{name}': #{value}"
73
+ log.warn "plugin-zabbix: failed to send to zabbix_server: #{@zabbix_server}:#{@port} #{bulk}"
86
74
  end
87
75
  end
88
76
 
@@ -90,20 +78,32 @@ class Fluent::ZabbixOutput < Fluent::Output
90
78
  if @name_keys
91
79
  es.each {|time,record|
92
80
  host = gen_host(record)
93
- @name_keys.each {|name|
94
- if record[name]
95
- send(host, tag, name, record[name], time)
81
+ bulk = []
82
+ @name_keys.each {|key|
83
+ if record[key]
84
+ bulk.push({ :key => format_key(tag, key),
85
+ :value => format_value(record[key]),
86
+ :host => host,
87
+ :time => time.to_i,
88
+ })
96
89
  end
97
90
  }
91
+ send(time, bulk) if bulk.size > 0
98
92
  }
99
93
  else # for name_key_pattern
100
94
  es.each {|time,record|
101
95
  host = gen_host(record)
96
+ bulk = []
102
97
  record.keys.each {|key|
103
- if @name_key_pattern.match(key) and record[key]
104
- send(host, tag, key, record[key], time)
98
+ if @name_key_pattern.match(key) && record[key]
99
+ bulk.push({ :key => format_key(tag, key),
100
+ :value => format_value(record[key]),
101
+ :host => host,
102
+ :time => time.to_i,
103
+ })
105
104
  end
106
105
  }
106
+ send(time, bulk) if bulk.size > 0
107
107
  }
108
108
  end
109
109
  chain.next
@@ -123,17 +123,34 @@ class Fluent::ZabbixOutput < Fluent::Output
123
123
  return host
124
124
  end
125
125
 
126
- def send_to_zabbix(sock, host, key, value, time)
127
- data = {
128
- :host => host,
129
- :key => key,
130
- :value => value.to_s,
131
- :time => time.to_i,
132
- }
126
+ def format_key(tag, key)
127
+ if @add_key_prefix
128
+ if @add_key_prefix == '${tag}'
129
+ "#{tag}.#{key}"
130
+ else
131
+ "#{@add_key_prefix}.#{key}"
132
+ end
133
+ else
134
+ key
135
+ end
136
+ end
137
+
138
+ def format_value(value)
139
+ if value.kind_of? Float
140
+ # https://www.zabbix.com/documentation/2.4/manual/config/items/item
141
+ # > Allowed range (for MySQL): -999999999999.9999 to 999999999999.9999 (double(16,4)).
142
+ # > Starting with Zabbix 2.2, receiving values in scientific notation is also supported. E.g. 1e+70, 1e-70.
143
+ value.round(4).to_s
144
+ else
145
+ value.to_s
146
+ end
147
+ end
148
+
149
+ def send_to_zabbix(sock, time, bulk)
133
150
  req = Yajl::Encoder.encode({
134
151
  :request => 'agent data',
135
152
  :clock => time.to_i,
136
- :data => [ data ],
153
+ :data => bulk,
137
154
  })
138
155
  sock.write(ZBXD + [ req.size ].pack('q') + req)
139
156
  sock.flush
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.7
4
+ version: 0.1.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: 2015-05-13 00:00:00.000000000 Z
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.0.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-unit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0
83
97
  description: Output data plugin to Zabbix
84
98
  email:
85
99
  - fujiwara.shunichiro@gmail.com
@@ -118,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
132
  version: '0'
119
133
  requirements: []
120
134
  rubyforge_project:
121
- rubygems_version: 2.2.2
135
+ rubygems_version: 2.4.5
122
136
  signing_key:
123
137
  specification_version: 4
124
138
  summary: Output data plugin to Zabbix (like zabbix_sender)