logstash-core 1.5.0.beta2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of logstash-core might be problematic. Click here for more details.

Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/lib/logstash-event.rb +2 -0
  3. data/lib/logstash.rb +4 -0
  4. data/lib/logstash/JRUBY-PR1448.rb +32 -0
  5. data/lib/logstash/agent.rb +355 -0
  6. data/lib/logstash/bundler.rb +124 -0
  7. data/lib/logstash/codecs/base.rb +50 -0
  8. data/lib/logstash/config/config_ast.rb +508 -0
  9. data/lib/logstash/config/file.rb +39 -0
  10. data/lib/logstash/config/grammar.rb +3503 -0
  11. data/lib/logstash/config/mixin.rb +495 -0
  12. data/lib/logstash/config/registry.rb +13 -0
  13. data/lib/logstash/environment.rb +168 -0
  14. data/lib/logstash/errors.rb +12 -0
  15. data/lib/logstash/event.rb +310 -0
  16. data/lib/logstash/filters/base.rb +239 -0
  17. data/lib/logstash/gemfile.rb +175 -0
  18. data/lib/logstash/inputs/base.rb +137 -0
  19. data/lib/logstash/inputs/threadable.rb +18 -0
  20. data/lib/logstash/java_integration.rb +41 -0
  21. data/lib/logstash/json.rb +53 -0
  22. data/lib/logstash/logging.rb +91 -0
  23. data/lib/logstash/multiqueue.rb +53 -0
  24. data/lib/logstash/namespace.rb +17 -0
  25. data/lib/logstash/outputs/base.rb +124 -0
  26. data/lib/logstash/patches.rb +3 -0
  27. data/lib/logstash/patches/bugfix_jruby_2558.rb +50 -0
  28. data/lib/logstash/patches/cabin.rb +34 -0
  29. data/lib/logstash/patches/profile_require_calls.rb +47 -0
  30. data/lib/logstash/pipeline.rb +305 -0
  31. data/lib/logstash/plugin.rb +177 -0
  32. data/lib/logstash/pluginmanager.rb +17 -0
  33. data/lib/logstash/pluginmanager/install.rb +112 -0
  34. data/lib/logstash/pluginmanager/list.rb +38 -0
  35. data/lib/logstash/pluginmanager/main.rb +22 -0
  36. data/lib/logstash/pluginmanager/maven_tools_patch.rb +12 -0
  37. data/lib/logstash/pluginmanager/uninstall.rb +49 -0
  38. data/lib/logstash/pluginmanager/update.rb +50 -0
  39. data/lib/logstash/pluginmanager/util.rb +88 -0
  40. data/lib/logstash/program.rb +15 -0
  41. data/lib/logstash/runner.rb +167 -0
  42. data/lib/logstash/sized_queue.rb +8 -0
  43. data/lib/logstash/threadwatchdog.rb +37 -0
  44. data/lib/logstash/timestamp.rb +97 -0
  45. data/lib/logstash/util.rb +152 -0
  46. data/lib/logstash/util/accessors.rb +88 -0
  47. data/lib/logstash/util/buftok.rb +139 -0
  48. data/lib/logstash/util/charset.rb +35 -0
  49. data/lib/logstash/util/fieldreference.rb +68 -0
  50. data/lib/logstash/util/filetools.rb +185 -0
  51. data/lib/logstash/util/password.rb +25 -0
  52. data/lib/logstash/util/plugin_version.rb +43 -0
  53. data/lib/logstash/util/prctl.rb +11 -0
  54. data/lib/logstash/util/require-helper.rb +18 -0
  55. data/lib/logstash/util/retryable.rb +39 -0
  56. data/lib/logstash/util/socket_peer.rb +7 -0
  57. data/lib/logstash/version.rb +6 -0
  58. data/locales/en.yml +176 -0
  59. metadata +427 -0
