Class: Scout::Command::Test

Inherits:
Scout::Command show all
Defined in:
lib/es-scout/command/test.rb

Constant Summary

Constants inherited from Scout::Command

HTTP_HEADERS

Instance Attribute Summary

Attributes inherited from Scout::Command

#config_dir, #history, #log_path, #server

Instance Method Summary collapse

Methods inherited from Scout::Command

#create_pid_file_or_exit, dispatch, #initialize, #level, #log, program_name, #program_name, program_path, #program_path, usage, #usage, user, #user, #verbose?

Constructor Details

This class inherits a constructor from Scout::Command

Instance Method Details

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/es-scout/command/test.rb', line 8

def run
  create_pid_file_or_exit
  plugin, *provided_options = @args
  # read the plugin_code from the file specified
  plugin_code    = File.read(plugin)

  options_for_run = {}

  # deal with embedded options yaml
  if  options_yaml = Scout::Plugin.extract_options_yaml_from_code(plugin_code)
    options=Scout::PluginOptions.from_yaml(options_yaml)

    if options.error
      puts "Problem parsing option definition in the plugin code (ignoring and continuing):"
      puts options_yaml
    else
      puts "== Plugin options: "
      puts options.to_s
      options.select{|o|o.has_default?}.each{|o|options_for_run[o.name]=o.default}
    end
  else
    puts "== This plugin doesn't have option metadata."
  end

  # provided_options are what the user gave us in the command line. Here, we merge them into
  # the defaults we've already established (if any) for this run.
  provided_options.each do |e|
    if e.include?('=')
      k,v=e.split('=',2)
      options_for_run[k]=v
    else
      puts "ERROR: Option '#{e}' is no good -- provided options should be in the format name=value."
    end
  end
  if options_for_run.any?
    puts "== Running plugin with: #{options_for_run.to_a.map{|a| "#{a.first}=#{a.last}"}.join('; ') }"
  else
    puts "== You haven't provided any options for running this plugin."
  end

  Scout::Server.new(nil, nil, history, log) do |scout|
    scout.prepare_checkin
    scout.process_plugin( 'interval'  => 0,
                          'plugin_id' => 1,
                          'name'      => "Local Plugin",
                          'code'      => plugin_code,
                          'options'   => options_for_run,
                          'path'      => plugin )
    puts "== Output:"
    scout.show_checkin(:pp)
  end  
end