Class: Laboratory
- Inherits:
-
Object
show all
- Defined in:
- lib/teuton/check/builtin.rb,
lib/teuton/check/dsl.rb,
lib/teuton/check/show.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
Returns a new instance of Laboratory.
40
41
42
43
44
45
46
47
|
# File 'lib/teuton/check/laboratory.rb', line 40
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, *args, &block) ⇒ Object
Check macros and _get_vars
80
81
82
83
84
85
|
# File 'lib/teuton/check/dsl.rb', line 80
def method_missing(method, *args, &block)
a = method.to_s
if args.nil? && block.nil?
instance_eval("get(:#{a[0, a.size - 1]})", __FILE__, __LINE__) if a[a.size - 1] == "?"
end
end
|
Instance Attribute Details
#result ⇒ Object
Returns the value of attribute result.
38
39
40
|
# File 'lib/teuton/check/laboratory.rb', line 38
def result
@result
end
|
Instance Method Details
#expect(cond) ⇒ Object
18
19
20
21
22
|
# File 'lib/teuton/check/dsl.rb', line 18
def expect(cond)
verboseln " alter #{result.alterations}" unless result.alterations.empty?
verboseln " expect #{cond} (#{cond.class})"
verboseln ""
end
|
#expect_first(cond) ⇒ Object
24
25
26
27
28
|
# File 'lib/teuton/check/dsl.rb', line 24
def expect_first(cond)
verboseln " alter #{result.alterations}" unless result.alterations.empty?
verboseln " expect_first #{cond} (#{cond.class})"
verboseln ""
end
|
#expect_last(cond) ⇒ Object
30
31
32
33
34
|
# File 'lib/teuton/check/dsl.rb', line 30
def expect_last(cond)
verboseln " alter #{result.alterations}" unless result.alterations.empty?
verboseln " expect_last #{cond} (#{cond.class})"
verboseln ""
end
|
#expect_none(cond) ⇒ Object
36
37
38
39
40
|
# File 'lib/teuton/check/dsl.rb', line 36
def expect_none(cond)
verboseln " alter #{result.alterations}" unless result.alterations.empty?
verboseln " expect_none #{cond} (#{cond.class})"
verboseln ""
end
|
#expect_one(cond) ⇒ Object
42
43
44
45
46
|
# File 'lib/teuton/check/dsl.rb', line 42
def expect_one(cond)
verboseln " alter #{result.alterations}" unless result.alterations.empty?
verboseln " expect_one #{cond} (#{cond.class})"
verboseln ""
end
|
#get(varname) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/teuton/check/dsl.rb', line 48
def get(varname)
@stats[:gets] += 1
if @gets[varname]
@gets[varname] += 1
else
@gets[varname] = 1
end
"get(#{varname})"
end
|
#gett(option) ⇒ Object
87
88
89
|
# File 'lib/teuton/check/dsl.rb', line 87
def gett(option)
get(option)
end
|
#goto(host = :localhost, args = {}) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/teuton/check/dsl.rb', line 67
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
98
99
100
101
|
# File 'lib/teuton/check/dsl.rb', line 98
def log(text = "", type = :info)
@stats[:logs] += 1
verboseln " log [#{type}]: " + text.to_s
end
|
#readme(_text) ⇒ Object
Include Teuton DSL keywords into Laboratory class
5
6
7
|
# File 'lib/teuton/check/dsl.rb', line 5
def readme(_text)
end
|
#reset ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/teuton/check/laboratory.rb', line 49
def reset
@result = Result.new
@targetid = 0
@stats = {groups: 0, targets: 0, uniques: 0, gets: 0, logs: 0, sets: 0}
@gets = {}
@sets = {}
@hosts = {}
@requests = [] @verbose = Project.value[:verbose]
end
|
#run(command, args = {}) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/teuton/check/dsl.rb', line 60
def run(command, args = {})
args[:exec] = command
host = :localhost
host = args[:on] if args[:on]
goto(host, args)
end
|
#service(param) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/teuton/check/builtin.rb', line 22
def service(param)
log "BUILTIN service(#{param})"
@builtin ||= Builtin.new(self)
@builtin.param = param
@builtin
end
|
#set(key, value) ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'lib/teuton/check/dsl.rb', line 103
def set(key, value)
@stats[:sets] += 1
key = ":" + key.to_s if key.instance_of? Symbol
value = ":" + value.to_s if value.instance_of? Symbol
@sets[key] = value
"set(#{key},#{value})"
end
|
#show ⇒ Object
8
9
10
11
12
13
|
# File 'lib/teuton/check/show.rb', line 8
def show
@verbose = true
process_content
show_stats
revise_config_content
end
|
#show_onlyconfig ⇒ Object
15
16
17
18
19
20
|
# File 'lib/teuton/check/show.rb', line 15
def show_onlyconfig
@verbose = false
process_content
@verbose = true
recomended_panelconfig_content
end
|
#target(desc, args = {}) ⇒ Object
Also known as:
goal
9
10
11
12
13
14
15
|
# File 'lib/teuton/check/dsl.rb', line 9
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
91
92
93
94
95
96
|
# File 'lib/teuton/check/dsl.rb', line 91
def unique(key, _value)
@stats[:uniques] += 1
verboseln " ! Unique value for <#{key}>"
verboseln ""
end
|