zabbix_receiver 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bb55e93057af6f74f3a28e11eeea044c38b78d0
4
- data.tar.gz: 5369d40a344d0973b03fffcba444af51de44b6ee
3
+ metadata.gz: 16d7639b10ddad739cc71e5027b0093fc3ea50cc
4
+ data.tar.gz: 1344cfc43519e4993c99a2cc12bc7a380b50360e
5
5
  SHA512:
6
- metadata.gz: 6ece7c04f1eb7379f87d570d915f1f8989d327c96ddc481ed8c637ee49bf2af4d7adc6733bbca81ca0c4fb834aa6615431aa09ea2a92b83521b04f8a7fb1c920
7
- data.tar.gz: 8638037e040dcd4bcbf6050ddac7e841d32f363918fc684fde44030dbee39061a0bf27ee703eec827aeb32c1873cc082c8b3295a121baf625708995e57fcdcd5
6
+ metadata.gz: 02f603fa3f485493b43bcdbbb880d44aadb31c57d860c63f315f1a984db94a5fc158c80a441b985aed028dc51ee904f4efb31c3e6bda73e3e5514b0af775b1f0
7
+ data.tar.gz: 46a7bb932afd96a319448ed2bb725e3a2ee0a2d97e9a6383ae16b6b0da4f69b6999ef762a2e7eade89bccee870411f8962202746d1940d41e40866cbb171fb63
data/README.md CHANGED
@@ -1,26 +1,24 @@
1
1
  # ZabbixReceiver
2
2
 
3
- TODO: Write a gem description
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'zabbix_receiver'
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
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install zabbix_receiver
17
+ ## Installation and Usage
20
18
 
21
- ## Usage
19
+ See:
22
20
 
23
- TODO: Write usage instructions here
21
+ - https://github.com/ryotarai/zabbix_receiver-fluentd
24
22
 
25
23
  ## Contributing
26
24
 
@@ -1,3 +1,3 @@
1
1
  module ZabbixReceiver
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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
- @output.receive_sender_data(request)
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::Server do
4
- let(:options) { {
5
- proxy_to: {
6
- host: 'zabbix-server',
7
- port: 'port',
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
- describe '#accept' do
13
- context 'with sender data' do
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
- received_data = nil
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 'with active checks' do
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 'proxies a request to zabbix server' do
44
- allow(socket_to_zabbix_server).to receive(:seek)
40
+ it "proxies a request to zabbix server" do
41
+ io = StringIO.new(request.dup)
45
42
 
46
- expect(TCPSocket).to receive(:open).with('zabbix-server', 'port').and_return(socket_to_zabbix_server)
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
- io = StringIO.new(request.dup)
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.3
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/server_spec.rb
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/server_spec.rb
133
+ - spec/zabbix_receiver/worker_spec.rb