zabbix_protocol 0.1.4 → 0.1.5.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67c7b17dd4b63ade76364acfb3b28c210aca1982
4
- data.tar.gz: c4b185dc8941064df32696c631fdc404cf5c963c
3
+ metadata.gz: a62768171ebe8a4628070f57c06e1c7926e9e25a
4
+ data.tar.gz: 06884716424ddcb37733ffe44e1540b7b0ecfc67
5
5
  SHA512:
6
- metadata.gz: fcd39d464d79479dcc0bfbb89adfe133d115fdb8544a3dc6a7842fa0004c7877c278e5ec4b63a3bf2f86f54cd17c2ee136c302f4d032c765fe2c2a1778016c65
7
- data.tar.gz: f86b19d6b0fb50a391ab9fe9372129c5985b76ef1f5c212d42455507391fc578204e9230ebbaac58e4f70fc504dc121930ab0fd5cbb7d29738cdfbf751d10818
6
+ metadata.gz: b96e8c4175247e9acb3727753a72ae8f1149b72b0da732d9bc3fbd04b3035c77d0102668b3eba7ba58da4f0c1560067f705b3509fb804ad3e4b5be53719bb538
7
+ data.tar.gz: 212615a265fde21f1efae21b0ae0f16566c90976fbd211cb07cadb9fb527cd06071cfe0b214fb4773aedc6dcec619dbb3015cf003cfad55d55e26630c3adbd8b
data/.travis.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ - jruby-19mode
4
7
  script:
5
8
  - bundle install
6
9
  - bundle exec rake
@@ -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.length + ZABBIX_VERSION.length + PAYLOAD_LEN_BYTES
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.length].pack('Q'),
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
- if data.length < MIN_DATA_LEN
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.length)
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.length)
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.length
56
- raise Error, "invalid payload length: expected=#{payload_len}, actual=#{sliced.length} (data: #{data.inspect})"
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,3 @@
1
1
  module ZabbixProtocol
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5.beta"
3
3
  end
@@ -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: "\u0002" (data: "ZBXD\u0002\b\u0000\u0000\u0000\u0000\u0000\u0000\u00001.000000")'
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\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u00001.000000")'
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
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-09-13 00:00:00.000000000 Z
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: '0'
105
+ version: 1.3.1
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.0.14
108
+ rubygems_version: 2.4.8
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: Zabbix protocols builder/parser.