7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/ruminate.rb', line 7
def self.create_plugins(config_file, ruminate_dir, plugin_dir)
FileUtils.mkdir_p(plugin_dir)
config = YAML.load(File.read(config_file))
ruminate_plugin = File.expand_path('../ruminate/plugin.rb', __FILE__)
rumx_mount = config['rumx_mount'] || ''
username = config['username']
password = config['password']
host = config['host'] || 'localhost'
port = config['port'] || 3000
smtp_host = config['smtp_host'] || 'localhost'
ruby_shebang = config['ruby_shebang'] || '/usr/bin/env ruby'
Dir["#{ruminate_dir}/*.yml"].each do |plugin_config_file|
plugin_basename = File.basename(plugin_config_file, '.*')
plugin_config = YAML.load(File.read(plugin_config_file))
replace_templates(plugin_config, ruminate_dir)
plugin_config.each do |graph_category, graph_configs|
graph_configs.each do |graph_config|
raise "No plot\n#{graph_config.inspect}" unless graph_config[:plot]
config_params = ''
graph_config.each do |key, value|
config_params += "#{key} #{value}\n" if key.to_s.start_with?('graph_')
end
config_params += "graph_category #{graph_category}\n" unless graph_config[:graph_category]
graph_config[:plot].each_with_index do |field_hash, i|
field_hash.each do |key, value|
next if key == :field
config_params += "field#{i}.#{key} #{value}\n"
end
end
fields = graph_config[:plot].map {|field_hash| field_hash[:field]}
query = graph_config[:query]
alerts = graph_config[:alert] || []
alerts.each do |alert|
alert[:email] = config['email'][alert[:email]] if alert[:email].kind_of?(Symbol)
end
name = plugin_basename
name += '_' + graph_config[:name] if graph_config[:name]
puts "Creating #{name}"
File.open(File.join(plugin_dir, name), 'w', 0755) do |f|
f.write <<-EOS
#!#{ruby_shebang}
require '#{ruminate_plugin}'
ruminate(
ARGV[0],
'#{rumx_mount}',
#{username && username.inspect},
#{password && password.inspect},
'#{host}',
#{port},
'#{smtp_host}',
#{config_params.inspect},
'#{query}',
#{fields.inspect},
#{alerts.inspect}
)
EOS
end
end
end
end
end
|