riemann-babbler 0.6.2 → 0.6.3

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.
data/bin/riemann-babbler CHANGED
@@ -10,6 +10,7 @@ require 'sequel'
10
10
 
11
11
  require File.expand_path('../../lib/riemann/version', __FILE__)
12
12
  require File.expand_path('../../lib/deep_merge', __FILE__)
13
+ require File.expand_path('../../lib/start_helpers', __FILE__)
13
14
  require File.expand_path('../../lib/riemann/babbler/plugin', __FILE__)
14
15
 
15
16
  opts = Trollop::options do
@@ -28,77 +29,8 @@ end
28
29
  # logger
29
30
  logger = Logger.new(STDOUT)
30
31
 
31
- # merge configs
32
- config_file = if File.exist?( opts[:config] )
33
- YAML.load_file( opts[:config] ).to_hash
34
- else
35
- logger.error "Can't load config file #{opts[:config]}"
36
- Hash.new
37
- end
38
-
39
- config_default = YAML.load_file( File.expand_path('../../config.yml', __FILE__) )
40
-
41
- config = config_default.deep_merge( config_file )
42
- configatron.configure_from_hash config
43
-
44
- # set logger lvl
45
- case configatron.logger.level
46
- when "INFO"
47
- logger.level = Logger::INFO
48
- when "WARN"
49
- logger.level = Logger::WARN
50
- when "ERROR"
51
- logger.level = Logger::ERROR
52
- when "FATAL"
53
- logger.level = Logger::FATAL
54
- when "UNKNOWN"
55
- logger.level = Logger::UNKNOWN
56
- else
57
- logger.level = Logger::DEBUG
58
- end
59
-
60
-
61
- # get plugins
62
- plugins = []
63
- default_plugins_dir = File.expand_path('../../lib/riemann/babbler/plugins/', __FILE__)
64
- Dir.glob( default_plugins_dir + "/*.rb" ) do |file|
65
- plugins << file
66
- end
67
-
68
- unless configatron.plugins.dirs.nil?
69
- configatron.plugins.dirs.each do |dir|
70
- next unless Dir.exist? dir
71
- Dir.glob( dir + "/*.rb" ) do |file|
72
- plugins << file
73
- end
74
- end
75
- end
76
-
77
- unless configatron.plugins.files.nil?
78
- configatron.plugins.files.each do |file|
79
- plugins << file
80
- end
81
- end
82
-
83
- # set riemann client
84
- riemann_ip = Resolv.new.getaddress(configatron.riemann.host)
85
- riemann = Riemann::Client.new(
86
- :host => riemann_ip,
87
- :port => configatron.riemann.port
88
- )
89
- riemann = ( configatron.riemann.proto == 'tcp' ) ? riemann.tcp : riemann
90
-
91
- # start plugins
92
- plugins.each { |plugin| require plugin }
93
-
94
- plugin_threads = Riemann::Babbler.registered_plugins.map do |plugin|
95
- Thread.new {
96
- plugin.new( configatron, logger, riemann ).run
97
- }
98
- end
99
-
100
- Signal.trap "TERM" do # перехватываем сообщение (на будущее)
101
- plugin_threads.each( &:kill )
102
- end
103
-
104
- plugin_threads.each( &:join )
32
+ merge_config(logger, opts, configatron)
33
+ set_logger_lvl(logger, configatron)
34
+ load_plugins(configatron)
35
+ riemann = get_riemann(configatron)
36
+ start_plugins( Riemann::Babbler.registered_plugins, riemann, logger, configatron )
data/config.yml CHANGED
@@ -8,6 +8,9 @@ logger:
8
8
 
9
9
  plugins:
10
10
 
11
+ run_only:
12
+ # - cpu
13
+
11
14
  interval: 60
12
15
 
13
16
  dummy:
@@ -1,5 +1,5 @@
1
1
  module Riemann
2
2
  class Babbler
3
- VERSION = '0.6.2'
3
+ VERSION = '0.6.3'
4
4
  end
