Class: Kurchatov::Plugins::DSL

Inherits:
Object
  • Object
show all
Includes:
Mixin::Ohai
Defined in:
lib/kurchatov/plugin/dsl.rb

Constant Summary collapse

PLUGIN_EXT =
'.rb'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Ohai

#ohai

Constructor Details

#initializeDSL

Returns a new instance of DSL.



10
11
12
# File 'lib/kurchatov/plugin/dsl.rb', line 10

def initialize
  @plugins = Array.new
end

Instance Attribute Details

#pluginsObject (readonly)

Returns the value of attribute plugins.



7
8
9
# File 'lib/kurchatov/plugin/dsl.rb', line 7

def plugins
  @plugins
end

Class Method Details

.load_riemann_plugin(file) ⇒ Object



92
93
94
95
96
97
# File 'lib/kurchatov/plugin/dsl.rb', line 92

def self.load_riemann_plugin(file)
  dsl = Kurchatov::Plugins::DSL.new
  dsl.plugins << Kurchatov::Plugins::Riemann.new(File.basename(file, PLUGIN_EXT))
  dsl.instance_eval(File.read(file), file)
  dsl.last
end

.load_riemann_plugins(paths) ⇒ Object

load part



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/kurchatov/plugin/dsl.rb', line 73

def self.load_riemann_plugins(paths)
  dsl = Kurchatov::Plugins::DSL.new
  paths = [paths] unless paths.kind_of? Array
  paths.map do |path|
    Log.error("Directory #{path} not exists") and exit Kurchatov::Config[:ERROR_CONFIG] unless
      File.directory?(path)
    Dir[File.join(path, "*#{PLUGIN_EXT}")].sort
  end.flatten.each do |path|
    begin
      dsl.plugins << Kurchatov::Plugins::Riemann.new(File.basename(path, PLUGIN_EXT))
      dsl.instance_eval(File.read(path), path)
    rescue LoadError, SyntaxError => e
      dsl.plugins.pop # todo: plugin.new creates
      Log.error("Load plugin from file #{path}, #{e.class}: #{e}\n #{e.backtrace.join("\n")}")
    end
  end
  dsl.plugins
end

Instance Method Details

#always_start(val) ⇒ Object

plugins dsl part



19
20
21
# File 'lib/kurchatov/plugin/dsl.rb', line 19

def always_start(val)
  last.always_start = !!val
end

#collect(opts = {}, *args, &block) ⇒ Object



43
44
45
46
# File 'lib/kurchatov/plugin/dsl.rb', line 43

def collect(opts = {}, *args, &block)
  return unless last.respond_to_ohai?(opts)
  last.collect = block
end

#critical(val) ⇒ Object



35
36
37
# File 'lib/kurchatov/plugin/dsl.rb', line 35

def critical(val)
  last.plugin[:critical] = val
end

#ignore_errors(val) ⇒ Object



23
24
25
# File 'lib/kurchatov/plugin/dsl.rb', line 23

def ignore_errors(val)
  last.ignore_errors = !!val
end

#interval(val) ⇒ Object



27
28
29
# File 'lib/kurchatov/plugin/dsl.rb', line 27

def interval(val)
  last.interval = val.to_f
end

#lastObject



14
15
16
# File 'lib/kurchatov/plugin/dsl.rb', line 14

def last
  @plugins.last
end

#last_pluginObject Also known as: default



64
65
66
# File 'lib/kurchatov/plugin/dsl.rb', line 64

def last_plugin
  last.plugin
end

#name(val) ⇒ Object



31
32
33
# File 'lib/kurchatov/plugin/dsl.rb', line 31

def name(val)
  last.name = val
end

#required(opts = {}, &block) ⇒ Object Also known as: helpers



58
59
60
61
# File 'lib/kurchatov/plugin/dsl.rb', line 58

def required(opts ={}, &block)
  return unless last.respond_to_ohai?(opts)
  last.required = block
end

#run(opts = {}, *args, &block) ⇒ Object



48
49
50
51
# File 'lib/kurchatov/plugin/dsl.rb', line 48

def run(opts = {}, *args, &block)
  return unless last.respond_to_ohai?(opts)
  last.run = block
end

#run_if(opts = {}, &block) ⇒ Object



53
54
55
56
# File 'lib/kurchatov/plugin/dsl.rb', line 53

def run_if(opts = {}, &block)
  return unless last.respond_to_ohai?(opts)
  last.run_if = block
end

#warning(val) ⇒ Object



39
40
41
# File 'lib/kurchatov/plugin/dsl.rb', line 39

def warning(val)
  last.plugin[:warning] = val
end