norikra-listener-zabbix 0.1.0-java → 0.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +66 -1
- data/lib/norikra/listener/zabbix.rb +40 -8
- data/norikra-listener-zabbix.gemspec +2 -2
- data/test/norikra/listener/zabbix_test.rb +36 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce069602d743378669cdad2f175e8a97e5549330
|
4
|
+
data.tar.gz: 45693b0371c948ff8a1f72f1a09a6ea3863f01e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b01185ce11b57ecd936a4754da4253303adf33f19384e8344dd4070788e5526715ad3f61980a50c54bc51ed51b831b8f8902564f51277587ca8f1751d06f776
|
7
|
+
data.tar.gz: cca8426ff06e52f18a6ac90f21e9e1bc5fdb49cb458019bfcd2e12e0b27080dfcb7551bccf70beda60b1b590194192a17980236a252211dd67dae6381da30985
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,72 @@
|
|
1
|
-
#
|
1
|
+
# Norikra::Listener::Zabbix
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/tkuchiki/norikra-listener-zabbix.svg?branch=master)](https://travis-ci.org/tkuchiki/norikra-listener-zabbix)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/github/tkuchiki/norikra-listener-zabbix/badge.svg?branch=master)](https://coveralls.io/github/tkuchiki/norikra-listener-zabbix?branch=master)
|
5
5
|
|
6
|
+
## Description
|
7
|
+
|
6
8
|
Norikra listener plugin to send performance data for Zabbix.
|
7
9
|
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
```shell
|
13
|
+
gem install norikra-listener-zabbix
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Add your query with group `ZABBIX(zabbix_server[:port=10051],zabbix_host[,preifx_item_key])`.
|
19
|
+
|
20
|
+
## Examples
|
21
|
+
|
22
|
+
```sql
|
23
|
+
SELECT sum(foo) AS sum, avg(foo) AS avg FROM test_table.win:time_batch(1 min)
|
24
|
+
-- group ZABBIX(localhost, zabbix host, foo.bar)
|
25
|
+
```
|
26
|
+
|
27
|
+
Send data `sum` and `avg` to item key `foo.bar.sum`, `foo.bar.avg`.
|
28
|
+
|
29
|
+
```sql
|
30
|
+
SELECT sum(foo) AS `bar@foo@sum`, avg(foo) AS `bar@foo@avg` FROM test_table.win:time_batch(1 min)
|
31
|
+
-- group ZABBIX(localhost, zabbix host)
|
32
|
+
```
|
33
|
+
|
34
|
+
Send data `sum` and `avg` to item key `bar.foo.sum`, `bar.foo.avg`.
|
35
|
+
Replace `@` with `.`.
|
36
|
+
|
37
|
+
>Identifiers cannot contain the "." (dot) character, i.e. "vol.price" is not a valid identifier for the rename syntax.
|
38
|
+
|
39
|
+
See: [5.3.4. Renaming event properties](http://www.espertech.com/esper/release-5.2.0/esper-reference/html/epl_clauses.html#epl-select-renaming)
|
40
|
+
|
41
|
+
```sql
|
42
|
+
SELECT sum(foo) AS sum, avg(foo) AS avg FROM test_table.win:time_batch(1 min)
|
43
|
+
-- group ZABBIX([::1], zabbix host)
|
44
|
+
```
|
45
|
+
|
46
|
+
IPv6 syntax `[IPADDR]:PORT`.
|
47
|
+
|
48
|
+
### Zabbix Items
|
49
|
+
|
50
|
+
- Key: `foo.bar.avg`
|
51
|
+
- Type: `Zabbix trapper`
|
52
|
+
- Type of information: `Numeric (float)`
|
53
|
+
|
54
|
+
## Test
|
55
|
+
|
56
|
+
```shell
|
57
|
+
rake [LOGLEVEL=ERROR]
|
58
|
+
```
|
59
|
+
|
60
|
+
```shell
|
61
|
+
rake LOGLEVEL=DEBUG
|
62
|
+
```
|
63
|
+
|
64
|
+
Set loglevel as `DEBUG`.
|
65
|
+
|
66
|
+
## Misc
|
67
|
+
|
68
|
+
Many codes was copied from [fujiwara/fluent-plugin-zabbix](https://github.com/fujiwara/fluent-plugin-zabbix/blob/master/lib/fluent/plugin/out_zabbix.rb).
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
GPLv2
|
@@ -7,7 +7,7 @@ include Norikra::Log
|
|
7
7
|
module Norikra
|
8
8
|
module Listener
|
9
9
|
class Zabbix < Norikra::Listener::Base
|
10
|
-
attr_reader :zabbix_server, :
|
10
|
+
attr_reader :zabbix_server, :zabbix_host, :prefix_item_key, :port
|
11
11
|
|
12
12
|
def self.label
|
13
13
|
"ZABBIX"
|
@@ -17,18 +17,42 @@ module Norikra
|
|
17
17
|
args.split(",").map(&:strip)
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.split_host_port(address)
|
21
|
+
colon = address.count(":")
|
22
|
+
|
23
|
+
case
|
24
|
+
when colon == 0 # IPv4 or FQDN
|
25
|
+
host = address
|
26
|
+
port = 10051
|
27
|
+
when colon == 1 # IPv4 or FQDN
|
28
|
+
hosts = address.split(":")
|
29
|
+
len = hosts.size - 1
|
30
|
+
host = hosts[0, len].join(":")
|
31
|
+
port = hosts[len].to_i
|
32
|
+
when colon >= 2 # IPv6
|
33
|
+
begin
|
34
|
+
hosts = address.match(/\[(.+)\]:?(.+)?/)
|
35
|
+
host = hosts[1]
|
36
|
+
port = (hosts[2] || 10051).to_i
|
37
|
+
rescue
|
38
|
+
host = nil
|
39
|
+
port = nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
[host, port]
|
44
|
+
end
|
45
|
+
|
20
46
|
def initialize(argument, query_name, query_group)
|
21
47
|
super
|
22
48
|
args = Zabbix::parse_argument(argument)
|
23
|
-
@zabbix_server = args[0]
|
24
|
-
@
|
49
|
+
@zabbix_server, @port = Zabbix::split_host_port(args[0])
|
50
|
+
@zabbix_host = args[1]
|
25
51
|
@prefix_item_key = args[2]
|
26
|
-
@port = args[3].nil? ? 10051 : args[3].to_i
|
27
52
|
|
28
53
|
raise Norikra::ArgumentError, "zabbix_server is not specified" unless @zabbix_server
|
29
|
-
raise Norikra::ArgumentError, "host is not specified" unless @host
|
30
|
-
raise Norikra::ArgumentError, "prefix_item_key is not specified" unless @prefix_item_key
|
31
54
|
raise Norikra::ArgumentError, "invalid port: #{@port}" if @port == 0
|
55
|
+
raise Norikra::ArgumentError, "zabbix_host is not specified" unless @zabbix_host
|
32
56
|
end
|
33
57
|
|
34
58
|
def process_async(events)
|
@@ -37,10 +61,10 @@ module Norikra
|
|
37
61
|
events.each do |time, record|
|
38
62
|
t = time if t.nil?
|
39
63
|
record.each do |key, value|
|
40
|
-
data.push({ host: @
|
64
|
+
data.push({ host: @zabbix_host, time: time.to_i, key: format_key(key), value: format_value(value) })
|
41
65
|
end
|
42
66
|
end
|
43
|
-
debug "send data #{@zabbix_sever}:#{@port} #{@
|
67
|
+
debug "send data #{@zabbix_sever}:#{@port} #{@zabbix_host} #{data}"
|
44
68
|
begin
|
45
69
|
send(t, data)
|
46
70
|
rescue => e
|
@@ -48,6 +72,14 @@ module Norikra
|
|
48
72
|
end
|
49
73
|
end
|
50
74
|
|
75
|
+
def format_key(key)
|
76
|
+
if @prefix_item_key.nil? || @prefix_item_key.empty?
|
77
|
+
key.gsub(/\$/, ".")
|
78
|
+
else
|
79
|
+
"#{@prefix_item_key}.#{key}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
51
83
|
# https://github.com/fujiwara/fluent-plugin-zabbix/blob/master/lib/fluent/plugin/out_zabbix.rb
|
52
84
|
|
53
85
|
def format_value(value)
|
@@ -5,12 +5,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "norikra-listener-zabbix"
|
8
|
-
spec.version = "0.
|
8
|
+
spec.version = "0.2.0"
|
9
9
|
spec.authors = ["KUCHIKI Taku"]
|
10
10
|
spec.email = ["kuchiki.taku@gmail.com"]
|
11
11
|
spec.summary = %q{Norikra listener plugin to send performance data for Zabbix.}
|
12
12
|
spec.description = %q{Norikra listener plugin to send performance data for Zabbix.}
|
13
|
-
spec.homepage = "https://github.com/tkuchiki/norikra-
|
13
|
+
spec.homepage = "https://github.com/tkuchiki/norikra-listener-zabbix"
|
14
14
|
spec.license = "GPLv2"
|
15
15
|
spec.platform = "java"
|
16
16
|
|
@@ -35,21 +35,48 @@ class Norikra::Listener::ZabbixTest < Minitest::Test
|
|
35
35
|
assert_equal Norikra::Listener::Zabbix.parse_argument(" localhost, zabbix-host , prefix "), args
|
36
36
|
end
|
37
37
|
|
38
|
+
def test_split_host_port
|
39
|
+
assert_equal Norikra::Listener::Zabbix.split_host_port("localhost"), ["localhost", 10051]
|
40
|
+
assert_equal Norikra::Listener::Zabbix.split_host_port("localhost:60051"), ["localhost", 60051]
|
41
|
+
assert_equal Norikra::Listener::Zabbix.split_host_port("127.0.0.1"), ["127.0.0.1", 10051]
|
42
|
+
assert_equal Norikra::Listener::Zabbix.split_host_port("127.0.0.1:60051"), ["127.0.0.1", 60051]
|
43
|
+
assert_equal Norikra::Listener::Zabbix.split_host_port("[::1]"), ["::1", 10051]
|
44
|
+
assert_equal Norikra::Listener::Zabbix.split_host_port("[::1]:60051"), ["::1", 60051]
|
45
|
+
assert_equal Norikra::Listener::Zabbix.split_host_port("[2001:DB8:0:0:8:800:200C:417A]"), ["2001:DB8:0:0:8:800:200C:417A", 10051]
|
46
|
+
assert_equal Norikra::Listener::Zabbix.split_host_port("[2001:DB8:0:0:8:800:200C:417A]:60051"), ["2001:DB8:0:0:8:800:200C:417A", 60051]
|
47
|
+
assert_equal Norikra::Listener::Zabbix.split_host_port("::1"), [nil, nil]
|
48
|
+
assert_equal Norikra::Listener::Zabbix.split_host_port("::1:60051"), [nil, nil]
|
49
|
+
end
|
50
|
+
|
38
51
|
def test_initialize
|
39
52
|
args = ["localhost", "zabbix-host", "prefix"]
|
40
53
|
listener = Norikra::Listener::Zabbix.new("localhost,zabbix-host,prefix", "query_name", "ZABBIX(localhost,zabbix-host,prefix)")
|
41
54
|
assert_equal listener.zabbix_server, args[0]
|
42
|
-
assert_equal listener.
|
55
|
+
assert_equal listener.zabbix_host, args[1]
|
43
56
|
assert_equal listener.prefix_item_key, args[2]
|
44
57
|
assert_equal listener.port, 10051
|
45
58
|
|
46
|
-
listener = Norikra::Listener::Zabbix.new("localhost,zabbix-host,prefix
|
59
|
+
listener = Norikra::Listener::Zabbix.new("localhost:60051,zabbix-host,prefix", "query_name", "ZABBIX(localhost:60051,zabbix-host,prefix)")
|
47
60
|
assert_equal listener.zabbix_server, args[0]
|
48
|
-
assert_equal listener.
|
61
|
+
assert_equal listener.zabbix_host, args[1]
|
49
62
|
assert_equal listener.prefix_item_key, args[2]
|
50
63
|
assert_equal listener.port, 60051
|
51
64
|
end
|
52
65
|
|
66
|
+
def test_format_key
|
67
|
+
listener = Norikra::Listener::Zabbix.new("localhost,zabbix-host,prefix", "query_name", "ZABBIX(localhost,zabbix-host,prefix)")
|
68
|
+
assert_equal "prefix.foo", listener.format_key("foo")
|
69
|
+
|
70
|
+
listener = Norikra::Listener::Zabbix.new("localhost,zabbix-host,prefix.foo", "query_name", "ZABBIX(localhost,zabbix-host,prefix)")
|
71
|
+
assert_equal "prefix.foo.bar", listener.format_key("bar")
|
72
|
+
|
73
|
+
listener = Norikra::Listener::Zabbix.new("localhost,zabbix-host", "query_name", "ZABBIX(localhost,zabbix-host,prefix)")
|
74
|
+
assert_equal "foobar", listener.format_key("foobar")
|
75
|
+
|
76
|
+
listener = Norikra::Listener::Zabbix.new("localhost,zabbix-host", "query_name", "ZABBIX(localhost,zabbix-host,prefix)")
|
77
|
+
assert_equal "foo.bar.baz", listener.format_key("foo$bar$baz")
|
78
|
+
end
|
79
|
+
|
53
80
|
def test_format_value
|
54
81
|
listener = Norikra::Listener::Zabbix.new("localhost,zabbix-host,prefix", "query_name", "ZABBIX(localhost,zabbix-host,prefix)")
|
55
82
|
assert_equal "1.2345", listener.format_value(1.23454) # round off
|
@@ -70,7 +97,7 @@ class Norikra::Listener::ZabbixTest < Minitest::Test
|
|
70
97
|
end
|
71
98
|
t = do_tcpserver(response)
|
72
99
|
|
73
|
-
listener = Norikra::Listener::Zabbix.new("localhost,zabbix-host,prefix
|
100
|
+
listener = Norikra::Listener::Zabbix.new("localhost:#{@port},zabbix-host,prefix", "query_name", "ZABBIX(localhost:#{@port},zabbix-host,prefix)")
|
74
101
|
epoch = Time.now.to_i
|
75
102
|
data = [{ host: "zabbix-host", time: epoch, key: "prefix.val1", value: 1.2345 }]
|
76
103
|
refute listener.send(epoch, data)
|
@@ -90,7 +117,11 @@ class Norikra::Listener::ZabbixTest < Minitest::Test
|
|
90
117
|
end
|
91
118
|
t = do_tcpserver(response)
|
92
119
|
|
93
|
-
listener = Norikra::Listener::Zabbix.new("localhost,zabbix-host,prefix
|
120
|
+
listener = Norikra::Listener::Zabbix.new("localhost:#{@port},zabbix-host,prefix", "query_name", "ZABBIX(localhost:#{@port},zabbix-host,prefix)")
|
121
|
+
assert listener.process_async([[1454556814, {"val1"=>0, "val2"=>1.2345,}]])
|
122
|
+
|
123
|
+
# IPv6
|
124
|
+
listener = Norikra::Listener::Zabbix.new("[::1]:#{@port},zabbix-host,prefix", "query_name", "ZABBIX([::1]:#{@port},zabbix-host,prefix)")
|
94
125
|
assert listener.process_async([[1454556814, {"val1"=>0, "val2"=>1.2345,}]])
|
95
126
|
|
96
127
|
t.exit
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: norikra-listener-zabbix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- KUCHIKI Taku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,7 +112,7 @@ files:
|
|
112
112
|
- norikra-listener-zabbix.gemspec
|
113
113
|
- test/norikra/listener/zabbix_test.rb
|
114
114
|
- test/test_helper.rb
|
115
|
-
homepage: https://github.com/tkuchiki/norikra-
|
115
|
+
homepage: https://github.com/tkuchiki/norikra-listener-zabbix
|
116
116
|
licenses:
|
117
117
|
- GPLv2
|
118
118
|
metadata: {}
|