zabbix_protocol 0.1.2 → 0.1.3

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: 213565fc54f02a1b972de73fec7051a43f3e402a
4
- data.tar.gz: 1c765a2e9b10acfa8fdd5165c3d5ecc192980e3a
3
+ metadata.gz: b24c8ba95636d6a46255007187c03a3092e14a8c
4
+ data.tar.gz: 7482b470bee62de53a1af853ec0818e160627410
5
5
  SHA512:
6
- metadata.gz: 02f4a321facacce7f61f74bd07e868c4bb2b15ab81ade4c9394cc1dfebd1f98dec9d375aae859ed9967da76c2d801326edd0133ee7b082c03963d8c44b0e3697
7
- data.tar.gz: a8a80824b2e352e19ab7725133e53d0988c2b5013d2aca91a14dd4c91e0d60ea071f4a086c56856bae9d7063094c0d246c8ad3c6acb6bb718f9c988406a72f28
6
+ metadata.gz: b631c8bcaf4dda3dc6ff73e569973153761fbf46ffde4cdd6684f9a19d39a5612ba947f3b2b67045a55acc13a2ec7dad39e6b8f89f847178e36518f509abca77
7
+ data.tar.gz: 9e45a2f07297fc37620c569a5b623f9c512d63060f649c8212b4f1cb6f0de858fb287655e615e14b5a6c128207869784580e419b74b23270171117ade7fce5ee
@@ -1,3 +1,3 @@
1
1
  module ZabbixProtocol
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -8,22 +8,22 @@ module ZabbixProtocol
8
8
  # http://www.zabbix.org/wiki/Docs/protocols/zabbix_agent/1.4
9
9
  ZABBIX_HEADER = "ZBXD"
10
10
  ZABBIX_VERSION = "\x01"
11
- DATA_LEN_BYTES = 8
11
+ PAYLOAD_LEN_BYTES = 8
12
12
 
13
- MIN_RESPONSE_LEN = ZABBIX_HEADER.length + ZABBIX_VERSION.length + DATA_LEN_BYTES
13
+ MIN_DATA_LEN = ZABBIX_HEADER.length + ZABBIX_VERSION.length + PAYLOAD_LEN_BYTES
14
14
 
15
- def self.dump(data)
16
- if data.is_a?(Hash)
17
- data = MultiJson.dump(data)
15
+ def self.dump(payload)
16
+ if payload.is_a?(Hash)
17
+ payload = MultiJson.dump(payload)
18
18
  else
19
- data = data.to_s
19
+ payload = payload.to_s
20
20
  end
21
21
 
22
22
  [
23
23
  ZABBIX_HEADER,
24
24
  ZABBIX_VERSION,
25
- [data.length].pack('Q'),
26
- data
25
+ [payload.length].pack('Q'),
26
+ payload
27
27
  ].join
28
28
  end
29
29
 
@@ -32,32 +32,32 @@ module ZabbixProtocol
32
32
  raise TypeError, "wrong argument type #{data.class} (expected String)"
33
33
  end
34
34
 
35
- if data.length < MIN_RESPONSE_LEN
35
+ if data.length < MIN_DATA_LEN
36
36
  raise Error, "data length is too short (data: #{data.inspect})"
37
37
  end
38
38
 
39
- data = data.dup
40
- header = data.slice!(0, ZABBIX_HEADER.length)
39
+ sliced = data.dup
40
+ header = sliced.slice!(0, ZABBIX_HEADER.length)
41
41
 
42
42
  if header != ZABBIX_HEADER
43
43
  raise Error, "invalid header: #{header.inspect} (data: #{data.inspect})"
44
44
  end
45
45
 
46
- version = data.slice!(0, ZABBIX_VERSION.length)
46
+ version = sliced.slice!(0, ZABBIX_VERSION.length)
47
47
 
48
48
  if version != ZABBIX_VERSION
49
49
  raise Error, "unsupported version: #{version.inspect} (data: #{data.inspect})"
50
50
  end
51
51
 
52
- data_len = data.slice!(0, DATA_LEN_BYTES)
53
- data_len = data_len.unpack("Q").first
52
+ payload_len = sliced.slice!(0, PAYLOAD_LEN_BYTES)
53
+ payload_len = payload_len.unpack("Q").first
54
54
 
55
- if data_len != data.length
56
- raise Error, "invalid data length: expected=#{data_len}, actual=#{data.length} (data: #{data.inspect})"
55
+ if payload_len != sliced.length
56
+ raise Error, "invalid payload length: expected=#{payload_len}, actual=#{sliced.length} (data: #{data.inspect})"
57
57
  end
58
58
 
59
59
  begin
60
- MultiJson.load(data)
60
+ MultiJson.load(sliced)
61
61
  rescue MultiJson::ParseError
62
62
  data
63
63
  end
@@ -55,14 +55,14 @@ describe ZabbixProtocol do
55
55
  expect {
56
56
  res_data = "ZBXD\x02\b\x00\x00\x00\x00\x00\x00\x001.000000"
57
57
  subject.load(res_data)
58
- }.to raise_error 'unsupported version: "\\u0002" (data: "\b\u0000\u0000\u0000\u0000\u0000\u0000\u00001.000000")'
58
+ }.to raise_error 'unsupported version: "\u0002" (data: "ZBXD\u0002\b\u0000\u0000\u0000\u0000\u0000\u0000\u00001.000000")'
59
59
  end
60
60
 
61
- it "raise error when invalid data length" do
61
+ it "raise error when invalid payload length" do
62
62
  expect {
63
63
  res_data = "ZBXD\x01\x00\x00\x00\x00\x00\x00\x00\x001.000000"
64
64
  subject.load(res_data)
65
- }.to raise_error 'invalid data length: expected=0, actual=8 (data: "1.000000")'
65
+ }.to raise_error 'invalid payload length: expected=0, actual=8 (data: "ZBXD\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u00001.000000")'
66
66
  end
67
67
  end
68
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbix_protocol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara