logstash-input-exec 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 305395f9da54e6b5ab85218a1e447767b656e229
4
- data.tar.gz: 8acf99875e32728c780aec5ccac84a133e9741f0
3
+ metadata.gz: eec72b75adc610d7f82a3086724de2d114aef6a2
4
+ data.tar.gz: 8c3c01dcaa78bcf8f58984e33d94ed94810788d4
5
5
  SHA512:
6
- metadata.gz: 813e0c6ec7727bbbda346b0dab7890cce02151d56a5b5d3add78de90b6a829d1b61ce3502d781315b788949b8aab516d7bdf21fca1ca49c0c3885b0ea132b3c4
7
- data.tar.gz: 2525248c677882dd049ddf80d32481a18320b347863c5c53d437664ce2589a0844ea05aa205831b5fb1b0561bca2f0049c38473b62a62da42e724514a83c566a
6
+ metadata.gz: 027c87842ed7a3959208afdb526a47fd094aebcea09b19579489dc049d7f1f6b9c61692d79436587f9efcd39b55bbdc23ee990477732277f090ad14f173b5e44
7
+ data.tar.gz: 265a6eecd2a5ab515ba66276e0c17d1ca1a4da7f9cf54a4c44181cbdb0608b79d0aee06e192fdf581dee61e7514c4ed9c3bd00327d0356bbcf80adef90b68611
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Logstash Plugin
2
2
 
3
- This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
4
 
5
5
  It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
6
 
7
7
  ## Documentation
8
8
 
9
- Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
10
 
11
11
  - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
- - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
13
 
14
14
  ## Need Help?
15
15
 
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
83
83
 
84
84
  It is more important to the community that you are able to contribute.
85
85
 
86
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -2,14 +2,14 @@
2
2
  require "logstash/inputs/base"
3
3
  require "logstash/namespace"
4
4
  require "socket" # for Socket.gethostname
5
+ require "stud/interval"
5
6
 
6
- # Run command line tools and capture the whole output as an event.
7
+ # Periodically run a shell command and capture the whole output as an event.
7
8
  #
8
9
  # Notes:
9
10
  #
10
- # * The `@source` of this event will be the command run.
11
- # * The `@message` of this event will be the entire stdout of the command
12
- # as one event.
11
+ # * The `command` field of this event will be the command run.
12
+ # * The `message` field of this event will be the entire stdout of the command.
13
13
  #
14
14
  class LogStash::Inputs::Exec < LogStash::Inputs::Base
15
15
 
@@ -26,42 +26,66 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
26
26
  # Interval to run the command. Value is in seconds.
27
27
  config :interval, :validate => :number, :required => true
28
28
 
29
- public
30
29
  def register
31
- @logger.info("Registering Exec Input", :type => @type,
32
- :command => @command, :interval => @interval)
30
+ @logger.info("Registering Exec Input", :type => @type, :command => @command, :interval => @interval)
31
+ @hostname = Socket.gethostname
32
+ @io = nil
33
33
  end # def register
34
34
 
35
- public
36
35
  def run(queue)
37
- hostname = Socket.gethostname
38
- loop do
36
+
37
+ while !stop?
39
38
  start = Time.now
40
- @logger.info? && @logger.info("Running exec", :command => @command)
41
- out = IO.popen(@command)
42
- # out.read will block until the process finishes.
43
- @codec.decode(out.read) do |event|
39
+ execute(@command)
40
+ duration = Time.now - start
41
+
42
+ @logger.info? && @logger.info("Command completed", :command => @command, :duration => duration)
43
+
44
+ wait_until_end_of_interval(duration)
45
+ end # loop
46
+ end # def run
47
+
48
+ def stop
49
+ if @io
50
+ @io.close
51
+ @io = nil
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ # Wait until the end of the interval
58
+ # @param [Integer] the duration of the last command executed
59
+ def wait_until_end_of_interval(duration)
60
+ # Sleep for the remainder of the interval, or 0 if the duration ran
61
+ # longer than the interval.
62
+ sleeptime = [0, @interval - duration].max
63
+ if sleeptime == 0
64
+ @logger.warn("Execution ran longer than the interval. Skipping sleep.",
65
+ :command => @command, :duration => duration, :interval => @interval)
66
+ else
67
+ Stud.stoppable_sleep(sleeptime) { stop? }
68
+ end
69
+ end
70
+
71
+ # Execute a given command
72
+ # @param [String] A command string
73
+ def execute(command)
74
+ @logger.info? && @logger.info("Running exec", :command => command)
75
+ begin
76
+ @io = IO.popen(command)
77
+ @codec.decode(@io.read) do |event|
44
78
  decorate(event)
45
- event["host"] = hostname
46
- event["command"] = @command
79
+ event["host"] = @hostname
80
+ event["command"] = command
47
81
  queue << event
48
82
  end
49
- out.close
83
+ rescue Exception => e
84
+ @logger.error("Exception while running command", :e => e, :backtrace => e.backtrace)
85
+ ensure
86
+ @io.close
87
+ @io = nil
88
+ end
89
+ end
50
90
 
51
- duration = Time.now - start
52
- @logger.info? && @logger.info("Command completed", :command => @command,
53
- :duration => duration)
54
-
55
- # Sleep for the remainder of the interval, or 0 if the duration ran
56
- # longer than the interval.
57
- sleeptime = [0, @interval - duration].max
58
- if sleeptime == 0
59
- @logger.warn("Execution ran longer than the interval. Skipping sleep.",
60
- :command => @command, :duration => duration,
61
- :interval => @interval)
62
- else
63
- sleep(sleeptime)
64
- end
65
- end # loop
66
- end # def run
67
91
  end # class LogStash::Inputs::Exec
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-exec'
4
- s.version = '1.0.0'
4
+ s.version = '2.0.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Run command line tools and capture the whole output as an event."
7
7
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.require_paths = ["lib"]
12
12
 
13
13
  # Files
14
- s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
14
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
15
 
16
16
  # Tests
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -20,8 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
21
21
 
22
22
  # Gem dependencies
23
- s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
24
-
23
+ s.add_runtime_dependency "logstash-core", "~> 2.0.0.snapshot"
24
+ s.add_runtime_dependency 'stud', '~> 0.0.22'
25
25
  s.add_runtime_dependency 'logstash-codec-plain'
26
26
 
27
27
  s.add_development_dependency 'logstash-devutils'
@@ -1 +1,25 @@
1
- require "logstash/devutils/rspec/spec_helper"
1
+ # encoding: utf-8
2
+ require_relative "../spec_helper"
3
+
4
+ describe LogStash::Inputs::Exec do
5
+
6
+ it "should register" do
7
+ input = LogStash::Plugin.lookup("input", "exec").new("command" => "uptime", "interval" => 0)
8
+
9
+ # register will try to load jars and raise if it cannot find jars or if org.apache.log4j.spi.LoggingEvent class is not present
10
+ expect {input.register}.to_not raise_error
11
+ end
12
+
13
+ context "when interrupting the plugin" do
14
+
15
+ it_behaves_like "an interruptible input plugin" do
16
+ let(:config) { { "command" => "uptime", "interval" => 0 } }
17
+ end
18
+
19
+ it_behaves_like "an interruptible input plugin" do
20
+ let(:config) { { "command" => "uptime", "interval" => 100 } }
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/exec"
metadata CHANGED
@@ -1,80 +1,87 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-exec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ~>
17
+ - !ruby/object:Gem::Version
18
+ version: 2.0.0.snapshot
14
19
  name: logstash-core
20
+ prerelease: false
21
+ type: :runtime
15
22
  version_requirements: !ruby/object:Gem::Requirement
16
23
  requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: 1.4.0
20
- - - <
24
+ - - ~>
21
25
  - !ruby/object:Gem::Version
22
- version: 2.0.0
26
+ version: 2.0.0.snapshot
27
+ - !ruby/object:Gem::Dependency
23
28
  requirement: !ruby/object:Gem::Requirement
24
29
  requirements:
25
- - - '>='
26
- - !ruby/object:Gem::Version
27
- version: 1.4.0
28
- - - <
30
+ - - ~>
29
31
  - !ruby/object:Gem::Version
30
- version: 2.0.0
32
+ version: 0.0.22
33
+ name: stud
31
34
  prerelease: false
32
35
  type: :runtime
33
- - !ruby/object:Gem::Dependency
34
- name: logstash-codec-plain
35
36
  version_requirements: !ruby/object:Gem::Requirement
36
37
  requirements:
37
- - - '>='
38
+ - - ~>
38
39
  - !ruby/object:Gem::Version
39
- version: '0'
40
+ version: 0.0.22
41
+ - !ruby/object:Gem::Dependency
40
42
  requirement: !ruby/object:Gem::Requirement
41
43
  requirements:
42
44
  - - '>='
43
45
  - !ruby/object:Gem::Version
44
46
  version: '0'
47
+ name: logstash-codec-plain
45
48
  prerelease: false
46
49
  type: :runtime
47
- - !ruby/object:Gem::Dependency
48
- name: logstash-devutils
49
50
  version_requirements: !ruby/object:Gem::Requirement
50
51
  requirements:
51
52
  - - '>='
52
53
  - !ruby/object:Gem::Version
53
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
54
56
  requirement: !ruby/object:Gem::Requirement
55
57
  requirements:
56
58
  - - '>='
57
59
  - !ruby/object:Gem::Version
58
60
  version: '0'
61
+ name: logstash-devutils
59
62
  prerelease: false
60
63
  type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
61
69
  description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
62
70
  email: info@elastic.co
63
71
  executables: []
64
72
  extensions: []
65
73
  extra_rdoc_files: []
66
74
  files:
67
- - .gitignore
68
75
  - CHANGELOG.md
69
76
  - CONTRIBUTORS
70
77
  - Gemfile
71
78
  - LICENSE
72
79
  - NOTICE.TXT
73
80
  - README.md
74
- - Rakefile
75
81
  - lib/logstash/inputs/exec.rb
76
82
  - logstash-input-exec.gemspec
77
83
  - spec/inputs/exec_spec.rb
84
+ - spec/spec_helper.rb
78
85
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
79
86
  licenses:
80
87
  - Apache License (2.0)
@@ -97,9 +104,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
104
  version: '0'
98
105
  requirements: []
99
106
  rubyforge_project:
100
- rubygems_version: 2.2.2
107
+ rubygems_version: 2.4.8
101
108
  signing_key:
102
109
  specification_version: 4
103
110
  summary: Run command line tools and capture the whole output as an event.
104
111
  test_files:
105
112
  - spec/inputs/exec_spec.rb
113
+ - spec/spec_helper.rb
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- Gemfile.lock
3
- .bundle
4
- vendor
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- @files=[]
2
-
3
- task :default do
4
- system("rake -T")
5
- end
6
-
7
- require "logstash/devutils/rake"