class Malevich::Plugin
Attributes
always_start[RW]
collect[RW]
errors[RW]
histories[RW]
interval[RW]
name[RW]
plugin[RW]
run_if[RW]
settings[RW]
Public Class Methods
new(name)
click to toggle source
# File lib/malevich/plugin.rb, line 14 def initialize(name) @name = name @interval = 60 @run_if = Proc.new { true } @always_start = false end
Private Class Methods
make_container(container)
click to toggle source
# File lib/malevich/plugin.rb, line 58 def self.make_container(container) define_method(container) do |&block| malevich.plugins[container] ||= Malevich::Hashie.new malevich.plugins[container][self.name] ||= Malevich::Hashie.new malevich.plugins[container][self.name] end end
Public Instance Methods
log_and_false(level = :info, msg)
click to toggle source
# File lib/malevich/plugin.rb, line 27 def log_and_false(level = :info, msg) log level, msg false end
run!()
click to toggle source
# File lib/malevich/plugin.rb, line 38 def run! loop do t_start = Time.now begin Timeout.timeout(interval.to_f * 2/3) do self.instance_eval(&collect) end rescue => e error(e) end sleep(interval - (Time.now - t_start).to_i) end end
runnable?()
click to toggle source
# File lib/malevich/plugin.rb, line 26 def runnable? def log_and_false(level = :info, msg) log level, msg false end return log_and_false("'#{name}' not started, because have not 'collect'") if collect.nil? return log_and_false("'#{name}' disabled in config") if settings.disable return log_and_false("'#{name} disabled by run_if statement") unless !!self.instance_eval(&run_if) log :unknown, "'#{name}' started" end
suitable_platform?(name)
click to toggle source
# File lib/malevich/plugin.rb, line 21 def suitable_platform?(name) request_platform = name.nil? || name.empty? ? ['linux'] : name request_platform.include?(ohai[:platform]) || request_platform.include?(ohai[:os]) end
Private Instance Methods
ohai()
click to toggle source
# File lib/malevich/plugin.rb, line 54 def ohai malevich.ohai end