Class: Laboratory
- Inherits:
-
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
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
81
82
83
84
85
86
|
# File 'lib/teuton/check/dsl.rb', line 81
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
19
20
21
22
23
|
# File 'lib/teuton/check/dsl.rb', line 19
def expect(cond)
verboseln " alter #{result.alterations}" unless result.alterations.empty?
verboseln " expect #{cond} (#{cond.class})"
verboseln ""
end
|
#expect_first(cond) ⇒ Object
25
26
27
28
29
|
# File 'lib/teuton/check/dsl.rb', line 25
def expect_first(cond)
verboseln " alter #{result.alterations}" unless result.alterations.empty?
verboseln " expect_first #{cond} (#{cond.class})"
verboseln ""
end
|
#expect_last(cond) ⇒ Object
31
32
33
34
35
|
# File 'lib/teuton/check/dsl.rb', line 31
def expect_last(cond)
verboseln " alter #{result.alterations}" unless result.alterations.empty?
verboseln " expect_last #{cond} (#{cond.class})"
verboseln ""
end
|
#expect_none(cond) ⇒ Object
37
38
39
40
41
|
# File 'lib/teuton/check/dsl.rb', line 37
def expect_none(cond)
verboseln " alter #{result.alterations}" unless result.alterations.empty?
verboseln " expect_none #{cond} (#{cond.class})"
verboseln ""
end
|
#expect_one(cond) ⇒ Object
43
44
45
46
47
|
# File 'lib/teuton/check/dsl.rb', line 43
def expect_one(cond)
verboseln " alter #{result.alterations}" unless result.alterations.empty?
verboseln " expect_one #{cond} (#{cond.class})"
verboseln ""
end
|
#get(varname) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/teuton/check/dsl.rb', line 49
def get(varname)
@stats[:gets] += 1
if @gets[varname]
@gets[varname] += 1
else
@gets[varname] = 1
end
"get(#{varname})"
end
|
#gett(option) ⇒ Object
88
89
90
|
# File 'lib/teuton/check/dsl.rb', line 88
def gett(option)
get(option)
end
|
#goto(host = :localhost, args = {}) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/teuton/check/dsl.rb', line 68
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
99
100
101
102
|
# File 'lib/teuton/check/dsl.rb', line 99
def log(text = "", type = :info)
@stats[:logs] += 1
verboseln " log [#{type}]: " + text.to_s
end
|
#readme(_text) ⇒ Object
6
7
8
|
# File 'lib/teuton/check/dsl.rb', line 6
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 = Application.instance.verbose
end
|
#run(command, args = {}) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/teuton/check/dsl.rb', line 61
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
104
105
106
107
108
109
110
111
112
|
# File 'lib/teuton/check/dsl.rb', line 104
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
12
13
14
15
16
17
|
# File 'lib/teuton/check/show.rb', line 12
def show
@verbose = true
process_content
show_stats
revise_config_content
end
|
#show_panelconfig ⇒ Object
19
20
21
22
23
24
|
# File 'lib/teuton/check/show.rb', line 19
def show_panelconfig
@verbose = false
process_content
@verbose = true
recomended_panelconfig_content
end
|
#target(desc, args = {}) ⇒ Object
Also known as:
goal
10
11
12
13
14
15
16
|
# File 'lib/teuton/check/dsl.rb', line 10
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
92
93
94
95
96
97
|
# File 'lib/teuton/check/dsl.rb', line 92
def unique(key, _value)
@stats[:uniques] += 1
verboseln " ! Unique value for <#{key}>"
verboseln ""
end
|