@@ -0,0 +1,17 @@
1
+ $DEBUGLIST = (ENV["DEBUG"] || "").split(",")
2
+
3
+ require "logstash/environment"
4
+
5
+ ENV["GEM_HOME"] = ENV["GEM_PATH"] = LogStash::Environment.logstash_gem_home
6
+ Gem.use_paths(LogStash::Environment.logstash_gem_home)
7
+
8
+ require 'logstash/pluginmanager/main'
9
+
10
+ if __FILE__ == $0
11
+ begin
12
+ LogStash::PluginManager::Main.run("bin/plugin", ARGV)
13
+ rescue LogStash::PluginManager::Error => e
14
+ $stderr.puts(e.message)
15
+ exit(1)
16
+ end
17
+ end
@@ -0,0 +1,112 @@
1
+ require 'clamp'
2
+ require 'logstash/namespace'
3
+ require 'logstash/environment'
4
+ require 'logstash/pluginmanager/util'
5
+ require 'jar-dependencies'
6
+ require 'jar_install_post_install_hook'
7
+ require 'file-dependencies/gem'
8
+
9
+ require "logstash/gemfile"
10
+ require "logstash/bundler"
11
+
12
+ class LogStash::PluginManager::Install < Clamp::Command
13
+ parameter "[PLUGIN] ...", "plugin name(s) or file"
14
+ option "--version", "VERSION", "version of the plugin to install"
15
+ option "--[no-]verify", :flag, "verify plugin validity before installation", :default => true
16
+ option "--development", :flag, "install all development dependencies of currently installed plugins", :default => false
17
+
18
+ # the install logic below support installing multiple plugins with each a version specification
19
+ # but the argument parsing does not support it for now so currently if specifying --version only
20
+ # one plugin name can be also specified.
21
+ #
22
+ # TODO: find right syntax to allow specifying list of plugins with optional version specification for each
23
+
24
+ def execute
25
+ if development?
26
+ raise(LogStash::PluginManager::Error, "Cannot specify plugin(s) with --development, it will add the development dependencies of the currently installed plugins") unless plugin_list.empty?
27
+ else
28
+ raise(LogStash::PluginManager::Error, "No plugin specified") if plugin_list.empty? && verify?
29
+
30
+ # temporary until we fullfil TODO ^^
31
+ raise(LogStash::PluginManager::Error, "Only 1 plugin name can be specified with --version") if version && plugin_list.size > 1
32
+ end
33
+ raise(LogStash::PluginManager::Error, "File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)
34
+
35
+ gemfile = LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, "r+")).load
36
+ # keep a copy of the gemset to revert on error
37
+ original_gemset = gemfile.gemset.copy
38
+
39
+ # force Rubygems sources to our Gemfile sources
40
+ Gem.sources = gemfile.gemset.sources
41
+
42
+ # install_list will be an array of [plugin name, version] tuples, version can be nil
43
+ install_list = []
44
+
45
+ if development?
46
+ specs = LogStash::PluginManager.all_installed_plugins_gem_specs(gemfile)
47
+ install_list = specs.inject([]) do |result, spec|
48
+ result = result + spec.dependencies.select{|dep| dep.type == :development}.map{|dep| [dep.name] + dep.requirement.as_list + [{:group => :development}]}
49
+ end
50
+ else
51
+ # at this point we know that plugin_list is not empty and if the --version is specified there is only one plugin in plugin_list
52
+
53
+ install_list = version ? [plugin_list << version] : plugin_list.map{|plugin| [plugin, nil]}
54
+
55
+ install_list.each do |plugin, version|
56
+ puts("Validating #{[plugin, version].compact.join("-")}")
57
+ raise(LogStash::PluginManager::Error, "Installation aborted") unless LogStash::PluginManager.logstash_plugin?(plugin, version)
58
+ end if verify?
59
+
60
+ # at this point we know that we either have a valid gem name & version or a valid .gem file path
61
+
62
+ # if LogStash::PluginManager.plugin_file?(plugin)
63
+ # raise(LogStash::PluginManager::Error) unless cache_gem_file(plugin)
64
+ # spec = LogStash::PluginManager.plugin_file_spec(plugin)
65
+ # gemfile.update(spec.name, spec.version.to_s)
66
+ # else
67
+ # plugins.each{|tuple| gemfile.update(*tuple)}
68
+ # end
69
+ end
70
+
71
+
72
+ install_list = LogStash::PluginManager.merge_duplicates(install_list)
73
+ install_list.each{|plugin, version| gemfile.update(plugin, version)}
74
+ gemfile.save
75
+
76
+ puts("Installing" + (install_list.empty? ? "..." : " " + install_list.map{|plugin, version| plugin}.join(", ")))
77
+
78
+ bundler_options = {:install => true}
79
+ bundler_options[:without] = [] if development?
80
+
81
+ # any errors will be logged to $stderr by invoke_bundler!
82
+ output, exception = LogStash::Bundler.invoke_bundler!(bundler_options)
83
+
84
+ if ENV["DEBUG"]
85
+ $stderr.puts(output)
86
+ $stderr.puts("Error: #{exception.class}, #{exception.message}") if exception
87
+ end
88
+
89
+ if exception
90
+ # revert to original Gemfile content
91
+ gemfile.gemset = original_gemset
92
+ gemfile.save
93
+ raise(LogStash::PluginManager::Error, "Installation aborted")
94
+ end
95
+
96
+ puts("Installation successful")
97
+ end
98
+
99
+ # copy .gem file into bundler cache directory, log any error to $stderr
100
+ # @param path [String] the source .gem file to copy
101
+ # @return [Boolean] true if successful
102
+ def cache_gem_file(path)
103
+ dest = ::File.join(LogStash::Environment.logstash_gem_home, "cache")
104
+ begin
105
+ FileUtils.cp(path, dest)
106
+ rescue => e
107
+ $stderr.puts("Error copying #{plugin} to #{dest}, caused by #{e.class}")
108
+ return false
109
+ end
110
+ true
111
+ end
112
+ end # class Logstash::PluginManager
@@ -0,0 +1,38 @@
1
+ require 'clamp'
2
+ require 'logstash/namespace'
3
+ require 'logstash/pluginmanager/util'
4
+ require 'rubygems/spec_fetcher'
5
+
6
+ class LogStash::PluginManager::List < Clamp::Command
7
+
8
+ parameter "[PLUGIN]", "Part of plugin name to search for, leave empty for all plugins"
9
+
10
+ option "--installed", :flag, "List only explicitly installed plugins using bin/plugin install ...", :default => false
11
+ option "--verbose", :flag, "Also show plugin version number", :default => false
12
+ option "--group", "NAME", "Filter plugins per group: input, output, filter or codec" do |arg|
13
+ raise(ArgumentError, "should be one of: input, output, filter or codec") unless ['input', 'output', 'filter', 'codec'].include?(arg)
14
+ arg
15
+ end
16
+
17
+ def execute
18
+ Gem.configuration.verbose = false
19
+
20
+ gemfile = LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, "r+")).load
21
+
22
+ # start with all locally installed plugin gems regardless of the Gemfile content
23
+ specs = LogStash::PluginManager.find_plugins_gem_specs
24
+
25
+ # apply filters
26
+ specs = specs.select{|spec| gemfile.find(spec.name)} if installed?
27
+ specs = specs.select{|spec| spec.name =~ /#{plugin}/i} if plugin
28
+ specs = specs.select{|spec| spec.metadata['logstash_group'] == group} if group
29
+
30
+ raise(LogStash::PluginManager::Error, "No plugins found") if specs.empty?
31
+
32
+ specs.sort_by{|spec| spec.name}.each do |spec|
33
+ line = "#{spec.name}"
34
+ line += " (#{spec.version})" if verbose?
35
+ puts(line)
36
+ end
37
+ end
38
+ end # class Logstash::PluginManager
@@ -0,0 +1,22 @@
1
+ require "logstash/namespace"
2
+ require "logstash/errors"
3
+ require "logstash/pluginmanager/install"
4
+ require "logstash/pluginmanager/uninstall"
5
+ require "logstash/pluginmanager/list"
6
+ require "logstash/pluginmanager/update"
7
+ require "logstash/pluginmanager/util"
8
+ require "logstash/pluginmanager/maven_tools_patch"
9
+ require "clamp"
10
+
11
+ module LogStash
12
+ module PluginManager
13
+ class Error < StandardError; end
14
+
15
+ class Main < Clamp::Command
16
+ subcommand "install", "Install a plugin", LogStash::PluginManager::Install
17
+ subcommand "uninstall", "Uninstall a plugin", LogStash::PluginManager::Uninstall
18
+ subcommand "update", "Install a plugin", LogStash::PluginManager::Update
19
+ subcommand "list", "List all installed plugins", LogStash::PluginManager::List
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ # This adds the "repo" element to the jar-dependencies DSL
2
+ # allowing a gemspec to require a jar that exists in a custom
3
+ # maven repository
4
+ # Example:
5
+ # gemspec.requirements << "repo http://localhosty/repo"
6
+ require 'maven/tools/dsl/project_gemspec'
7
+ class Maven::Tools::DSL::ProjectGemspec
8
+ def repo(url)
9
+ @parent.repository(:id => url, :url => url)
10
+ end
11
+ end
12
+
@@ -0,0 +1,49 @@
1
+ require "logstash/namespace"
2
+ require "logstash/logging"
3
+ require "logstash/errors"
4
+ require "logstash/environment"
5
+ require "logstash/pluginmanager/util"
6
+ require "clamp"
7
+
8
+ require "logstash/gemfile"
9
+ require "logstash/bundler"
10
+
11
+ class LogStash::PluginManager::Uninstall < Clamp::Command
12
+ parameter "PLUGIN", "plugin name"
13
+
14
+
15
+ def execute
16
+ raise(LogStash::PluginManager::Error, "File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)
17
+
18
+ gemfile = LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, "r+")).load
19
+ # keep a copy of the gemset to revert on error
20
+ original_gemset = gemfile.gemset.copy
21
+
22
+ # make sure this is an installed plugin and present in Gemfile.
23
+ # it is not possible to uninstall a dependency not listed in the Gemfile, for example a dependent codec
24
+ raise(LogStash::PluginManager::Error, "This plugin has not been previously installed, aborting") unless LogStash::PluginManager.installed_plugin?(plugin, gemfile)
25
+
26
+ # since we previously did a gemfile.find(plugin) there is no reason why
27
+ # remove would not work (return nil) here
28
+ if gemfile.remove(plugin)
29
+ gemfile.save
30
+
31
+ puts("Uninstalling #{plugin}")
32
+
33
+ # any errors will be logged to $stderr by invoke_bundler!
34
+ output, exception = LogStash::Bundler.invoke_bundler!(:clean => true)
35
+
36
+ if ENV["DEBUG"]
37
+ $stderr.puts(output)
38
+ $stderr.puts("Error: #{exception.class}, #{exception.message}") if exception
39
+ end
40
+
41
+ if exception
42
+ # revert to original Gemfile content
43
+ gemfile.gemset = original_gemset
44
+ gemfile.save
45
+ raise(LogStash::PluginManager::Error, "Uninstall aborted")
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,50 @@
1
+ require 'clamp'
2
+ require 'logstash/namespace'
3
+ require 'logstash/pluginmanager/util'
4
+ require 'jar-dependencies'
5
+ require 'jar_install_post_install_hook'
6
+ require 'file-dependencies/gem'
7
+
8
+ require "logstash/gemfile"
9
+ require "logstash/bundler"
10
+
11
+ class LogStash::PluginManager::Update < Clamp::Command
12
+ parameter "[PLUGIN] ...", "Plugin name(s) to upgrade to latest version"
13
+
14
+ def execute
15
+ gemfile = LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, "r+")).load
16
+ # keep a copy of the gemset to revert on error
17
+ original_gemset = gemfile.gemset.copy
18
+
19
+ # create list of plugins to update
20
+ plugins = unless plugin_list.empty?
21
+ not_installed = plugin_list.find{|plugin| !LogStash::PluginManager.installed_plugin?(plugin, gemfile)}
22
+ raise(LogStash::PluginManager::Error, "Plugin #{not_installed} has not been previously installed, aborting") if not_installed
23
+ plugin_list
24
+ else
25
+ LogStash::PluginManager.all_installed_plugins_gem_specs(gemfile).map{|spec| spec.name}
26
+ end
27
+
28
+ # remove any version constrain from the Gemfile so the plugin(s) can be updated to latest version
29
+ # calling update without requiremend will remove any previous requirements
30
+ plugins.each{|plugin| gemfile.update(plugin)}
31
+ gemfile.save
32
+
33
+ puts("Updating " + plugins.join(", "))
34
+
35
+ # any errors will be logged to $stderr by invoke_bundler!
36
+ output, exception = LogStash::Bundler.invoke_bundler!(:update => plugins)
37
+
38
+ if ENV["DEBUG"]
39
+ $stderr.puts(output)
40
+ $stderr.puts("Error: #{exception.class}, #{exception.message}") if exception
41
+ end
42
+
43
+ if exception
44
+ # revert to original Gemfile content
45
+ gemfile.gemset = original_gemset
46
+ gemfile.save
47
+ raise(LogStash::PluginManager::Error, "Update aborted")
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,88 @@
1
+ module LogStash::PluginManager
2
+
3
+ # check for valid logstash plugin gem name & version or .gem file, logs errors to $stdout
4
+ # uses Rubygems API and will remotely validated agains the current Gem.sources
5
+ # @param plugin [String] plugin name or .gem file path
6
+ # @param version [String] gem version requirement string
7
+ # @return [Boolean] true if valid logstash plugin gem name & version or a .gem file
8
+ def self.logstash_plugin?(plugin, version = nil)
9
+ if plugin_file?(plugin)
10
+ begin
11
+ return logstash_plugin_gem_spec?(plugin_file_spec(plugin))
12
+ rescue => e
13
+ $stderr.puts("Error reading plugin file #{plugin}, caused by #{e.class}")
14
+ $stderr.puts(e.message) if ENV["DEBUG"]
15
+ return false
16
+ end
17
+ else
18
+ dep = Gem::Dependency.new(plugin, version || Gem::Requirement.default)
19
+ specs, error = Gem::SpecFetcher.fetcher.spec_for_dependency(dep)
20
+
21
+ # depending on version requirements, multiple specs can be returned in which case
22
+ # we will grab the one with the highest version number
23
+ if latest = specs.map(&:first).max_by(&:version)
24
+ unless valid = logstash_plugin_gem_spec?(latest)
25
+ $stderr.puts("#{plugin} is not a Logstash plugin")
26
+ end
27
+ return valid
28
+ else
29
+ $stderr.puts("Plugin #{plugin}" + (version ? " version #{version}" : "") + " does not exist")
30
+ return false
31
+ end
32
+ end
33
+ end
34
+
35
+ # @param spec [Gem::Specification] plugin gem specification
36
+ # @return [Boolean] true if this spec is for an installable logstash plugin
37
+ def self.logstash_plugin_gem_spec?(spec)
38
+ spec.metadata && spec.metadata["logstash_plugin"] == "true"
39
+ end
40
+
41
+ # @param path [String] path to .gem file
42
+ # @return [Gem::Specification] .get file gem specification
43
+ # @raise [Exception] Gem::Package::FormatError will be raised on invalid .gem file format, might be other exceptions too
44
+ def self.plugin_file_spec(path)
45
+ Gem::Package.new(path).spec
46
+ end
47
+
48
+ # @param plugin [String] the plugin name or the local path to a .gem file
49
+ # @return [Boolean] true if the plugin is a local .gem file
50
+ def self.plugin_file?(plugin)
51
+ (plugin =~ /\.gem$/ && File.file?(plugin))
52
+ end
53
+
54
+ # retrieve gem specs for all or specified name valid logstash plugins locally installed
55
+ # @param name [String] specific plugin name to find or nil for all plungins
56
+ # @return [Array<Gem::Specification>] all local logstash plugin gem specs
57
+ def self.find_plugins_gem_specs(name = nil)
58
+ specs = name ? Gem::Specification.find_all_by_name(name) : Gem::Specification.find_all
59
+ specs.select{|spec| logstash_plugin_gem_spec?(spec)}
60
+ end
61
+
62
+ # list of all locally installed plugins specs specified in the Gemfile.
63
+ # note that an installed plugin dependecies like codecs will not be listed, only those
64
+ # specifically listed in the Gemfile.
65
+ # @param gemfile [LogStash::Gemfile] the gemfile to validate against
66
+ # @return [Array<Gem::Specification>] list of plugin names
67
+ def self.all_installed_plugins_gem_specs(gemfile)
68
+ # we start form the installed gemspecs so we can verify the metadata for valid logstash plugin
69
+ # then filter out those not included in the Gemfile
70
+ find_plugins_gem_specs.select{|spec| !!gemfile.find(spec.name)}
71
+ end
72
+
73
+ # @param plugin [String] plugin name
74
+ # @param gemfile [LogStash::Gemfile] the gemfile to validate against
75
+ # @return [Boolean] true if the plugin is an installed logstash plugin and spefificed in the Gemfile
76
+ def self.installed_plugin?(plugin, gemfile)
77
+ !!gemfile.find(plugin) && find_plugins_gem_specs(plugin).any?
78
+ end
79
+
80
+ # @param plugin_list [Array] array of [plugin name, version] tuples
81
+ # @return [Array] array of [plugin name, version, ...] tuples when duplciate names have been merged and non duplicate version requirements added
82
+ def self.merge_duplicates(plugin_list)
83
+
84
+ # quick & dirty naive dedup for now
85
+ # TODO: properly merge versions requirements
86
+ plugin_list.uniq(&:first)
87
+ end
88
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require "logstash/namespace"
4
+
5
+ module LogStash::Program
6
+ public
7
+ def exit(value)
8
+ if RUBY_ENGINE == "jruby"
9
+ # Kernel::exit() in jruby just tosses an exception? Let's actually exit.
10
+ Java::java.lang.System.exit(value)
11
+ else
12
+ Kernel::exit(value)
13
+ end
14
+ end # def exit
15
+ end # module LogStash::Program
@@ -0,0 +1,167 @@
1
+ # encoding: utf-8
2
+
3
+ Encoding.default_external = Encoding::UTF_8
4
+ $START = Time.now
5
+ $DEBUGLIST = (ENV["DEBUG"] || "").split(",")
6
+
7
+ require "logstash/environment"
8
+ LogStash::Environment.bundler_setup!
9
+ LogStash::Environment.load_locale!
10
+
11
+ Thread.abort_on_exception = true
12
+
13
+ require "logstash/namespace"
14
+ require "logstash/program"
15
+
16
+ class LogStash::RSpecsRunner
17
+ def initialize(args)
18
+ @args = args
19
+ end
20
+
21
+ def run
22
+ @result = RSpec::Core::Runner.run(@args)
23
+ end
24
+
25
+ def wait
26
+ return @result
27
+ end
28
+ end
29
+
30
+ class LogStash::Runner
31
+ include LogStash::Program
32
+
33
+ def main(args)
34
+ require "logstash/util"
35
+ require "stud/trap"
36
+ require "stud/task"
37
+ @startup_interruption_trap = Stud::trap("INT") { puts "Interrupted"; exit 0 }
38
+
39
+ LogStash::Util::set_thread_name(self.class.name)
40
+ #$LOAD_PATH << File.join(File.dirname(__FILE__), "..")
41
+
42
+ if RUBY_VERSION < "1.9.2"
43
+ $stderr.puts "Ruby 1.9.2 or later is required. (You are running: " + RUBY_VERSION + ")"
44
+ return 1
45
+ end
46
+
47
+ Stud::untrap("INT", @startup_interruption_trap)
48
+
49
+ task = run(args)
50
+ exit(task.wait)
51
+ end # def self.main
52
+
53
+ def run(args)
54
+ command = args.shift
55
+ commands = {
56
+ "version" => lambda do
57
+ require "logstash/agent"
58
+ agent_args = ["--version"]
59
+ if args.include?("--verbose")
60
+ agent_args << "--verbose"
61
+ end
62
+ return LogStash::Agent.run($0, agent_args)
63
+ end,
64
+ "rspec" => lambda do
65
+ require "rspec/core/runner"
66
+ require "rspec"
67
+ spec_path = File.expand_path(File.join(File.dirname(__FILE__), "/../../spec"))
68
+ $LOAD_PATH << spec_path
69
+ all_specs = Dir.glob(File.join(spec_path, "/**/*_spec.rb"))
70
+ rspec = LogStash::RSpecsRunner.new(args.empty? ? all_specs : args)
71
+ return rspec.run
72
+ end,
73
+ "irb" => lambda do
74
+ require "irb"
75
+ return IRB.start(__FILE__)
76
+ end,
77
+ "pry" => lambda do
78
+ require "pry"
79
+ return binding.pry
80
+ end,
81
+ "docgen" => lambda do
82
+ require 'docs/asciidocgen'
83
+ opts = OptionParser.new
84
+ settings = {}
85
+ opts.on("-o DIR", "--output DIR",
86
+ "Directory to output to; optional. If not specified,"\
87
+ "we write to stdout.") do |val|
88
+ settings[:output] = val
89
+ end
90
+ args = opts.parse(ARGV)
91
+ docs = LogStashConfigAsciiDocGenerator.new
92
+ args.each do |arg|
93
+ docs.generate(arg, settings)
94
+ end
95
+ return 0
96
+ end,
97
+ "plugin" => lambda do
98
+ require 'logstash/pluginmanager'
99
+ plugin_manager = LogStash::PluginManager::Main.new($0)
100
+ begin
101
+ plugin_manager.parse(args)
102
+ return plugin_manager.execute
103
+ rescue Clamp::HelpWanted => e
104
+ show_help(e.command)
105
+ return 0
106
+ end
107
+ end,
108
+ "agent" => lambda do
109
+ require "logstash/agent"
110
+ # Hack up a runner
111
+ agent = LogStash::Agent.new($0)
112
+ begin
113
+ agent.parse(args)
114
+ rescue Clamp::HelpWanted => e
115
+ show_help(e.command)
116
+ return 0
117
+ rescue Clamp::UsageError => e
118
+ # If 'too many arguments' then give the arguments to
119
+ # the next command. Otherwise it's a real error.
120
+ raise if e.message != "too many arguments"
121
+ remaining = agent.remaining_arguments
122
+ end
123
+
124
+ return agent.execute
125
+ end
126
+ } # commands
127
+
128
+ if commands.include?(command)
129
+ return Stud::Task.new { commands[command].call }
130
+ else
131
+ if command.nil?
132
+ $stderr.puts "No command given"
133
+ else
134
+ if !%w(--help -h help).include?(command)
135
+ # Emit 'no such command' if it's not someone asking for help.
136
+ $stderr.puts "No such command #{command.inspect}"
137
+ end
138
+ end
139
+ $stderr.puts %q[
140
+ Usage: logstash <command> [command args]
141
+ Run a command with the --help flag to see the arguments.
142
+ For example: logstash agent --help
143
+
144
+ Available commands:
145
+ agent - runs the logstash agent
146
+ version - emits version info about this logstash
147
+ rspec - runs tests
148
+ ]
149
+ #$stderr.puts commands.keys.map { |s| " #{s}" }.join("\n")
150
+ return Stud::Task.new { 1 }
151
+ end
152
+ end # def run
153
+
154
+ # @return true if this file is the main file being run and not via rspec
155
+ def self.autorun?
156
+ # caller is the current execution stack
157
+ $0 == __FILE__ && caller.none?{|entry| entry =~ /rspec/}
158
+ end
159
+
160
+ private
161
+
162
+ def show_help(command)
163
+ puts command.help
164
+ end
165
+ end # class LogStash::Runner
166
+
167
+ LogStash::Runner.new.main(ARGV) if LogStash::Runner.autorun?