class Laboratory
-
service
-
target
-
request (development)
-
tempfile
-
goto
-
run
-
expect
-
get
-
unique
-
log
-
set
Show objectives stats from RB script file
Attributes
result[R]
Public Class Methods
new(script_path, config_path)
click to toggle source
Initialize instance
# File lib/teuton/project/laboratory/laboratory.rb, line 48 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
Public Instance Methods
expect(_cond, args = {})
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 53 def expect(_cond, args = {}) verboseln " alter #{result.alterations}" unless result.alterations.empty? verboseln " expect #{_cond} (#{_cond.class})" verboseln '' end
expect_none(_cond, args = {})
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 65 def expect_none(_cond, args = {}) verboseln " alter #{result.alterations}" unless result.alterations.empty? verboseln " expect_none #{_cond} (#{_cond.class})" verboseln '' end
expect_one(_cond, args = {})
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 59 def expect_one(_cond, args = {}) verboseln " alter #{result.alterations}" unless result.alterations.empty? verboseln " expect_one #{_cond} (#{_cond.class})" verboseln '' end
get(varname)
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 71 def get(varname) @stats[:gets] += 1 if @gets[varname] @gets[varname] += 1 else @gets[varname] = 1 end "get(#{varname})" end
gett(option)
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 89 def gett(option) value = get(option) value end
goto(host = :localhost, args = {})
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 41 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)
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 101 def log(text = '', type = :info) @stats[:logs] += 1 verboseln " log [#{type}]: " + text.to_s end
method_missing(method)
click to toggle source
If a method call is missing, then delegate to concept parent.
# File lib/teuton/project/laboratory/dsl.rb, line 84 def method_missing(method) a = method.to_s instance_eval("get(:#{a[0, a.size - 1]})") if a[a.size - 1] == '?' end
readme(_text)
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 13 def readme(_text) # Usefull for "teuton readme" command action. end
reset()
click to toggle source
Set attibutes to default values
# File lib/teuton/project/laboratory/laboratory.rb, line 59 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 = {})
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 34 def run(command, args = {}) args[:exec] = command host = :localhost host = args[:on] if args[:on] goto(host, args) end
service(param)
click to toggle source
# File lib/teuton/project/laboratory/builtin.rb, line 18 def service(param) log "BUILTIN service(#{param})" @builtin = @builtin || Builtin.new(self) @builtin.param = param @builtin end
set(key, value)
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 106 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
show_config()
click to toggle source
Display config on screen
# File lib/teuton/project/laboratory/show.rb, line 54 def show_config @verbose = false process_content @verbose = true revise_config_content end
show_dsl()
click to toggle source
Display DSL
on screen
# File lib/teuton/project/laboratory/show.rb, line 14 def show_dsl @verbose = true process_content show_stats show_config end
show_stats()
click to toggle source
Display stats on screen
# File lib/teuton/project/laboratory/show.rb, line 23 def show_stats @stats[:hosts] = 0 @hosts.each_pair { |_k, v| @stats[:hosts] += v } my_screen_table = Terminal::Table.new do |st| st.add_row ['DSL Stats', 'Count'] st.add_separator st.add_row ['Groups', @stats[:groups]] st.add_row ['Targets', @stats[:targets]] st.add_row ['Goto', @stats[:hosts]] @hosts.each_pair { |k, v| st.add_row [" * #{k}", v] } st.add_row ['Uniques', @stats[:uniques]] st.add_row ['Logs', @stats[:uniques]] st.add_row [' ', ' '] st.add_row ['Gets', @stats[:gets]] if @gets.count > 0 list = @gets.sort_by { |_k, v| v } list.reverse_each { |item| st.add_row [" * #{item[0]}", item[1].to_s] } end st.add_row ['Sets', @stats[:sets]] if @sets.count > 0 @sets.each_pair { |k, v| st.add_row [" * #{k}", v.to_s] } end end verboseln my_screen_table.to_s + "\n" end
target(desc, args = {})
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 17 def target(desc, args = {}) @stats[:targets] += 1 @targetid += 1 weight = args[:weight] || 1.0 verboseln '(%03d' % @targetid + ") target #{desc}" verboseln " weight #{weight}" end
Also aliased as: goal
tempfile(_tempfile = nil)
click to toggle source
def request(text)
@requests << text.to_s
end
# File lib/teuton/project/laboratory/dsl.rb, line 30 def tempfile(_tempfile = nil) 'tempfile' end
unique(key, _value)
click to toggle source
# File lib/teuton/project/laboratory/dsl.rb, line 94 def unique(key, _value) @stats[:uniques] += 1 verboseln " ! Unique value for <#{key}>" verboseln '' end
Private Instance Methods
find_script_vars()
click to toggle source
# File lib/teuton/project/laboratory/show.rb, line 99 def find_script_vars script_vars = [:tt_members] @hosts.each_key do |k| next if k == :localhost if k.class == Symbol script_vars << (k.to_s + '_ip').to_sym script_vars << (k.to_s + '_username').to_sym script_vars << (k.to_s + '_password').to_sym else script_vars << k.to_s + '_ip' script_vars << k.to_s + '_username' script_vars << k.to_s + '_password' end end @gets.each_key { |k| script_vars << k } script_vars end
process_content()
click to toggle source
# File lib/teuton/project/laboratory/show.rb, line 85 def process_content groups = Application.instance.groups verboseln '' groups.each do |t| @stats[:groups] += 1 msg = "GROUP: #{t[:name]}" my_screen_table = Terminal::Table.new { |st| st.add_row [msg] } verboseln my_screen_table instance_eval(&t[:block]) end end
recomended_config_content()
click to toggle source
# File lib/teuton/project/laboratory/show.rb, line 118 def recomended_config_content verbose Rainbow('[WARN] File ').yellow verbose Rainbow(@path[:config]).yellow.bright verboseln Rainbow(' not found!').yellow verboseln '[INFO] Recomended content:' output = { global: nil, cases: [] } output[:cases][0] = {} script_vars = find_script_vars script_vars.each { |i| output[:cases][0][i] = 'VALUE' } verboseln YAML.dump(output) end
revise_config_content()
click to toggle source
Revive and check config content
# File lib/teuton/project/laboratory/show.rb, line 132 def revise_config_content @verbose = true my_screen_table = Terminal::Table.new do |st| st.add_row ['Revising CONFIG file'] end verboseln my_screen_table unless File.exist?(@path[:config]) recomended_config_content return end script_vars = find_script_vars config_vars = ConfigFileReader.read(@path[:config]) unless config_vars[:global].nil? config_vars[:global].each_key { |k| script_vars.delete(k) } end unless config_vars[:alias].nil? config_vars[:alias].each_key { |k| script_vars.delete(k) } end config_vars[:cases].each_with_index do |item, index| next if item[:tt_skip] == true script_vars.each do |value| next unless item[value].nil? next unless @sets[':' + value.to_s].nil? verbose Rainbow(' * Define ').red verbose Rainbow(value).red.bright verbose Rainbow(' value for Case[').red verbose Rainbow(index).red.bright verboseln Rainbow('] or set tt_skip = true').red end end end
verbose(text)
click to toggle source
def show_requests
@verbose = false process_content @verbose = true my_screen_table = Terminal::Table.new do |st| st.add_row ['Lines', 'REQUEST description'] st.add_separator @requests.each_with_index do |line, index| st.add_row ['%03d' % index, line] end end verboseln my_screen_table
end
# File lib/teuton/project/laboratory/show.rb, line 77 def verbose(text) print text if @verbose end
verboseln(text)
click to toggle source
# File lib/teuton/project/laboratory/show.rb, line 81 def verboseln(text) puts text if @verbose end