logstash-input-unix 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/logstash/inputs/unix.rb +21 -44
- data/logstash-input-unix.gemspec +3 -3
- data/spec/inputs/unix_spec.rb +51 -1
- data/spec/spec_helper.rb +33 -0
- metadata +19 -25
- data/.gitignore +0 -4
- data/Rakefile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef37b6ec56baca1660701d989e36a7896e73f2d8
|
4
|
+
data.tar.gz: 88f5eb311cafe9f088db03df8bdd2d03f376bfba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b33029bc4b66ae9d0ecf0d4a443a85b92c381aac27dd15e5600e6255eb524a0d22fe38c9ccca36cd2971c5bf5533b88f02e46b6586d9cc5ec9fa78780b5c741
|
7
|
+
data.tar.gz: 9441f735054e324611531bb7b1e868bdcc6638f76024db724ed4fea20188e960a2caab9b4c6d583b8e6f3dd9d875e0b824908a3871706e59f9a5f87e5dfa11cc
|
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Logstash Plugin
|
2
2
|
|
3
|
-
This is a plugin for [Logstash](https://github.com/
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
4
|
|
5
5
|
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
6
6
|
|
7
7
|
## Documentation
|
8
8
|
|
9
|
-
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.
|
9
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
10
10
|
|
11
11
|
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
12
|
-
- For more asciidoc formatting tips, see the excellent reference here https://github.com/
|
12
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
13
13
|
|
14
14
|
## Need Help?
|
15
15
|
|
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
|
|
83
83
|
|
84
84
|
It is more important to the community that you are able to contribute.
|
85
85
|
|
86
|
-
For more information about contributing, see the [CONTRIBUTING](https://github.com/
|
86
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
data/lib/logstash/inputs/unix.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "logstash/inputs/base"
|
3
3
|
require "logstash/namespace"
|
4
|
-
require "
|
4
|
+
require "logstash/util/socket_peer"
|
5
5
|
|
6
6
|
# Read events over a UNIX socket.
|
7
7
|
#
|
@@ -68,7 +68,7 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
|
|
68
68
|
def handle_socket(socket, output_queue)
|
69
69
|
begin
|
70
70
|
hostname = Socket.gethostname
|
71
|
-
|
71
|
+
while !stop?
|
72
72
|
buf = nil
|
73
73
|
# NOTE(petef): the timeout only hits after the line is read
|
74
74
|
# or socket dies
|
@@ -86,13 +86,11 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
|
|
86
86
|
event["path"] = @path
|
87
87
|
output_queue << event
|
88
88
|
end
|
89
|
-
end
|
89
|
+
end
|
90
90
|
rescue => e
|
91
|
-
@logger.debug("Closing connection", :path => @path,
|
92
|
-
:exception => e, :backtrace => e.backtrace)
|
91
|
+
@logger.debug("Closing connection", :path => @path, :exception => e, :backtrace => e.backtrace)
|
93
92
|
rescue Timeout::Error
|
94
|
-
@logger.debug("Closing connection after read timeout",
|
95
|
-
:path => @path)
|
93
|
+
@logger.debug("Closing connection after read timeout", :path => @path)
|
96
94
|
end # begin
|
97
95
|
|
98
96
|
ensure
|
@@ -100,7 +98,7 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
|
|
100
98
|
socket.close
|
101
99
|
rescue IOError
|
102
100
|
#pass
|
103
|
-
end
|
101
|
+
end
|
104
102
|
end
|
105
103
|
|
106
104
|
private
|
@@ -111,52 +109,31 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
|
|
111
109
|
public
|
112
110
|
def run(output_queue)
|
113
111
|
if server?
|
114
|
-
@thread = Thread.current
|
115
112
|
@client_threads = []
|
116
|
-
|
113
|
+
while !stop?
|
117
114
|
# Start a new thread for each connection.
|
118
|
-
|
119
|
-
@
|
120
|
-
|
121
|
-
|
122
|
-
@logger.debug("Accepted connection",
|
123
|
-
:server => "#{@path}")
|
124
|
-
begin
|
125
|
-
handle_socket(s, output_queue)
|
126
|
-
rescue Interrupted
|
127
|
-
s.close rescue nil
|
128
|
-
end
|
129
|
-
end # Thread.start
|
130
|
-
rescue IOError, Interrupted
|
131
|
-
if @interrupted
|
132
|
-
# Intended shutdown, get out of the loop
|
133
|
-
@server_socket.close
|
134
|
-
@client_threads.each do |thread|
|
135
|
-
thread.raise(IOError.new)
|
136
|
-
end
|
137
|
-
break
|
138
|
-
else
|
139
|
-
# Else it was a genuine IOError caused by something else, so propagate it up..
|
140
|
-
raise
|
141
|
-
end
|
115
|
+
@client_threads << Thread.start(@server_socket.accept) do |s|
|
116
|
+
@logger.debug("Accepted connection", :server => "#{@path}")
|
117
|
+
handle_socket(s, output_queue)
|
142
118
|
end
|
143
|
-
end
|
119
|
+
end
|
144
120
|
else
|
145
|
-
|
146
|
-
client_socket = UNIXSocket.new(@path)
|
147
|
-
client_socket.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
|
121
|
+
while !stop?
|
122
|
+
@client_socket = UNIXSocket.new(@path)
|
123
|
+
@client_socket.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
|
148
124
|
@logger.debug("Opened connection", :client => @path)
|
149
|
-
handle_socket(client_socket, output_queue)
|
150
|
-
end
|
125
|
+
handle_socket(@client_socket, output_queue)
|
126
|
+
end
|
151
127
|
end
|
152
128
|
end # def run
|
153
129
|
|
154
130
|
public
|
155
|
-
def
|
131
|
+
def stop
|
156
132
|
if server?
|
157
133
|
File.unlink(@path)
|
158
|
-
@
|
159
|
-
|
134
|
+
@server_socket.close
|
135
|
+
else
|
136
|
+
@client_socket.close
|
160
137
|
end
|
161
|
-
end # def
|
138
|
+
end # def stop
|
162
139
|
end # class LogStash::Inputs::Unix
|
data/logstash-input-unix.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-input-unix'
|
4
|
-
s.version = '
|
4
|
+
s.version = '2.0.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Read events over a UNIX socket."
|
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"
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.require_paths = ["lib"]
|
12
12
|
|
13
13
|
# Files
|
14
|
-
s.files =
|
14
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
15
15
|
|
16
16
|
# Tests
|
17
17
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
|
21
21
|
|
22
22
|
# Gem dependencies
|
23
|
-
s.add_runtime_dependency "logstash-core",
|
23
|
+
s.add_runtime_dependency "logstash-core", "~> 2.0.0.snapshot"
|
24
24
|
|
25
25
|
s.add_runtime_dependency 'logstash-codec-line'
|
26
26
|
s.add_development_dependency 'logstash-devutils'
|
data/spec/inputs/unix_spec.rb
CHANGED
@@ -1 +1,51 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative "../spec_helper"
|
3
|
+
require "stud/temporary"
|
4
|
+
require "tempfile"
|
5
|
+
|
6
|
+
describe LogStash::Inputs::Unix do
|
7
|
+
|
8
|
+
let(:tempfile) { Tempfile.new("/tmp/foo") }
|
9
|
+
|
10
|
+
it "should register without errors" do
|
11
|
+
plugin = LogStash::Plugin.lookup("input", "unix").new({ "path" => tempfile.path, "force_unlink" => true })
|
12
|
+
expect { plugin.register }.to_not raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "when interrupting the plugin" do
|
16
|
+
|
17
|
+
context "#server" do
|
18
|
+
it_behaves_like "an interruptible input plugin" do
|
19
|
+
let(:config) { { "path" => tempfile.path, "force_unlink" => true } }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "#client" do
|
24
|
+
let(:tempfile) { "/tmp/sock#{rand(65532)}" }
|
25
|
+
let(:config) { { "path" => tempfile, "mode" => "client" } }
|
26
|
+
let(:unix_socket) { UnixSocketHelper.new.new_socket(tempfile) }
|
27
|
+
let(:run_forever) { true }
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
unix_socket.loop(run_forever)
|
31
|
+
end
|
32
|
+
|
33
|
+
after(:each) do
|
34
|
+
unix_socket.close
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when the unix socket has data to be read" do
|
38
|
+
it_behaves_like "an interruptible input plugin" do
|
39
|
+
let(:run_forever) { true }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when the unix socket has no data to be read" do
|
44
|
+
it_behaves_like "an interruptible input plugin" do
|
45
|
+
let(:run_forever) { false }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require 'logstash/inputs/unix'
|
4
|
+
|
5
|
+
class UnixSocketHelper
|
6
|
+
|
7
|
+
attr_reader :path
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@socket = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_socket(path)
|
14
|
+
@path = path
|
15
|
+
File.unlink if File.exists?(path) && File.socket?(path)
|
16
|
+
@socket = UNIXServer.new(path)
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def loop(forever=false)
|
21
|
+
@thread = Thread.new do
|
22
|
+
s = @socket.accept
|
23
|
+
s.puts "hi" while forever
|
24
|
+
end
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def close
|
29
|
+
@thread.kill
|
30
|
+
@socket.close
|
31
|
+
File.unlink(path)
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,80 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-unix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: logstash-core
|
15
|
-
version_requirements: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.4.0
|
20
|
-
- - <
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.0.0
|
23
14
|
requirement: !ruby/object:Gem::Requirement
|
24
15
|
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: 1.4.0
|
28
|
-
- - <
|
16
|
+
- - ~>
|
29
17
|
- !ruby/object:Gem::Version
|
30
|
-
version: 2.0.0
|
18
|
+
version: 2.0.0.snapshot
|
19
|
+
name: logstash-core
|
31
20
|
prerelease: false
|
32
21
|
type: :runtime
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: logstash-codec-line
|
35
22
|
version_requirements: !ruby/object:Gem::Requirement
|
36
23
|
requirements:
|
37
|
-
- -
|
24
|
+
- - ~>
|
38
25
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
26
|
+
version: 2.0.0.snapshot
|
27
|
+
- !ruby/object:Gem::Dependency
|
40
28
|
requirement: !ruby/object:Gem::Requirement
|
41
29
|
requirements:
|
42
30
|
- - '>='
|
43
31
|
- !ruby/object:Gem::Version
|
44
32
|
version: '0'
|
33
|
+
name: logstash-codec-line
|
45
34
|
prerelease: false
|
46
35
|
type: :runtime
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: logstash-devutils
|
49
36
|
version_requirements: !ruby/object:Gem::Requirement
|
50
37
|
requirements:
|
51
38
|
- - '>='
|
52
39
|
- !ruby/object:Gem::Version
|
53
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
54
42
|
requirement: !ruby/object:Gem::Requirement
|
55
43
|
requirements:
|
56
44
|
- - '>='
|
57
45
|
- !ruby/object:Gem::Version
|
58
46
|
version: '0'
|
47
|
+
name: logstash-devutils
|
59
48
|
prerelease: false
|
60
49
|
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
61
55
|
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
56
|
email: info@elastic.co
|
63
57
|
executables: []
|
64
58
|
extensions: []
|
65
59
|
extra_rdoc_files: []
|
66
60
|
files:
|
67
|
-
- .gitignore
|
68
61
|
- CHANGELOG.md
|
69
62
|
- CONTRIBUTORS
|
70
63
|
- Gemfile
|
71
64
|
- LICENSE
|
72
65
|
- NOTICE.TXT
|
73
66
|
- README.md
|
74
|
-
- Rakefile
|
75
67
|
- lib/logstash/inputs/unix.rb
|
76
68
|
- logstash-input-unix.gemspec
|
77
69
|
- spec/inputs/unix_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
78
71
|
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
79
72
|
licenses:
|
80
73
|
- Apache License (2.0)
|
@@ -97,9 +90,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
90
|
version: '0'
|
98
91
|
requirements: []
|
99
92
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
93
|
+
rubygems_version: 2.4.8
|
101
94
|
signing_key:
|
102
95
|
specification_version: 4
|
103
96
|
summary: Read events over a UNIX socket.
|
104
97
|
test_files:
|
105
98
|
- spec/inputs/unix_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
data/.gitignore
DELETED