zabbix_receiver 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -17
- data/lib/zabbix_receiver/version.rb +1 -1
- data/lib/zabbix_receiver/worker.rb +9 -2
- data/spec/zabbix_receiver/{server_spec.rb → worker_spec.rb} +29 -31
- 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: 16d7639b10ddad739cc71e5027b0093fc3ea50cc
|
4
|
+
data.tar.gz: 1344cfc43519e4993c99a2cc12bc7a380b50360e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02f603fa3f485493b43bcdbbb880d44aadb31c57d860c63f315f1a984db94a5fc158c80a441b985aed028dc51ee904f4efb31c3e6bda73e3e5514b0af775b1f0
|
7
|
+
data.tar.gz: 46a7bb932afd96a319448ed2bb725e3a2ee0a2d97e9a6383ae16b6b0da4f69b6999ef762a2e7eade89bccee870411f8962202746d1940d41e40866cbb171fb63
|
data/README.md
CHANGED
@@ -1,26 +1,24 @@
|
|
1
1
|
# ZabbixReceiver
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
```
|
4
|
+
+--------------+ +-----------------+ +-----------------------+
|
5
|
+
| | | | | |
|
6
|
+
| Zabbix Agent +-------> zabbix_receiver +-------------> Output (like Fluentd) |
|
7
|
+
| | | | sender data | |
|
8
|
+
+--------------+ +----------+------+ +-----------------------+
|
9
|
+
|
|
10
|
+
| +---------------+
|
11
|
+
| | |
|
12
|
+
+------> Zabbix Server |
|
13
|
+
active checks | |
|
14
|
+
+---------------+
|
11
15
|
```
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install zabbix_receiver
|
17
|
+
## Installation and Usage
|
20
18
|
|
21
|
-
|
19
|
+
See:
|
22
20
|
|
23
|
-
|
21
|
+
- https://github.com/ryotarai/zabbix_receiver-fluentd
|
24
22
|
|
25
23
|
## Contributing
|
26
24
|
|
@@ -4,8 +4,11 @@ module ZabbixReceiver
|
|
4
4
|
module Worker
|
5
5
|
ZABBIX_HEADER = "ZBXD\x01"
|
6
6
|
|
7
|
+
def output
|
8
|
+
@output ||= config[:output_class].new(logger, config)
|
9
|
+
end
|
10
|
+
|
7
11
|
def run
|
8
|
-
@output = config[:output_class].new(logger, config)
|
9
12
|
|
10
13
|
until @stop
|
11
14
|
process(server.sock.accept)
|
@@ -26,7 +29,7 @@ module ZabbixReceiver
|
|
26
29
|
when 'active checks'
|
27
30
|
c.write(proxy_request(request_body))
|
28
31
|
when 'sender data'
|
29
|
-
|
32
|
+
output.receive_sender_data(request)
|
30
33
|
|
31
34
|
count = request['data'].size
|
32
35
|
|
@@ -36,6 +39,10 @@ module ZabbixReceiver
|
|
36
39
|
})
|
37
40
|
else
|
38
41
|
logger.error "Unknown request type (#{request_type})"
|
42
|
+
respond_with(c, {
|
43
|
+
"response" => "success",
|
44
|
+
"info" => ""
|
45
|
+
})
|
39
46
|
end
|
40
47
|
ensure
|
41
48
|
c.close
|
@@ -1,57 +1,55 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'logger'
|
2
3
|
|
3
|
-
describe ZabbixReceiver::
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
describe ZabbixReceiver::Worker do
|
5
|
+
subject(:worker) do
|
6
|
+
double(:worker).extend(described_class)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:output) { double(:output) }
|
10
|
+
let(:config) { {
|
11
|
+
proxy_to_host: 'zabbix-server',
|
12
|
+
proxy_to_port: 'port',
|
9
13
|
} }
|
10
|
-
subject(:server) { described_class.new(options) }
|
11
14
|
|
12
|
-
|
13
|
-
|
15
|
+
before do
|
16
|
+
allow(worker).to receive(:logger).and_return(Logger.new(open('/dev/null', 'w')))
|
17
|
+
allow(worker).to receive(:output).and_return(output)
|
18
|
+
allow(worker).to receive(:config).and_return(config)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#process" do
|
22
|
+
context "with sender data" do
|
14
23
|
let(:request) { "ZBXD\u0001b\u0000\u0000\u0000\u0000\u0000\u0000\u0000{\n\t\"request\":\"sender data\",\n\t\"data\":[\n\t\t{\n\t\t\t\"host\":\"hello\",\n\t\t\t\"key\":\"key\",\n\t\t\t\"value\":\"value\"}]}" }
|
24
|
+
it "receives sender data" do
|
25
|
+
expect(output).to receive(:receive_sender_data).with({"request"=>"sender data", "data"=>[{"host"=>"hello", "key"=>"key", "value"=>"value"}]})
|
15
26
|
|
16
|
-
it 'receives sender data' do
|
17
27
|
io = StringIO.new(request.dup)
|
18
28
|
|
19
|
-
|
20
|
-
server.on_receive_sender_data do |data|
|
21
|
-
received_data = data
|
22
|
-
end
|
23
|
-
|
24
|
-
server.accept(io)
|
29
|
+
worker.process(io)
|
25
30
|
expected_response = "ZBXD\u0001S\u0000\u0000\u0000\u0000\u0000\u0000\u0000{\"response\":\"success\",\"info\":\"Processed 1 Failed 0 Total 1 Seconds spent 0.000000\"}"
|
26
31
|
expect(io.string).to eq(request + expected_response)
|
27
|
-
expect(received_data).to eq({
|
28
|
-
'request' => 'sender data',
|
29
|
-
'data' => [{
|
30
|
-
'host' => 'hello',
|
31
|
-
'key' => 'key',
|
32
|
-
'value' => 'value',
|
33
|
-
}],
|
34
|
-
})
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
|
-
context
|
35
|
+
context "with active checks" do
|
39
36
|
let(:socket_to_zabbix_server) { double(:socket) }
|
40
37
|
let(:request) { "ZBXD\u0001)\x00\x00\x00\x00\x00\x00\x00{\"request\":\"active checks\",\"key\":\"value\"}" }
|
41
38
|
let(:response) { "response_from_zabbix_server" }
|
42
39
|
|
43
|
-
it
|
44
|
-
|
40
|
+
it "proxies a request to zabbix server" do
|
41
|
+
io = StringIO.new(request.dup)
|
45
42
|
|
46
|
-
expect(TCPSocket).to receive(:open).
|
43
|
+
expect(TCPSocket).to receive(:open).
|
44
|
+
with('zabbix-server', 'port').
|
45
|
+
and_return(socket_to_zabbix_server)
|
47
46
|
expect(socket_to_zabbix_server).to receive(:close)
|
48
47
|
expect(socket_to_zabbix_server).to receive(:write).with(request)
|
49
48
|
expect(socket_to_zabbix_server).to receive(:read).and_return(response)
|
50
49
|
|
51
|
-
|
52
|
-
server.accept(io)
|
53
|
-
expect(io.string).to eq(request + response)
|
50
|
+
worker.process(io)
|
54
51
|
end
|
55
52
|
end
|
56
53
|
end
|
57
54
|
end
|
55
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabbix_receiver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Arai
|
@@ -102,7 +102,7 @@ files:
|
|
102
102
|
- lib/zabbix_receiver/version.rb
|
103
103
|
- lib/zabbix_receiver/worker.rb
|
104
104
|
- spec/spec_helper.rb
|
105
|
-
- spec/zabbix_receiver/
|
105
|
+
- spec/zabbix_receiver/worker_spec.rb
|
106
106
|
- zabbix_receiver.gemspec
|
107
107
|
homepage: ''
|
108
108
|
licenses:
|
@@ -130,4 +130,4 @@ specification_version: 4
|
|
130
130
|
summary: Server to receive sender data from zabbix-agent.
|
131
131
|
test_files:
|
132
132
|
- spec/spec_helper.rb
|
133
|
-
- spec/zabbix_receiver/
|
133
|
+
- spec/zabbix_receiver/worker_spec.rb
|