zabbix_receiver 0.0.2 → 0.0.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: b9b18abfc85a6f0c988942665b7764545131a0e5
4
- data.tar.gz: e4ff56edf7bbfd4ba960881f25db18ab9156cbda
3
+ metadata.gz: 6bb55e93057af6f74f3a28e11eeea044c38b78d0
4
+ data.tar.gz: 5369d40a344d0973b03fffcba444af51de44b6ee
5
5
  SHA512:
6
- metadata.gz: 39fcb740b7dc74ea719ac4dc330e52f28aa9202db534669527eb1b4b7f80aee4d3319f49dbdf6808518fe9a0d091c369d092c5cdbf113275e562e745beba5356
7
- data.tar.gz: 4d755551630c848207a7174b93804c9ef63244197666da6d7109a597e21d41bc7df077a8e372e641d616d4d00950641dc7a2d3df2986b4a5d158810db22023ea
6
+ metadata.gz: 6ece7c04f1eb7379f87d570d915f1f8989d327c96ddc481ed8c637ee49bf2af4d7adc6733bbca81ca0c4fb834aa6615431aa09ea2a92b83521b04f8a7fb1c920
7
+ data.tar.gz: 8638037e040dcd4bcbf6050ddac7e841d32f363918fc684fde44030dbee39061a0bf27ee703eec827aeb32c1873cc082c8b3295a121baf625708995e57fcdcd5
@@ -1,11 +1,9 @@
1
1
  require 'zabbix_receiver'
2
2
  require 'serverengine'
3
- require 'optparse'
3
+ require 'slop'
4
4
 
5
5
  module ZabbixReceiver
6
6
  class CLI
7
- REQUIRED_OPTIONS = %i(daemonize workers proxy_to_host proxy_to_port bind port)
8
-
9
7
  def self.start(argv)
10
8
  self.new(argv).start
11
9
  end
@@ -26,45 +24,44 @@ module ZabbixReceiver
26
24
  private
27
25
 
28
26
  def load_options(argv)
29
- argv_for_main, argv_for_output = argv.slice_before('--').to_a
30
- argv_for_output.shift
27
+ output_type = argv.first
28
+ output_class = get_output_class(output_type)
29
+ if output_class
30
+ argv.shift # output type
31
+ else
32
+ output_type = 'stdout'
33
+ output_class = get_output_class(output_type)
34
+ end
31
35
 
32
- @options = {
33
- daemonize: false,
34
- workers: 1,
35
- bind: '0.0.0.0',
36
- port: 10051,
37
- proxy_to_port: 10051,
38
- to: 'stdout',
39
- }
36
+ puts "Using #{output_type} output."
40
37
 
41
- parser = OptionParser.new
42
- parser.on('--daemonize') {|v| @options[:daemonize] = true }
43
- parser.on('--log=VAL', 'default: STDERR') {|v| @options[:log] = v }
44
- parser.on('--pid-path=VAL') {|v| @options[:pid_path] = v }
45
- parser.on('--workers=VAL') {|v| @options[:worker] = v }
46
- parser.on('--bind=VAL') {|v| @options[:bind] = v }
47
- parser.on('--port=VAL') {|v| @options[:port] = v }
48
- parser.on('--proxy-to-host=VAL') {|v| @options[:proxy_to_host] = v }
49
- parser.on('--proxy-to-port=VAL') {|v| @options[:proxy_to_port] = v }
50
- parser.on('--to=VAL') {|v| @options[:to] = v }
51
- parser.on('--log-level=VAL') {|v| @options[:log_level] = v }
52
- parser.parse!(argv_for_main)
38
+ opts = Slop::Options.new
39
+ opts.on('--help') { puts opts; exit }
40
+ opts.bool '--daemonize', default: false
41
+ opts.string '--log'
42
+ opts.string '--pid-path'
43
+ opts.integer '--workers', default: 1
44
+ opts.string '--bind', default: '0.0.0.0'
45
+ opts.integer '--port', default: 10051
46
+ opts.string '--proxy-to-host'
47
+ opts.integer '--proxy-to-port', default: 10051
48
+ opts.string '--log-level'
49
+ output_class.add_options(opts)
53
50
 
54
- REQUIRED_OPTIONS.each do |key|
55
- unless @options.has_key?(key)
56
- raise "--#{key.to_s.split('_').join('-')} option is required."
57
- end
58
- end
51
+ parser = Slop::Parser.new(opts)
52
+ @options = Hash[parser.parse(argv).to_hash.map do |k, v|
53
+ [k.to_s.tr('-', '_').to_sym, v]
54
+ end]
59
55
 
60
56
  @options[:output_class] = output_class
61
- @options[:output_options] = @options[:output_class].parse_options(argv_for_output)
62
57
  end
63
58
 
64
- def output_class
65
- require "zabbix_receiver/output/#{@options[:to]}"
66
- class_name = @options[:to].split('_').map {|v| v.capitalize }.join
59
+ def get_output_class(type)
60
+ require "zabbix_receiver/output/#{type}"
61
+ class_name = type.split('_').map {|v| v.capitalize }.join
67
62
  ZabbixReceiver::Output.const_get(class_name)
63
+ rescue NameError, LoadError
64
+ nil
68
65
  end
69
66
  end
70
67
  end
@@ -1,15 +1,16 @@
1
1
  module ZabbixReceiver
2
2
  module Output
3
3
  class Stdout
4
- def self.parse_options(argv)
5
- {}
4
+ def self.add_options(opts)
5
+ opts.string '--indent', default: ''
6
6
  end
7
7
 
8
8
  def initialize(logger, options)
9
+ @options = options
9
10
  end
10
11
 
11
12
  def receive_sender_data(data)
12
- puts data
13
+ puts @options[:indent] + data.inspect
13
14
  end
14
15
  end
15
16
  end
@@ -1,3 +1,3 @@
1
1
  module ZabbixReceiver
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -5,7 +5,7 @@ module ZabbixReceiver
5
5
  ZABBIX_HEADER = "ZBXD\x01"
6
6
 
7
7
  def run
8
- @output = config[:output_class].new(logger, config[:output_options])
8
+ @output = config[:output_class].new(logger, config)
9
9
 
10
10
  until @stop
11
11
  process(server.sock.accept)
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "zabbix_receiver"
8
8
  spec.version = ZabbixReceiver::VERSION
9
9
  spec.authors = ["Ryota Arai"]
10
- spec.email = ["ryota-arai@cookpad.com"]
10
+ spec.email = ["ryota.arai@gmail.com"]
11
11
  spec.summary = %q{Server to receive sender data from zabbix-agent.}
12
12
  spec.homepage = ""
13
13
  spec.license = "MIT"
@@ -17,7 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_development_dependency "serverengine"
20
+ spec.add_dependency "serverengine", "~> 1.5.10"
21
+ spec.add_dependency "slop"
21
22
 
22
23
  spec.add_development_dependency "bundler", "~> 1.7"
23
24
  spec.add_development_dependency "rake", "~> 10.0"
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
@@ -12,12 +12,26 @@ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: serverengine
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: slop
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
18
32
  - !ruby/object:Gem::Version
19
33
  version: '0'
20
- type: :development
34
+ type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
@@ -68,7 +82,7 @@ dependencies:
68
82
  version: '0'
69
83
  description:
70
84
  email:
71
- - ryota-arai@cookpad.com
85
+ - ryota.arai@gmail.com
72
86
  executables:
73
87
  - zabbix_receiver
74
88
  extensions: []