zabbix_protocol 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zabbix_protocol/version.rb +1 -1
- data/lib/zabbix_protocol.rb +9 -10
- data/spec/zabbix_protocol_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba8ff0426cf78193691e25d0ca9e578beb0f8691
|
4
|
+
data.tar.gz: 4a66154c9a451c5b9f98b7fa680eca2042967d9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be5dd593ea6e29a70dfbad6ee50f6214b23ca175e7079436868c9ab353ac63b1c06e72ed9785b5af351acc022f34d25a2c4cab69540e02cf470ec3aedaec6ae3
|
7
|
+
data.tar.gz: e3a7099d791633c090684ab9c4c85e31e456d628b6731a47f8a692b3e48f1cd28904429a08c4a06a9e5c7079054f9281976521fcd48decf0e941afa1f0c00e58
|
data/lib/zabbix_protocol.rb
CHANGED
@@ -6,23 +6,22 @@ module ZabbixProtocol
|
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
8
|
# http://www.zabbix.org/wiki/Docs/protocols/zabbix_agent/1.4
|
9
|
-
|
10
|
-
|
9
|
+
ZABBIX_HEADER = "ZBXD"
|
10
|
+
ZABBIX_VERSION = "\x01"
|
11
11
|
DATA_LEN_BYTES = 8
|
12
12
|
|
13
|
-
MIN_RESPONSE_LEN =
|
13
|
+
MIN_RESPONSE_LEN = ZABBIX_HEADER.length + ZABBIX_VERSION.length + DATA_LEN_BYTES
|
14
14
|
|
15
15
|
def self.dump(data)
|
16
16
|
if data.is_a?(Hash)
|
17
17
|
data = MultiJson.dump(data)
|
18
18
|
else
|
19
19
|
data = data.to_s
|
20
|
-
data << "\n" unless data =~ /\n\z/
|
21
20
|
end
|
22
21
|
|
23
22
|
[
|
24
|
-
|
25
|
-
|
23
|
+
ZABBIX_HEADER,
|
24
|
+
ZABBIX_VERSION,
|
26
25
|
[data.length].pack('Q'),
|
27
26
|
data
|
28
27
|
].join
|
@@ -38,15 +37,15 @@ module ZabbixProtocol
|
|
38
37
|
end
|
39
38
|
|
40
39
|
data = res_data.dup
|
41
|
-
header = data.slice!(0,
|
40
|
+
header = data.slice!(0, ZABBIX_HEADER.length)
|
42
41
|
|
43
|
-
if header !=
|
42
|
+
if header != ZABBIX_HEADER
|
44
43
|
raise Error, "invalid header: #{header.inspect}"
|
45
44
|
end
|
46
45
|
|
47
|
-
version = data.slice!(0,
|
46
|
+
version = data.slice!(0, ZABBIX_VERSION.length)
|
48
47
|
|
49
|
-
if version !=
|
48
|
+
if version != ZABBIX_VERSION
|
50
49
|
raise Error, "unsupported version: #{version.inspect}"
|
51
50
|
end
|
52
51
|
|
@@ -4,8 +4,8 @@ describe ZabbixProtocol do
|
|
4
4
|
context "when request" do
|
5
5
|
it "should convert string to zabbix request" do
|
6
6
|
res = subject.dump("system.cpu.load[all,avg1]")
|
7
|
-
expect(res).to eq "ZBXD\x01\
|
8
|
-
"system.cpu.load[all,avg1]
|
7
|
+
expect(res).to eq "ZBXD\x01\x19\x00\x00\x00\x00\x00\x00\x00" +
|
8
|
+
"system.cpu.load[all,avg1]"
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should convert hash to zabbix request" do
|