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 +1 -1
- data/lib/riemann/babbler/options.rb +6 -0
- data/lib/riemann/babbler/plugin_loader.rb +49 -8
- data/lib/riemann/babbler/version.rb +1 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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}"
|