zabbix_protocol 0.1.4 → 0.1.5.beta
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 +4 -4
- data/.travis.yml +4 -1
- data/lib/zabbix_protocol.rb +12 -7
- data/lib/zabbix_protocol/version.rb +1 -1
- data/spec/zabbix_protocol_spec.rb +25 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a62768171ebe8a4628070f57c06e1c7926e9e25a
|
4
|
+
data.tar.gz: 06884716424ddcb37733ffe44e1540b7b0ecfc67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b96e8c4175247e9acb3727753a72ae8f1149b72b0da732d9bc3fbd04b3035c77d0102668b3eba7ba58da4f0c1560067f705b3509fb804ad3e4b5be53719bb538
|
7
|
+
data.tar.gz: 212615a265fde21f1efae21b0ae0f16566c90976fbd211cb07cadb9fb527cd06071cfe0b214fb4773aedc6dcec619dbb3015cf003cfad55d55e26630c3adbd8b
|
data/.travis.yml
CHANGED
data/lib/zabbix_protocol.rb
CHANGED
@@ -10,7 +10,7 @@ module ZabbixProtocol
|
|
10
10
|
ZABBIX_VERSION = "\x01"
|
11
11
|
PAYLOAD_LEN_BYTES = 8
|
12
12
|
|
13
|
-
MIN_DATA_LEN = ZABBIX_HEADER.
|
13
|
+
MIN_DATA_LEN = ZABBIX_HEADER.bytesize + ZABBIX_VERSION.bytesize + PAYLOAD_LEN_BYTES
|
14
14
|
|
15
15
|
def self.dump(payload)
|
16
16
|
if payload.is_a?(Hash)
|
@@ -19,10 +19,12 @@ module ZabbixProtocol
|
|
19
19
|
payload = payload.to_s
|
20
20
|
end
|
21
21
|
|
22
|
+
payload.force_encoding('ASCII-8BIT')
|
23
|
+
|
22
24
|
[
|
23
25
|
ZABBIX_HEADER,
|
24
26
|
ZABBIX_VERSION,
|
25
|
-
[payload.
|
27
|
+
[payload.bytesize].pack('Q'),
|
26
28
|
payload
|
27
29
|
].join
|
28
30
|
end
|
@@ -32,18 +34,21 @@ module ZabbixProtocol
|
|
32
34
|
raise TypeError, "wrong argument type #{data.class} (expected String)"
|
33
35
|
end
|
34
36
|
|
35
|
-
|
37
|
+
data = data.dup
|
38
|
+
data.force_encoding('ASCII-8BIT')
|
39
|
+
|
40
|
+
if data.bytesize < MIN_DATA_LEN
|
36
41
|
raise Error, "data length is too short (data: #{data.inspect})"
|
37
42
|
end
|
38
43
|
|
39
44
|
sliced = data.dup
|
40
|
-
header = sliced.slice!(0, ZABBIX_HEADER.
|
45
|
+
header = sliced.slice!(0, ZABBIX_HEADER.bytesize)
|
41
46
|
|
42
47
|
if header != ZABBIX_HEADER
|
43
48
|
raise Error, "invalid header: #{header.inspect} (data: #{data.inspect})"
|
44
49
|
end
|
45
50
|
|
46
|
-
version = sliced.slice!(0, ZABBIX_VERSION.
|
51
|
+
version = sliced.slice!(0, ZABBIX_VERSION.bytesize)
|
47
52
|
|
48
53
|
if version != ZABBIX_VERSION
|
49
54
|
raise Error, "unsupported version: #{version.inspect} (data: #{data.inspect})"
|
@@ -52,8 +57,8 @@ module ZabbixProtocol
|
|
52
57
|
payload_len = sliced.slice!(0, PAYLOAD_LEN_BYTES)
|
53
58
|
payload_len = payload_len.unpack("Q").first
|
54
59
|
|
55
|
-
if payload_len != sliced.
|
56
|
-
raise Error, "invalid payload length: expected=#{payload_len}, actual=#{sliced.
|
60
|
+
if payload_len != sliced.bytesize
|
61
|
+
raise Error, "invalid payload length: expected=#{payload_len}, actual=#{sliced.bytesize} (data: #{data.inspect})"
|
57
62
|
end
|
58
63
|
|
59
64
|
begin
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
describe ZabbixProtocol do
|
2
4
|
subject { described_class }
|
3
5
|
|
@@ -22,6 +24,27 @@ describe ZabbixProtocol do
|
|
22
24
|
expect(res).to eq "ZBXD\x01Z\x00\x00\x00\x00\x00\x00\x00" +
|
23
25
|
'{"request":"sender.data","data":[{"host":"LinuxDB3","key":"db.connections","value":"43"}]}'
|
24
26
|
end
|
27
|
+
|
28
|
+
context "when multibyte character" do
|
29
|
+
it "should convert hash to zabbix request" do
|
30
|
+
req_data = {
|
31
|
+
"request" => "sender.data",
|
32
|
+
"data" => [{
|
33
|
+
"host" => "LinuxDB3",
|
34
|
+
"key" => "multibyte.item",
|
35
|
+
"value" => "ййццууккееннггшшщщ"
|
36
|
+
}]
|
37
|
+
}
|
38
|
+
|
39
|
+
res = subject.dump(req_data)
|
40
|
+
|
41
|
+
expected = "ZBXD\x01|\x00\x00\x00\x00\x00\x00\x00" +
|
42
|
+
%!{"request":"sender.data","data":[{"host":"LinuxDB3","key":"multibyte.item","value":"\xD0\xB9\xD0\xB9\xD1\x86\xD1\x86\xD1\x83\xD1\x83\xD0\xBA\xD0\xBA\xD0\xB5\xD0\xB5\xD0\xBD\xD0\xBD\xD0\xB3\xD0\xB3\xD1\x88\xD1\x88\xD1\x89\xD1\x89"}]}!
|
43
|
+
expected.force_encoding('ASCII-8BIT')
|
44
|
+
|
45
|
+
expect(res).to eq expected
|
46
|
+
end
|
47
|
+
end
|
25
48
|
end
|
26
49
|
|
27
50
|
context "when response" do
|
@@ -55,14 +78,14 @@ describe ZabbixProtocol do
|
|
55
78
|
expect {
|
56
79
|
res_data = "ZBXD\x02\b\x00\x00\x00\x00\x00\x00\x001.000000"
|
57
80
|
subject.load(res_data)
|
58
|
-
}.to raise_error 'unsupported version: "\
|
81
|
+
}.to raise_error 'unsupported version: "\x02" (data: "ZBXD\x02\b\x00\x00\x00\x00\x00\x00\x001.000000")'
|
59
82
|
end
|
60
83
|
|
61
84
|
it "raise error when invalid payload length" do
|
62
85
|
expect {
|
63
86
|
res_data = "ZBXD\x01\x00\x00\x00\x00\x00\x00\x00\x001.000000"
|
64
87
|
subject.load(res_data)
|
65
|
-
}.to raise_error 'invalid payload length: expected=0, actual=8 (data: "ZBXD\
|
88
|
+
}.to raise_error 'invalid payload length: expected=0, actual=8 (data: "ZBXD\x01\x00\x00\x00\x00\x00\x00\x00\x001.000000")'
|
66
89
|
end
|
67
90
|
|
68
91
|
it "should parse error message" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabbix_protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -100,12 +100,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
|
-
- - '
|
103
|
+
- - '>'
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
105
|
+
version: 1.3.1
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.4.8
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Zabbix protocols builder/parser.
|