logstash-input-exec 3.4.0 → 3.6.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
  SHA256:
3
- metadata.gz: 9c34902b8be4e548af7df0fa8a539ca5c795e9faeff9d4dccaa9d357e080c424
4
- data.tar.gz: d4d9f5e6aa8d1afd53e7d6fcb37f5e84277c3ea0038a44d0ec27577497447f8f
3
+ metadata.gz: 01d8e2cf6057c8c259d53f056dab08b583d222b367adda70a80a045eac7fa08d
4
+ data.tar.gz: 30536c1078190608e0894f9e018dc70cb7fffe0b72ce80ed08a36294d804def8
5
5
  SHA512:
6
- metadata.gz: 7ff940ad3f3a22894d5242d1ee3b5238e805af2e629c1aa7a93f1f7d5986cf70140c519c859abb2776101550b80b80c40c0669a60e9e0b6b1a2aa21ad8d19865
7
- data.tar.gz: 18f68b20afd72dde8384d8c5d39a468436666d3a43014425a1f17ffa6d42bdcd23e27dce2721f0f97ded83159375a2e9aec2d11de95b88fbc74475cd4107eeef
6
+ metadata.gz: cf1aa23f2e652c11dbdf22cfb78a1831ab0965befa58b69fbef3d83e71f85e65e98f48d71363df258aa087d9d01f0fdc43b784ec8ee4a38631af5d0615aee467
7
+ data.tar.gz: d517483d728e1c59f99bbce6318aeb685f0933e8300d1fbc144362c4828a40c67015edcaefe735b44c12b08f9a6ffff01e208cb3f6779581afc8cc7d37a2c407
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 3.6.0
2
+ - Refactor: start using scheduler mixin [#33](https://github.com/logstash-plugins/logstash-input-exec/pull/33)
3
+ - Fix: Test failures due to insufficient time given for scheduler to start [#32](https://github.com/logstash-plugins/logstash-input-exec/pull/32)
4
+
5
+ ## 3.5.0
6
+ - Fix: behavior incompatiblity between (standalone) LS and LS in Docker [#30](https://github.com/logstash-plugins/logstash-input-exec/pull/30)
7
+
1
8
  ## 3.4.0
2
9
  - Feat: adjust fields for ECS compatibility [#28](https://github.com/logstash-plugins/logstash-input-exec/pull/28)
3
10
  - Plugin will no longer override fields if they exist in the decoded payload.
@@ -1,11 +1,12 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/inputs/base"
3
3
  require "logstash/namespace"
4
+ require "open3"
4
5
  require "socket" # for Socket.gethostname
5
6
  require "stud/interval"
6
- require "rufus/scheduler"
7
7
 
8
8
  require 'logstash/plugin_mixins/ecs_compatibility_support'
9
+ require "logstash/plugin_mixins/scheduler"
9
10
 
10
11
  # Periodically run a shell command and capture the whole output as an event.
11
12
  #
@@ -17,6 +18,7 @@ require 'logstash/plugin_mixins/ecs_compatibility_support'
17
18
  class LogStash::Inputs::Exec < LogStash::Inputs::Base
18
19
 
19
20
  include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1, :v8 => :v1)
21
+ include LogStash::PluginMixins::Scheduler
20
22
 
21
23
  config_name "exec"
22
24
 
@@ -36,8 +38,7 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
36
38
 
37
39
  def register
38
40
  @hostname = Socket.gethostname.freeze
39
- @io = nil
40
-
41
+
41
42
  if (@interval.nil? && @schedule.nil?) || (@interval && @schedule)
42
43
  raise LogStash::ConfigurationError, "exec input: either 'interval' or 'schedule' option must be defined."
43
44
  end
@@ -53,11 +54,8 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
53
54
 
54
55
  def run(queue)
55
56
  if @schedule
56
- @scheduler = Rufus::Scheduler.new(:max_work_threads => 1)
57
- @scheduler.cron @schedule do
58
- execute(queue)
59
- end
60
- @scheduler.join
57
+ scheduler.cron(@schedule) { execute(queue) }
58
+ scheduler.join
61
59
  else
62
60
  while !stop?
63
61
  duration = execute(queue)
@@ -67,8 +65,7 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
67
65
  end # def run
68
66
 
69
67
  def stop
70
- close_io()
71
- @scheduler.shutdown(:wait) if @scheduler
68
+ close_out_and_in
72
69
  end
73
70
 
74
71
  # Execute a given command
@@ -105,20 +102,26 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
105
102
  private
106
103
 
107
104
  def run_command
108
- @io = IO.popen(@command)
109
- output = @io.read
110
- @io.close # required in order to read $?
111
- exit_status = $?.exitstatus
105
+ @p_in, @p_out, waiter = Open3.popen2(@command)
106
+ output = @p_out.read
107
+ exit_status = waiter.value.exitstatus
112
108
  [output, exit_status]
113
109
  ensure
114
- close_io()
110
+ close_out_and_in
111
+ end
112
+
113
+ def close_out_and_in
114
+ close_io(@p_out)
115
+ @p_out = nil
116
+ close_io(@p_in)
117
+ @p_in = nil
115
118
  end
116
119
 
117
- # Close @io
118
- def close_io
119
- return if @io.nil? || @io.closed?
120
- @io.close
121
- @io = nil
120
+ def close_io(io)
121
+ return if io.nil? || io.closed?
122
+ io.close
123
+ rescue => e
124
+ @logger.debug("ignoring exception raised while closing io", :io => io, :exception => e.class, :message => e.message)
122
125
  end
123
126
 
124
127
  # Wait until the end of the interval
@@ -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.0'
4
+ s.version = '3.6.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"
@@ -22,10 +22,10 @@ Gem::Specification.new do |s|
22
22
  # Gem dependencies
23
23
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
24
  s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~> 1.3'
25
+ s.add_runtime_dependency "logstash-mixin-scheduler", '~> 1.0'
25
26
 
26
27
  s.add_runtime_dependency 'stud', '~> 0.0.22'
27
28
  s.add_runtime_dependency 'logstash-codec-plain'
28
- s.add_runtime_dependency 'rufus-scheduler'
29
29
 
30
30
  s.add_development_dependency 'logstash-devutils'
31
31
  s.add_development_dependency 'timecop'
@@ -46,6 +46,23 @@ describe LogStash::Inputs::Exec, :ecs_compatibility_support do
46
46
  end
47
47
  end
48
48
 
49
+ context "when command fails" do
50
+ let(:input) { described_class.new("command" => "invalid_command 1 2 3", "interval" => 0) }
51
+ let(:queue) { [] }
52
+
53
+ before :each do
54
+ input.register
55
+ end
56
+
57
+ it "does not enqueue an event (in a non-Docker env)" do
58
+ expect(input.logger).to receive(:error).and_call_original
59
+
60
+ input.execute(queue)
61
+
62
+ expect(queue.map(&:to_hash)).to be_empty
63
+ end
64
+ end
65
+
49
66
  context "when a command runs normally" do
50
67
  let(:command) { "/bin/sh -c 'sleep 1; /bin/echo -n two; exit 3'" }
51
68
  let(:input) { described_class.new("command" => command, "interval" => 0) }
@@ -73,7 +90,7 @@ describe LogStash::Inputs::Exec, :ecs_compatibility_support do
73
90
  expect(elapsed_time).to be > 1 * 1_000_000
74
91
  expect(elapsed_time).to be < 3 * 1_000_000
75
92
  end if ecs_select.active_mode != :disabled
76
-
93
+
77
94
  it "has output as expected" do
78
95
  expect(queue.pop.get('message')).to eq "two"
79
96
  end
@@ -99,25 +116,28 @@ describe LogStash::Inputs::Exec, :ecs_compatibility_support do
99
116
  end
100
117
 
101
118
  context "when scheduling" do
102
- let(:input) { described_class.new("command" => "ls --help", "schedule" => "* * * * * UTC") }
119
+ let(:input) { described_class.new("command" => "ls --help", "schedule" => "5-6 * * * * UTC") }
103
120
  let(:queue) { [] }
104
121
 
105
122
  before do
123
+ Timecop.travel(Time.new(2000))
124
+ Timecop.scale(60)
106
125
  input.register
107
126
  end
108
127
 
128
+ after do
129
+ Timecop.return
130
+ end
131
+
109
132
  it "should properly schedule" do
110
- Timecop.travel(Time.new(2000))
111
- Timecop.scale(60)
112
133
  runner = Thread.new do
113
134
  input.run(queue)
114
135
  end
115
- sleep 3
136
+ sleep 10
116
137
  input.stop
117
138
  runner.kill
118
139
  runner.join
119
140
  expect(queue.size).to eq(2)
120
- Timecop.return
121
141
  end
122
142
  end
123
143
 
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.0
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2022-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -49,36 +49,36 @@ dependencies:
49
49
  requirements:
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
- version: 0.0.22
53
- name: stud
52
+ version: '1.0'
53
+ name: logstash-mixin-scheduler
54
54
  prerelease: false
55
55
  type: :runtime
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: 0.0.22
60
+ version: '1.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - ">="
64
+ - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: '0'
67
- name: logstash-codec-plain
66
+ version: 0.0.22
67
+ name: stud
68
68
  prerelease: false
69
69
  type: :runtime
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">="
72
+ - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: 0.0.22
75
75
  - !ruby/object:Gem::Dependency
76
76
  requirement: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
- name: rufus-scheduler
81
+ name: logstash-codec-plain
82
82
  prerelease: false
83
83
  type: :runtime
84
84
  version_requirements: !ruby/object:Gem::Requirement