logstash-input-pipe 0.1.4 → 0.1.5

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: 186eac42ddcc84a5617b4230279f21b071271273
4
- data.tar.gz: 474b8c3e2d843ac67ad1f019e3a277f4fe23f1f3
3
+ metadata.gz: fd004399743c5e103d23b513388b0659e743e758
4
+ data.tar.gz: 5df2f4312e0e1ed558833063e796eb0ed18aa0e8
5
5
  SHA512:
6
- metadata.gz: 08aa2401c11aafcfa44ca8f699bd3bd42c465e8472556de08caf37651811bbc7b88c0f272aa5690e309bfb23f285b382a6cad46f60ec3a5b57eadbfaa1835e7b
7
- data.tar.gz: c820b097bc25d67177e6164c84185deb621e042b726e0fd89df2f5cd58da27cb586726121b9a68eb2583051af823f5d867f8e5a425228d7b25f193a80ea8a82b
6
+ metadata.gz: 97b65f55794d98ddf78467dde8ea3de77960330ed2d688a0e7b54d2c56e1b1d278595bd5483b4533cd42f817e8f5634d1772c27c92000de2419c20387742a33d
7
+ data.tar.gz: d4c628c49a7992007e196e049f6ee9bdb3e70123289c5dd08ba47876d8c53c9ab9acb78ac07d9c16610381cf3cdbcab9406893c3c6829223e01e1a287bc45356
@@ -26,6 +26,12 @@ class LogStash::Inputs::Pipe < LogStash::Inputs::Base
26
26
  # command => "echo hello world"
27
27
  config :command, :validate => :string, :required => true
28
28
 
29
+ def initialize(params)
30
+ super
31
+ @shutdown_requested = false
32
+ @pipe = nil
33
+ end # def initialize
34
+
29
35
  public
30
36
  def register
31
37
  @logger.info("Registering pipe input", :command => @command)
@@ -33,14 +39,13 @@ class LogStash::Inputs::Pipe < LogStash::Inputs::Base
33
39
 
34
40
  public
35
41
  def run(queue)
36
- loop do
42
+ while !@shutdown_requested
37
43
  begin
38
- @pipe = IO.popen(@command, mode="r")
44
+ @pipe = IO.popen(@command, mode = "r")
39
45
  hostname = Socket.gethostname
40
46
 
41
47
  @pipe.each do |line|
42
48
  line = line.chomp
43
- source = "pipe://#{hostname}/#{@command}"
44
49
  @logger.debug? && @logger.debug("Received line", :command => @command, :line => line)
45
50
  @codec.decode(line) do |event|
46
51
  event["host"] = hostname
@@ -49,6 +54,8 @@ class LogStash::Inputs::Pipe < LogStash::Inputs::Base
49
54
  queue << event
50
55
  end
51
56
  end
57
+ @pipe.close
58
+ @pipe = nil
52
59
  rescue LogStash::ShutdownSignal => e
53
60
  break
54
61
  rescue Exception => e
@@ -59,4 +66,15 @@ class LogStash::Inputs::Pipe < LogStash::Inputs::Base
59
66
  sleep(10)
60
67
  end
61
68
  end # def run
69
+
70
+ def teardown
71
+ @shutdown_requested = true
72
+ if @pipe
73
+ Process.kill("KILL", @pipe.pid) rescue nil
74
+ @pipe.close rescue nil
75
+ @pipe = nil
76
+ end
77
+ finished
78
+ end
79
+
62
80
  end # class LogStash::Inputs::Pipe
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-pipe'
4
- s.version = '0.1.4'
4
+ s.version = '0.1.5'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Stream events from a long running command pipe"
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,56 +4,52 @@ require "tempfile"
4
4
 
5
5
  describe "inputs/pipe", :unix => true do
6
6
 
7
- describe "echo" do
8
- event_count = 1
9
- tmp_file = Tempfile.new('logstash-spec-input-pipe')
10
-
11
- config <<-CONFIG
12
- input {
13
- pipe {
14
- command => "echo ☹"
7
+ # rince and repeat a few times to stress the shutdown sequence
8
+ 5.times.each do
9
+ it "should pipe from echo" do
10
+ conf = <<-CONFIG
11
+ input {
12
+ pipe {
13
+ command => "echo ☹"
14
+ }
15
15
  }
16
- }
17
- CONFIG
16
+ CONFIG
18
17
 
19
- input do |pipeline, queue|
20
- Thread.new { pipeline.run }
21
- sleep 0.1 while !pipeline.ready?
22
-
23
- events = event_count.times.collect { queue.pop }
24
- event_count.times do |i|
25
- insist { events[i]["message"] } == "☹"
18
+ event = input(conf) do |pipeline, queue|
19
+ queue.pop
26
20
  end
27
- end # input
28
- end
29
21
 
30
- describe "tail -f" do
31
- event_count = 10
32
- tmp_file = Tempfile.new('logstash-spec-input-pipe')
22
+ insist { event["message"] } == "☹"
23
+ end
24
+ end
33
25
 
34
- config <<-CONFIG
35
- input {
36
- pipe {
37
- command => "tail -f #{tmp_file.path}"
26
+ # rince and repeat a few times to stress the shutdown sequence
27
+ 5.times.each do
28
+ it "should pipe from tail -f" do
29
+ event_count = 10
30
+ tmp_file = Tempfile.new('logstash-spec-input-pipe')
31
+
32
+ conf = <<-CONFIG
33
+ input {
34
+ pipe {
35
+ command => "tail -n +0 -f #{tmp_file.path}"
36
+ }
38
37
  }
39
- }
40
- CONFIG
41
-
42
- input do |pipeline, queue|
43
- Thread.new { pipeline.run }
44
- sleep 0.1 while !pipeline.ready?
45
-
46
- File.open(tmp_file, "a") do |fd|
47
- event_count.times do |i|
48
- # unicode smiley for testing unicode support!
49
- fd.puts("#{i} ☹")
38
+ CONFIG
39
+
40
+ events = input(conf) do |pipeline, queue|
41
+ File.open(tmp_file, "a") do |fd|
42
+ event_count.times do |i|
43
+ # unicode smiley for testing unicode support!
44
+ fd.puts("#{i} ☹")
45
+ end
50
46
  end
47
+ event_count.times.map { queue.pop }
51
48
  end
52
- events = event_count.times.collect { queue.pop }
49
+
53
50
  event_count.times do |i|
54
51
  insist { events[i]["message"] } == "#{i} ☹"
55
52
  end
56
- end # input
53
+ end
57
54
  end
58
-
59
55
  end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-pipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elasticsearch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- requirement: !ruby/object:Gem::Requirement
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - '>='
17
18
  - !ruby/object:Gem::Version
@@ -19,10 +20,7 @@ dependencies:
19
20
  - - <
20
21
  - !ruby/object:Gem::Version
21
22
  version: 2.0.0
22
- name: logstash-core
23
- prerelease: false
24
- type: :runtime
25
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: !ruby/object:Gem::Requirement
26
24
  requirements:
27
25
  - - '>='
28
26
  - !ruby/object:Gem::Version
@@ -30,34 +28,36 @@ dependencies:
30
28
  - - <
31
29
  - !ruby/object:Gem::Version
32
30
  version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
33
  - !ruby/object:Gem::Dependency
34
+ name: logstash-codec-plain
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
34
40
  requirement: !ruby/object:Gem::Requirement
35
41
  requirements:
36
42
  - - '>='
37
43
  - !ruby/object:Gem::Version
38
44
  version: '0'
39
- name: logstash-codec-plain
40
45
  prerelease: false
41
46
  type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-devutils
42
49
  version_requirements: !ruby/object:Gem::Requirement
43
50
  requirements:
44
51
  - - '>='
45
52
  - !ruby/object:Gem::Version
46
53
  version: '0'
47
- - !ruby/object:Gem::Dependency
48
54
  requirement: !ruby/object:Gem::Requirement
49
55
  requirements:
50
56
  - - '>='
51
57
  - !ruby/object:Gem::Version
52
58
  version: '0'
53
- name: logstash-devutils
54
59
  prerelease: false
55
60
  type: :development
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - '>='
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
61
  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
62
  email: info@elasticsearch.com
63
63
  executables: []
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.4.5
98
+ rubygems_version: 2.1.9
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Stream events from a long running command pipe