5
5
  end
@@ -0,0 +1,87 @@
1
+ def set_logger_lvl(logger, configatron)
2
+ case configatron.logger.level
3
+ when "INFO"
4
+ logger.level = Logger::INFO
5
+ when "WARN"
6
+ logger.level = Logger::WARN
7
+ when "ERROR"
8
+ logger.level = Logger::ERROR
9
+ when "FATAL"
10
+ logger.level = Logger::FATAL
11
+ when "UNKNOWN"
12
+ logger.level = Logger::UNKNOWN
13
+ else
14
+ logger.level = Logger::DEBUG
15
+ end
16
+ end
17
+
18
+ # merge configs
19
+ def merge_config(logger, opts, configatron)
20
+ config_file = if File.exist?( opts[:config] )
21
+ YAML.load_file( opts[:config] ).to_hash
22
+ else
23
+ logger.error "Can't load config file #{opts[:config]}"
24
+ Hash.new
25
+ end
26
+
27
+ config_default = YAML.load_file( File.expand_path('../../config.yml', __FILE__) )
28
+
29
+ config = config_default.deep_merge( config_file )
30
+ configatron.configure_from_hash config
31
+ end
32
+
33
+ # получаем список все плагинов
34
+ def load_plugins(configatron)
35
+ plugins = []
36
+ default_plugins_dir = File.expand_path('../riemann/babbler/plugins/', __FILE__)
37
+ Dir.glob( default_plugins_dir + "/*.rb" ) do |file|
38
+ plugins << file
39
+ end
40
+
41
+ unless configatron.plugins.dirs.nil?
42
+ configatron.plugins.dirs.each do |dir|
43
+ next unless Dir.exist? dir
44
+ Dir.glob( dir + "/*.rb" ) do |file|
45
+ plugins << file
46
+ end
47
+ end
48
+ end
49
+
50
+ unless configatron.plugins.files.nil?
51
+ configatron.plugins.files.each do |file|
52
+ plugins << file
53
+ end
54
+ end
55
+ plugins.each { |plugin| require plugin }
56
+ end
57
+
58
+ def get_riemann(configatron)
59
+ riemann_ip = Resolv.new.getaddress(configatron.riemann.host)
60
+ riemann = Riemann::Client.new(
61
+ :host => riemann_ip,
62
+ :port => configatron.riemann.port
63
+ )
64
+ riemann = ( configatron.riemann.proto == 'tcp' ) ? riemann.tcp : riemann
65
+ riemann
66
+ end
67
+
68
+ # логика стартования плагинов
69
+ def start_plugins(registered_plugins, riemann, logger, configatron)
70
+ plugins_for_run = registered_plugins
71
+ if run_only = configatron.plugins.run_only
72
+ plugins_for_run.delete_if {|plugin| ! run_only.include? plugin.to_s.split("::").last.downcase }
73
+ end unless ( configatron.plugins.run_only.nil? || configatron.plugins.run_only.empty? )
74
+
75
+ plugin_threads = plugins_for_run.map do |plugin|
76
+ Thread.new {
77
+ plugin.new( configatron, logger, riemann ).run
78
+ }
79
+ end
80
+
81
+ # plugin control
82
+ Signal.trap "TERM" do
83
+ plugin_threads.each( &:kill )
84
+ end
85
+
86
+ plugin_threads.each( &:join )
87
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-babbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -148,6 +148,7 @@ files:
148
148
  - lib/riemann/babbler/plugins/memory.rb
149
149
  - lib/riemann/babbler/plugins/net.rb
150
150
  - lib/riemann/version.rb
151
+ - lib/start_helpers.rb
151
152
  - riemann-babbler.gemspec
152
153
  homepage: https://github.com/vadv/riemann-babbler
153
154
  licenses:
@@ -164,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
165
  version: '0'
165
166
  segments:
166
167
  - 0
167
- hash: 3834453135357588375
168
+ hash: 204431131547743034
168
169
  required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  none: false
170
171
  requirements: