riemann-babbler 2.0.0pre8 → 2.0.0pre9

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- riemann-babbler (2.0.0pre7)
4
+ riemann-babbler (2.0.0pre8)
5
5
  configatron
6
6
  docile
7
7
  file-tail
@@ -24,6 +24,12 @@ module Riemann
24
24
  opts.configure_from_hash(result_config)
25
25
  end
26
26
 
27
+ # return configatron from hash
28
+ def opts_reset!(hash)
29
+ opts.reset!
30
+ opts.configure_from_hash(hash)
31
+ end
32
+
27
33
  # return string tw_cli_3
28
34
  def name_to_underscore(name = 'Riemann::Babbler::Plugin::TwCli_3')
29
35
  name.split('::').last.gsub(/(\p{Lower})(\p{Upper})/, "\\1_\\2").downcase
@@ -22,10 +22,12 @@ module Riemann
22
22
  'errors_reporter'
23
23
  ].freeze
24
24
 
25
- attr_accessor :sender
25
+ attr_accessor :sender, :load_plugin_names_from_config, :delete_from_autostart
26
26
 
27
27
  def initialize(riemann)
28
28
  @sender = riemann
29
+ @load_plugin_names_from_config = Array.new
30
+ @delete_from_autostart = Array.new
29
31
  end
30
32
 
31
33
  def all_available_plugins
@@ -44,10 +46,7 @@ module Riemann
44
46
  plugins
45
47
  end
46
48
 
47
- def require_all_plugins
48
- Riemann::Babbler::Plugin.registered_plugins.clear
49
- all_available_plugins.each { |file| require file }
50
- log :debug, "Require plugins: #{Riemann::Babbler::Plugin.registered_plugins}"
49
+ def require_parents
51
50
  # load parent
52
51
  opts.plugins.to_hash.each do |plugin_name, plugin_opts|
53
52
  next if plugin_opts.nil?
@@ -55,21 +54,63 @@ module Riemann
55
54
  if plugin_opts.has_key? :parent
56
55
  cmd = "class #{underscore_to_name plugin_name} < #{underscore_to_name plugin_opts[:parent]}; end;"
57
56
  cmd += "Riemann::Babbler::Plugin.registered_plugins << #{underscore_to_name plugin_name}"
58
- puts "CMD: #{cmd}"
57
+ load_plugin_names_from_config << plugin_name
59
58
  eval(cmd)
60
59
  end
61
60
  end
62
61
  end
63
62
 
63
+ def require_from_config
64
+ # load array new fea
65
+ new_opts = opts.to_hash
66
+ opts.plugins.to_hash.each do |plugin_name, plugin_opts|
67
+ next if plugin_opts.nil?
68
+ next if plugin_name == :dirs
69
+ next unless plugin_opts.kind_of?(Array)
70
+ plugin_opts.each_with_index do |new_plugin_opts, index|
71
+ parent_class = underscore_to_name(plugin_name)
72
+ new_plugin_name = "#{plugin_name}_#{index}"
73
+ new_class = "#{parent_class}_#{index}"
74
+ cmd = "class #{new_class} < #{parent_class}; end;"
75
+ cmd += "Riemann::Babbler::Plugin.registered_plugins << #{new_class}"
76
+ eval(cmd)
77
+ new_opts[:plugins][new_plugin_name.to_sym] = new_plugin_opts # set opts
78
+ load_plugin_names_from_config << new_plugin_name.to_s
79
+ delete_from_autostart << plugin_name.to_s
80
+ end
81
+ new_opts[:plugins].delete(plugin_name) # delete old if it array
82
+ end
83
+ opts_reset!(new_opts)
84
+ end
85
+
86
+ def require_all_plugins!
87
+ Riemann::Babbler::Plugin.registered_plugins.clear
88
+ all_available_plugins.each { |file| require file }
89
+ log :debug, "Require plugins: #{Riemann::Babbler::Plugin.registered_plugins}"
90
+ require_parents
91
+ require_from_config
92
+ end
93
+
64
94
  def run!
65
- plugin_names_to_run = AUTO_START + opts.plugins.to_hash.keys.map {|name| name.to_s}
66
- require_all_plugins
95
+
67
96
  started_plugins = []
97
+
98
+ plugin_names_to_run = (AUTO_START +
99
+ opts.plugins.to_hash.keys.map { |name| name.to_s }).uniq
100
+
101
+ require_all_plugins!
102
+
103
+ plugin_names_to_run = (plugin_names_to_run +
104
+ load_plugin_names_from_config.map {|name| name.to_s}).uniq
105
+
106
+ plugin_names_to_run = plugin_names_to_run - delete_from_autostart
107
+
68
108
  Riemann::Babbler::Plugin.registered_plugins.each do |klass|
69
109
  if plugin_names_to_run.include? name_to_underscore(klass.to_s)
70
110
  started_plugins << klass
71
111
  end
72
112
  end
113
+
73
114
  plugin_threads = started_plugins.map do |plugin|
74
115
  Thread.new {
75
116
  log :unknown, "Start plugin #{plugin}"
@@ -1,5 +1,5 @@
1
1
  module Riemann
2
2
  module Babbler
3
- VERSION = '2.0.0pre8'
3
+ VERSION = '2.0.0pre9'
4
4
  end
5
5
  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: 2.0.0pre8
4
+ version: 2.0.0pre9
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors: