logstash-input-exec 2.0.2 → 2.0.3

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: 9ee98f76ace84a124e270c9c0c549fa7ff1de3e4
4
- data.tar.gz: c282719c6909289b370b17d4a4880787cbf9e339
3
+ metadata.gz: 1838721f463687da2fdf8d3d94bb9aefb043b84d
4
+ data.tar.gz: 38275e923b71a58734c510c1924a0fe136748da0
5
5
  SHA512:
6
- metadata.gz: 9a78a43c27abc3944d56ba99a00aa7f1dccace2f06d85f95713a538c11150e12e1155504c4e45250c50605e794a0707ae687a4108ecfd9538e3909cceee70c94
7
- data.tar.gz: 008e043fa4f4c45fb544a4c0df16fffaea986350a01850c3be4ed771a1886ad3706d7a43c0eedeabfc0f8ecf63cd6f909b98962143accdc3dddee22d66d1ef6d
6
+ metadata.gz: c25fc3abcdcd4270a5dfa0af02e6816ffc37ee1006d5a4baa6f3cbd8dec3a2867892633be1c2705e2702b7eae177918fbedc09c2658c1b6dd9824798fffea703
7
+ data.tar.gz: f6dbccaf648dd4d1a6b94f37f665fbb52553de1b83ad1b52aa1383a205a6dd375dc5c3bdac354574c2a1c555b573386ef5c0faf2140c901c5849d3efcc7e0fca
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.0.3
2
+ - fix masked errors due to rescue Exception
3
+ - fix random race condition on closing io object
4
+ - refactor code for more reliable tests
1
5
  ## 2.0.1
2
6
  - Replace non-whitespace character in code
3
7
 
@@ -33,23 +33,25 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
33
33
  end # def register
34
34
 
35
35
  def run(queue)
36
-
37
36
  while !stop?
38
- start = Time.now
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)
37
+ inner_run(queue)
45
38
  end # loop
46
39
  end # def run
47
40
 
41
+ def inner_run(queue)
42
+ start = Time.now
43
+ execute(@command, queue)
44
+ duration = Time.now - start
45
+
46
+ @logger.info? && @logger.info("Command completed", :command => @command, :duration => duration)
47
+
48
+ wait_until_end_of_interval(duration)
49
+ end
50
+
48
51
  def stop
49
- if @io
50
- @io.close
51
- @io = nil
52
- end
52
+ return if @io.nil? || @io.closed?
53
+ @io.close
54
+ @io = nil
53
55
  end
54
56
 
55
57
  private
@@ -60,17 +62,18 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
60
62
  # Sleep for the remainder of the interval, or 0 if the duration ran
61
63
  # longer than the interval.
62
64
  sleeptime = [0, @interval - duration].max
63
- if sleeptime == 0
65
+ if sleeptime > 0
66
+ Stud.stoppable_sleep(sleeptime) { stop? }
67
+ else
64
68
  @logger.warn("Execution ran longer than the interval. Skipping sleep.",
65
69
  :command => @command, :duration => duration, :interval => @interval)
66
- else
67
- Stud.stoppable_sleep(sleeptime) { stop? }
68
70
  end
69
71
  end
70
72
 
71
73
  # Execute a given command
72
74
  # @param [String] A command string
73
- def execute(command)
75
+ # @param [Array or Queue] A queue to append events to
76
+ def execute(command, queue)
74
77
  @logger.info? && @logger.info("Running exec", :command => command)
75
78
  begin
76
79
  @io = IO.popen(command)
@@ -80,12 +83,14 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
80
83
  event["command"] = command
81
84
  queue << event
82
85
  end
86
+ rescue StandardError => e
87
+ @logger.error("Error while running command",
88
+ :command => command, :e => e, :backtrace => e.backtrace)
83
89
  rescue Exception => e
84
- @logger.error("Exception while running command", :e => e, :backtrace => e.backtrace)
90
+ @logger.error("Exception while running command",
91
+ :command => command, :e => e, :backtrace => e.backtrace)
85
92
  ensure
86
- @io.close
87
- @io = nil
93
+ stop
88
94
  end
89
95
  end
90
-
91
96
  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 = '2.0.2'
4
+ s.version = '2.0.3'
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"
@@ -4,20 +4,45 @@ require_relative "../spec_helper"
4
4
  describe LogStash::Inputs::Exec do
5
5
 
6
6
  it "should register" do
7
- input = LogStash::Plugin.lookup("input", "exec").new("command" => "uptime", "interval" => 0)
7
+ input = LogStash::Plugin.lookup("input", "exec").new("command" => "ls", "interval" => 0)
8
8
 
9
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
10
  expect {input.register}.to_not raise_error
11
11
  end
12
12
 
13
+ context "when operating normally" do
14
+ let(:input) { LogStash::Plugin.lookup("input", "exec").new("command" => "ls", "interval" => 0) }
15
+ let(:queue) { [] }
16
+ let(:loggr) { double('loggr') }
17
+
18
+ before do
19
+ allow(loggr).to receive(:info)
20
+ allow(loggr).to receive(:info?)
21
+ allow(loggr).to receive(:warn)
22
+ allow(loggr).to receive(:warn?)
23
+ allow(loggr).to receive(:debug)
24
+ allow(loggr).to receive(:debug?)
25
+ end
26
+
27
+ it "enqueues some events" do
28
+ input.logger = loggr
29
+ input.register
30
+ expect(loggr).not_to receive(:error)
31
+
32
+ input.inner_run(queue)
33
+
34
+ expect(queue.size).not_to be_zero
35
+ end
36
+ end
37
+
13
38
  context "when interrupting the plugin" do
14
39
 
15
40
  it_behaves_like "an interruptible input plugin" do
16
- let(:config) { { "command" => "uptime", "interval" => 0 } }
41
+ let(:config) { { "command" => "ls", "interval" => 0 } }
17
42
  end
18
43
 
19
44
  it_behaves_like "an interruptible input plugin" do
20
- let(:config) { { "command" => "uptime", "interval" => 100 } }
45
+ let(:config) { { "command" => "ls", "interval" => 100 } }
21
46
  end
22
47
 
23
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-exec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement