logstash-input-exec 2.0.2 → 2.0.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/logstash/inputs/exec.rb +25 -20
- data/logstash-input-exec.gemspec +1 -1
- data/spec/inputs/exec_spec.rb +28 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1838721f463687da2fdf8d3d94bb9aefb043b84d
|
4
|
+
data.tar.gz: 38275e923b71a58734c510c1924a0fe136748da0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c25fc3abcdcd4270a5dfa0af02e6816ffc37ee1006d5a4baa6f3cbd8dec3a2867892633be1c2705e2702b7eae177918fbedc09c2658c1b6dd9824798fffea703
|
7
|
+
data.tar.gz: f6dbccaf648dd4d1a6b94f37f665fbb52553de1b83ad1b52aa1383a205a6dd375dc5c3bdac354574c2a1c555b573386ef5c0faf2140c901c5849d3efcc7e0fca
|
data/CHANGELOG.md
CHANGED
data/lib/logstash/inputs/exec.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
51
|
-
|
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
|
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
|
-
|
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",
|
90
|
+
@logger.error("Exception while running command",
|
91
|
+
:command => command, :e => e, :backtrace => e.backtrace)
|
85
92
|
ensure
|
86
|
-
|
87
|
-
@io = nil
|
93
|
+
stop
|
88
94
|
end
|
89
95
|
end
|
90
|
-
|
91
96
|
end # class LogStash::Inputs::Exec
|
data/logstash-input-exec.gemspec
CHANGED
@@ -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.
|
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"
|
data/spec/inputs/exec_spec.rb
CHANGED
@@ -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" => "
|
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" => "
|
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" => "
|
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.
|
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-
|
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
|