Class: Laboratory

Inherits:
Object
  • Object
show all
Defined in:
lib/teuton/check/dsl.rb,
lib/teuton/check/show.rb,
lib/teuton/check/builtin.rb,
lib/teuton/check/laboratory.rb

Overview

Show objectives stats from RB script file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script_path, config_path) ⇒ Laboratory

Initialize instance



45
46
47
48
49
50
51
52
# File 'lib/teuton/check/laboratory.rb', line 45

def initialize(script_path, config_path)
  @path = {}
  @path[:script]   = script_path
  @path[:dirname]  = File.dirname(script_path)
  @path[:filename] = File.basename(script_path, '.rb')
  @path[:config]   = config_path
  reset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object

If a method call is missing, then try to call get(var) rubocop:disable Style/MissingRespondToMissing



86
87
88
89
# File 'lib/teuton/check/dsl.rb', line 86

def method_missing(method)
  a = method.to_s
  instance_eval("get(:#{a[0, a.size - 1]})", __FILE__, __LINE__) if a[a.size - 1] == '?'
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



41
42
43
# File 'lib/teuton/check/laboratory.rb', line 41

def result
  @result
end

Instance Method Details

#expect(cond) ⇒ Object

Execute Teuton DSL expect keyword



48
49
50
51
52
# File 'lib/teuton/check/dsl.rb', line 48

def expect(cond)
  verboseln "      alter       #{result.alterations}" unless result.alterations.empty?
  verboseln "      expect      #{cond} (#{cond.class})"
  verboseln ''
end

#expect_none(cond) ⇒ Object

Execute Teuton DSL expect_none keyword



64
65
66
67
68
# File 'lib/teuton/check/dsl.rb', line 64

def expect_none(cond)
  verboseln "      alter       #{result.alterations}" unless result.alterations.empty?
  verboseln "      expect_none #{cond} (#{cond.class})"
  verboseln ''
end

#expect_one(cond) ⇒ Object

Execute Teuton DSL expect_one keyword



56
57
58
59
60
# File 'lib/teuton/check/dsl.rb', line 56

def expect_one(cond)
  verboseln "      alter       #{result.alterations}" unless result.alterations.empty?
  verboseln "      expect_one  #{cond} (#{cond.class})"
  verboseln ''
end

#get(varname) ⇒ Object

Execute Teuton DSL get keyword



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/teuton/check/dsl.rb', line 72

def get(varname)
  @stats[:gets] += 1

  if @gets[varname]
    @gets[varname] += 1
  else
    @gets[varname] = 1
  end

  "get(#{varname})"
end

#gett(option) ⇒ Object

Execute Teuton DSL gett keyword Same as get keyword, but show pretty output when used by readme command.



95
96
97
98
# File 'lib/teuton/check/dsl.rb', line 95

def gett(option)
  value = get(option)
  value
end

#goto(host = :localhost, args = {}) ⇒ Object

Execute Teuton DSL goto keyword



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/teuton/check/dsl.rb', line 34

def goto(host = :localhost, args = {})
  result.reset
  args[:on] = host unless args[:on]

  if @hosts[host]
    @hosts[host] += 1
  else
    @hosts[host] = 1
  end
  verboseln "      run         '#{args[:exec]}' on #{args[:on]}"
end

#log(text = '', type = :info) ⇒ Object

Execute Teuton DSL log keyword



111
112
113
114
# File 'lib/teuton/check/dsl.rb', line 111

def log(text = '', type = :info)
  @stats[:logs] += 1
  verboseln "      log    [#{type}]: " + text.to_s
end

#readme(_text) ⇒ Object

Execute Teuton DSL readme keyword



8
9
10
# File 'lib/teuton/check/dsl.rb', line 8

def readme(_text)
  # Usefull for "teuton readme" command action.
end

#resetObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/teuton/check/laboratory.rb', line 54

def reset
  @result = Result.new
  @targetid = 0
  @stats = { groups: 0, targets: 0, uniques: 0, gets: 0, logs: 0, sets: 0 }
  @gets = {}
  @sets = {}
  @hosts = {}
  @requests = [] # REVISE this
  @verbose = Application.instance.verbose
end

#run(command, args = {}) ⇒ Object

Execute Teuton DSL run keyword



25
26
27
28
29
30
# File 'lib/teuton/check/dsl.rb', line 25

def run(command, args = {})
  args[:exec] = command
  host = :localhost
  host = args[:on] if args[:on]
  goto(host, args)
end

#service(param) ⇒ Object



18
19
20
21
22
23
# File 'lib/teuton/check/builtin.rb', line 18

def service(param)
  log "BUILTIN service(#{param})"
  @builtin = @builtin || Builtin.new(self)
  @builtin.param = param
  @builtin
end

#set(key, value) ⇒ Object

Execute Teuton DSL set keyword



118
119
120
121
122
123
124
125
126
# File 'lib/teuton/check/dsl.rb', line 118

def set(key, value)
  @stats[:sets] += 1

  key = ':' + key.to_s if key.class == Symbol
  value = ':' + value.to_s if value.class == Symbol

  @sets[key] = value
  "set(#{key},#{value})"
end

#showObject

Display DSL checking on screen



14
15
16
17
18
19
# File 'lib/teuton/check/show.rb', line 14

def show
  @verbose = true
  process_content
  show_stats
  revise_config_content
end

#show_panelconfigObject

Display config for teuton panel on screen



23
24
25
26
27
28
# File 'lib/teuton/check/show.rb', line 23

def show_panelconfig
  @verbose = false
  process_content
  @verbose = true
  recomended_panelconfig_content
end

#target(desc, args = {}) ⇒ Object Also known as: goal

Execute Teuton DSL target keyword



14
15
16
17
18
19
20
# File 'lib/teuton/check/dsl.rb', line 14

def target(desc, args = {})
  @stats[:targets] += 1
  @targetid += 1
  weight = args[:weight] || 1.0
  verboseln format('(%03<targetid>d) target      %<desc>s', targetid: @targetid, desc: desc)
  verboseln "      weight      #{weight}"
end

#unique(key, _value) ⇒ Object

Execute Teuton DSL unique keyword



102
103
104
105
106
107
# File 'lib/teuton/check/dsl.rb', line 102

def unique(key, _value)
  @stats[:uniques] += 1

  verboseln "    ! Unique      value for <#{key}>"
  verboseln ''
end