logstash-input-exec 3.2.0 → 3.3.0
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 +3 -0
- data/lib/logstash/inputs/exec.rb +43 -34
- data/logstash-input-exec.gemspec +1 -1
- data/spec/inputs/exec_spec.rb +28 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce9ee9b0271289948781bc4b076ab78e944c873d43a66ee3c0dd24a51d82e255
|
4
|
+
data.tar.gz: b91a2de52e523b0f1299582f01502d8c07046979772a413ff9aa5c5a917e9e27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c58e64c70dc75fff5fb89bb3648bbb52410a2cb35571ce72188b08b466e0db3ee5efc3436e1cf24dc1dd1182b553c3afae07789bc9e5edd9e780fa8b8d6749a
|
7
|
+
data.tar.gz: 8ea6953772bbc385bd4664ff900fc6cb68bb870154ed31197996150f821724ace54ab43e646a283d6677e80b11cd737ae85b60258d72bb5241fa78197043698e
|
data/CHANGELOG.md
CHANGED
data/lib/logstash/inputs/exec.rb
CHANGED
@@ -44,34 +44,65 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
|
|
44
44
|
if @schedule
|
45
45
|
@scheduler = Rufus::Scheduler.new(:max_work_threads => 1)
|
46
46
|
@scheduler.cron @schedule do
|
47
|
-
|
47
|
+
execute(queue)
|
48
48
|
end
|
49
49
|
@scheduler.join
|
50
50
|
else
|
51
51
|
while !stop?
|
52
|
-
duration =
|
52
|
+
duration = execute(queue)
|
53
53
|
wait_until_end_of_interval(duration)
|
54
54
|
end # loop
|
55
55
|
end
|
56
56
|
end # def run
|
57
57
|
|
58
|
-
def
|
58
|
+
def stop
|
59
|
+
close_io()
|
60
|
+
@scheduler.shutdown(:wait) if @scheduler
|
61
|
+
end
|
62
|
+
|
63
|
+
# Execute a given command
|
64
|
+
# @param [String] A command string
|
65
|
+
# @param [Array or Queue] A queue to append events to
|
66
|
+
def execute(queue)
|
59
67
|
start = Time.now
|
60
|
-
|
68
|
+
output = exit_status = nil
|
69
|
+
begin
|
70
|
+
@logger.debug? && @logger.debug("Running exec", :command => @command)
|
71
|
+
output, exit_status = run_command()
|
72
|
+
rescue StandardError => e
|
73
|
+
@logger.error("Error while running command",
|
74
|
+
:command => @command, :e => e, :backtrace => e.backtrace)
|
75
|
+
rescue Exception => e
|
76
|
+
@logger.error("Exception while running command",
|
77
|
+
:command => @command, :e => e, :backtrace => e.backtrace)
|
78
|
+
end
|
61
79
|
duration = Time.now - start
|
62
|
-
|
63
80
|
@logger.debug? && @logger.debug("Command completed", :command => @command, :duration => duration)
|
64
|
-
|
65
|
-
|
81
|
+
if output
|
82
|
+
@codec.decode(output) do |event|
|
83
|
+
decorate(event)
|
84
|
+
event.set("host", @hostname)
|
85
|
+
event.set("command", @command)
|
86
|
+
event.set("[@metadata][duration]", duration)
|
87
|
+
event.set("[@metadata][exit_status]", exit_status)
|
88
|
+
queue << event
|
89
|
+
end
|
90
|
+
end
|
91
|
+
duration
|
66
92
|
end
|
67
93
|
|
68
|
-
|
94
|
+
private
|
95
|
+
|
96
|
+
def run_command
|
97
|
+
@io = IO.popen(@command)
|
98
|
+
output = @io.read
|
99
|
+
@io.close # required in order to read $?
|
100
|
+
exit_status = $?.exitstatus # should be threadsafe as per rb_thread_save_context
|
101
|
+
[output, exit_status]
|
102
|
+
ensure
|
69
103
|
close_io()
|
70
|
-
@scheduler.shutdown(:wait) if @scheduler
|
71
104
|
end
|
72
105
|
|
73
|
-
private
|
74
|
-
|
75
106
|
# Close @io
|
76
107
|
def close_io
|
77
108
|
return if @io.nil? || @io.closed?
|
@@ -93,27 +124,5 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
|
|
93
124
|
end
|
94
125
|
end
|
95
126
|
|
96
|
-
|
97
|
-
# @param [String] A command string
|
98
|
-
# @param [Array or Queue] A queue to append events to
|
99
|
-
def execute(command, queue)
|
100
|
-
@logger.debug? && @logger.debug("Running exec", :command => command)
|
101
|
-
begin
|
102
|
-
@io = IO.popen(command)
|
103
|
-
@codec.decode(@io.read) do |event|
|
104
|
-
decorate(event)
|
105
|
-
event.set("host", @hostname)
|
106
|
-
event.set("command", command)
|
107
|
-
queue << event
|
108
|
-
end
|
109
|
-
rescue StandardError => e
|
110
|
-
@logger.error("Error while running command",
|
111
|
-
:command => command, :e => e, :backtrace => e.backtrace)
|
112
|
-
rescue Exception => e
|
113
|
-
@logger.error("Exception while running command",
|
114
|
-
:command => command, :e => e, :backtrace => e.backtrace)
|
115
|
-
ensure
|
116
|
-
close_io()
|
117
|
-
end
|
118
|
-
end
|
127
|
+
|
119
128
|
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 = '3.
|
4
|
+
s.version = '3.3.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Captures the output of a shell command 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/logstash-plugin install gemname. This gem is not a stand-alone program"
|
data/spec/inputs/exec_spec.rb
CHANGED
@@ -36,20 +36,45 @@ describe LogStash::Inputs::Exec do
|
|
36
36
|
input.register
|
37
37
|
expect(loggr).not_to receive(:error)
|
38
38
|
|
39
|
-
input.
|
39
|
+
input.execute(queue)
|
40
40
|
|
41
41
|
expect(queue.size).not_to be_zero
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
context "when a command runs normally" do
|
46
|
+
let(:input) { LogStash::Plugin.lookup("input", "exec").new("command" => "/bin/sh -c 'sleep 1; /bin/echo -n two; exit 3'", "interval" => 0) }
|
47
|
+
let(:queue) { [] }
|
48
|
+
|
49
|
+
before do
|
50
|
+
input.register
|
51
|
+
input.execute(queue)
|
52
|
+
end
|
53
|
+
|
54
|
+
after do
|
55
|
+
input.stop
|
56
|
+
end
|
57
|
+
|
58
|
+
it "has duration tracked" do
|
59
|
+
expect(queue.pop.get('[@metadata][duration]')).to be > 1
|
60
|
+
end
|
61
|
+
it "has output as expected" do
|
62
|
+
expect(queue.pop.get('message')).to eq "two"
|
63
|
+
end
|
64
|
+
it "has exit_status tracked" do
|
65
|
+
expect(queue.pop.get('[@metadata][exit_status]')).to eq 3
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
45
70
|
context "when scheduling" do
|
46
71
|
let(:input) { LogStash::Plugin.lookup("input", "exec").new("command" => "ls", "schedule" => "* * * * * UTC") }
|
47
72
|
let(:queue) { [] }
|
48
|
-
|
73
|
+
|
49
74
|
before do
|
50
75
|
input.register
|
51
76
|
end
|
52
|
-
|
77
|
+
|
53
78
|
it "should properly schedule" do
|
54
79
|
Timecop.travel(Time.new(2000))
|
55
80
|
Timecop.scale(60)
|
@@ -63,7 +88,6 @@ describe LogStash::Inputs::Exec do
|
|
63
88
|
expect(queue.size).to eq(2)
|
64
89
|
Timecop.return
|
65
90
|
end
|
66
|
-
|
67
91
|
end
|
68
92
|
|
69
93
|
context "when interrupting the plugin" do
|
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: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|