logstash-input-unix 3.0.5 → 3.1.1

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
- SHA1:
3
- metadata.gz: 7bb630baf9c8d17039e40ba0c11047078ae27267
4
- data.tar.gz: 81fbec03d16d6bfe1fbae745a8dfe7a98aae50d3
2
+ SHA256:
3
+ metadata.gz: 211693d1622019fadfcdd5f41b94b7e15594abc983aa54000ea59353392b5d4e
4
+ data.tar.gz: a8b25c6eb9e1627b502b9177f17510d0e631a72c87883058f3d1f2fa93cb145e
5
5
  SHA512:
6
- metadata.gz: 16c5e41bd9bb88505ebfe9c676d1d916f2e74791d272c46813d94881e9139f23df7ff917027854d90e047546e29eab0001cb2386b155bb716fb8a5e9082c6e33
7
- data.tar.gz: 03c78b33f8280162e78a2884d8448015d444e5185c05572ccca783adad0be04b9fd57595f2942c22bd7ce7a6480d1ac2f7966c18b985fcd855643f1a41399af5
6
+ metadata.gz: 8c3c0d4cc5bcdee9fb3a32de4593764f9b458861401569ecd16b6055bb905b4d0bf06da68824d0a8358a77e7f4bce2546736a28c407a6a02535150e85364d375
7
+ data.tar.gz: da09882dac50d95baef03af89fc1b577ddbd31576d28cbdd02dc42fa350284512050480b231dd59ac6da247d8ec84a71c728ab656a29eb1cf443c0b63a440353
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 3.1.1
2
+ - Fix: unable to stop plugin (on LS 6.x) [#29](https://github.com/logstash-plugins/logstash-input-unix/pull/29)
3
+ - Refactor: plugin internals got reviewed for `data_timeout => ...` to work reliably
4
+
5
+ ## 3.1.0
6
+ - Feat: adjust fields for ECS compatibility [#28](https://github.com/logstash-plugins/logstash-input-unix/pull/28)
7
+
8
+ ## 3.0.7
9
+ - Docs: Set the default_codec doc attribute.
10
+
11
+ ## 3.0.6
12
+ - Update gemspec summary
13
+
1
14
  ## 3.0.5
2
15
  - Fix some documentation issues
3
16
 
data/LICENSE CHANGED
@@ -1,13 +1,202 @@
1
- Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
1
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
6
5
 
7
- http://www.apache.org/licenses/LICENSE-2.0
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
7
 
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 Elastic and contributors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Logstash Plugin
2
2
 
3
- [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-input-unix.svg)](https://travis-ci.org/logstash-plugins/logstash-input-unix)
3
+ [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-input-unix.svg)](https://travis-ci.com/logstash-plugins/logstash-input-unix)
4
4
 
5
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
6
 
data/docs/index.asciidoc CHANGED
@@ -1,5 +1,6 @@
1
1
  :plugin: unix
2
2
  :type: input
3
+ :default_codec: line
3
4
 
4
5
  ///////////////////////////////////////////
5
6
  START - GENERATED VARIABLES, DO NOT EDIT!
@@ -27,6 +28,23 @@ Like `stdin` and `file` inputs, each event is assumed to be one line of text.
27
28
  Can either accept connections from clients or connect to a server,
28
29
  depending on `mode`.
29
30
 
31
+ [id="plugins-{type}s-{plugin}-ecs"]
32
+ ==== Compatibility with the Elastic Common Schema (ECS)
33
+
34
+ This plugin adds extra fields about the event's source.
35
+ Configure the <<plugins-{type}s-{plugin}-ecs_compatibility>> option if you want
36
+ to ensure that these fields are compatible with {ecs-ref}[ECS].
37
+
38
+ These fields are added after the event has been decoded by the appropriate codec,
39
+ and will not overwrite existing values.
40
+
41
+ |========
42
+ | ECS Disabled | ECS v1 , v8 | Description
43
+
44
+ | `host` | `[host][name]` | The name of the {ls} host that processed the event
45
+ | `path` | `[file][path]` | The socket path configured in the plugin
46
+ |========
47
+
30
48
  [id="plugins-{type}s-{plugin}-options"]
31
49
  ==== Unix Input Configuration Options
32
50
 
@@ -36,6 +54,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
36
54
  |=======================================================================
37
55
  |Setting |Input type|Required
38
56
  | <<plugins-{type}s-{plugin}-data_timeout>> |<<number,number>>|No
57
+ | <<plugins-{type}s-{plugin}-ecs_compatibility>> |<<string,string>>|No
39
58
  | <<plugins-{type}s-{plugin}-force_unlink>> |<<boolean,boolean>>|No
40
59
  | <<plugins-{type}s-{plugin}-mode>> |<<string,string>>, one of `["server", "client"]`|No
41
60
  | <<plugins-{type}s-{plugin}-path>> |<<string,string>>|Yes
@@ -58,6 +77,44 @@ more than this timeout period, we will assume it is dead and close it.
58
77
 
59
78
  If you never want to timeout, use -1.
60
79
 
80
+ [id="plugins-{type}s-{plugin}-ecs_compatibility"]
81
+ ===== `ecs_compatibility`
82
+
83
+ * Value type is <<string,string>>
84
+ * Supported values are:
85
+ ** `disabled`: uses backwards compatible field names, such as `[host]`
86
+ ** `v1`, `v8`: uses fields that are compatible with ECS, such as `[host][name]`
87
+
88
+ Controls this plugin's compatibility with the {ecs-ref}[Elastic Common Schema (ECS)].
89
+ See <<plugins-{type}s-{plugin}-ecs>> for detailed information.
90
+
91
+
92
+ **Sample output: ECS enabled**
93
+ [source,ruby]
94
+ -----
95
+ {
96
+ "@timestamp" => 2021-11-16T13:20:06.308Z,
97
+ "file" => {
98
+ "path" => "/tmp/sock41299"
99
+ },
100
+ "host" => {
101
+ "name" => "deus-ex-machina"
102
+ },
103
+ "message" => "foo"
104
+ }
105
+ -----
106
+
107
+ **Sample output: ECS disabled**
108
+ [source,ruby]
109
+ -----
110
+ {
111
+ "@timestamp" => 2021-11-16T13:20:06.308Z,
112
+ "path" => "/tmp/sock41299",
113
+ "host" => "deus-ex-machina",
114
+ "message" => "foo"
115
+ }
116
+ -----
117
+
61
118
  [id="plugins-{type}s-{plugin}-force_unlink"]
62
119
  ===== `force_unlink`
63
120
 
@@ -100,4 +157,6 @@ This setting is only used if `mode` is `client`.
100
157
 
101
158
 
102
159
  [id="plugins-{type}s-{plugin}-common-options"]
103
- include::{include_path}/{type}.asciidoc[]
160
+ include::{include_path}/{type}.asciidoc[]
161
+
162
+ :default_codec!:
@@ -3,6 +3,8 @@ require "logstash/inputs/base"
3
3
  require "logstash/namespace"
4
4
  require "logstash/util/socket_peer"
5
5
 
6
+ require 'logstash/plugin_mixins/ecs_compatibility_support'
7
+
6
8
  # Read events over a UNIX socket.
7
9
  #
8
10
  # Like `stdin` and `file` inputs, each event is assumed to be one line of text.
@@ -10,7 +12,9 @@ require "logstash/util/socket_peer"
10
12
  # Can either accept connections from clients or connect to a server,
11
13
  # depending on `mode`.
12
14
  class LogStash::Inputs::Unix < LogStash::Inputs::Base
13
- class Interrupted < StandardError; end
15
+
16
+ include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1, :v8 => :v1)
17
+
14
18
  config_name "unix"
15
19
 
16
20
  default :codec, "line"
@@ -38,17 +42,19 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
38
42
  # This setting is only used if `mode` is `client`.
39
43
  config :socket_not_present_retry_interval_seconds, :validate => :number, :required => true, :default => 5
40
44
 
41
- def initialize(*args)
42
- super(*args)
45
+ def initialize(*params)
46
+ super
47
+
48
+ @host_name_field = ecs_select[disabled: 'host', v1: '[host][name]']
49
+ @file_path_field = ecs_select[disabled: 'path', v1: '[file][path]']
43
50
  end # def initialize
44
51
 
45
52
  public
46
53
  def register
47
54
  require "socket"
48
- require "timeout"
49
55
 
50
56
  if server?
51
- @logger.info("Starting unix input listener", :address => "#{@path}", :force_unlink => "#{@force_unlink}")
57
+ @logger.info("Starting unix input listener", :address => @path, :force_unlink => @force_unlink)
52
58
  begin
53
59
  @server_socket = UNIXServer.new(@path)
54
60
  rescue Errno::EADDRINUSE, IOError
@@ -58,18 +64,16 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
58
64
  @server_socket = UNIXServer.new(@path)
59
65
  return
60
66
  rescue Errno::EADDRINUSE, IOError
61
- @logger.error("!!!Could not start UNIX server: Address in use",
62
- :path => @path)
67
+ @logger.error("Could not start UNIX server: address in use", :path => @path)
63
68
  raise
64
69
  end
65
70
  end
66
- @logger.error("Could not start UNIX server: Address in use",
67
- :path => @path)
71
+ @logger.error("Could not start UNIX server: address in use", :path => @path)
68
72
  raise
69
73
  end
70
74
  else # client
71
- if @socket_not_present_retry_interval_seconds < 0
72
- @logger.warn("Value #{@socket_not_present_retry_interval_seconds} for socket_not_present_retry_interval_seconds is not valid, using default value of 5 instead")
75
+ if socket_not_present_retry_interval_seconds < 0
76
+ @logger.warn("Value #{socket_not_present_retry_interval_seconds} for socket_not_present_retry_interval_seconds is not valid, using default value of 5 instead")
73
77
  @socket_not_present_retry_interval_seconds = 5
74
78
  end
75
79
  end
@@ -80,30 +84,32 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
80
84
  begin
81
85
  hostname = Socket.gethostname
82
86
  while !stop?
83
- buf = nil
84
- # NOTE(petef): the timeout only hits after the line is read
85
- # or socket dies
86
- # TODO(sissel): Why do we have a timeout here? What's the point?
87
- if @data_timeout == -1
88
- buf = socket.readpartial(16384)
89
- else
90
- Timeout::timeout(@data_timeout) do
91
- buf = socket.readpartial(16384)
87
+ data = socket.read_nonblock(16384, exception: false)
88
+
89
+ if data == :wait_readable
90
+ if @data_timeout == -1 || IO.select([socket], nil, nil, @data_timeout)
91
+ next # retry socket read
92
+ else
93
+ # socket not ready after @data_timeout seconds
94
+ @logger.info("Closing connection after read timeout", :path => @path)
95
+ return
92
96
  end
93
97
  end
94
- @codec.decode(buf) do |event|
98
+
99
+ @codec.decode(data) do |event|
95
100
  decorate(event)
96
- event.set("host", hostname) unless event.include?("host")
97
- event.set("path", @path) unless event.include?("path")
101
+ event.set(@host_name_field, hostname) unless event.include?(@host_name_field)
102
+ event.set(@file_path_field, @path) unless event.include?(@file_path_field)
98
103
  output_queue << event
99
104
  end
100
105
  end
101
106
  rescue => e
102
- @logger.debug("Closing connection", :path => @path, :exception => e, :backtrace => e.backtrace)
103
- rescue Timeout::Error
104
- @logger.debug("Closing connection after read timeout", :path => @path)
105
- end # begin
106
-
107
+ if @logger.debug?
108
+ @logger.debug("Closing connection", :path => @path, :exception => e, :backtrace => e.backtrace)
109
+ else
110
+ @logger.info("Closing connection", :path => @path, :exception => e)
111
+ end
112
+ end
107
113
  ensure
108
114
  begin
109
115
  socket.close
@@ -124,20 +130,20 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
124
130
  while !stop?
125
131
  # Start a new thread for each connection.
126
132
  @client_threads << Thread.start(@server_socket.accept) do |s|
127
- @logger.debug("Accepted connection", :server => "#{@path}")
133
+ @logger.debug("Accepted connection", :server => @path)
128
134
  handle_socket(s, output_queue)
129
135
  end
130
136
  end
131
137
  else
132
138
  while !stop?
133
- if File.socket?(@path) then
139
+ if File.socket?(@path)
134
140
  @client_socket = UNIXSocket.new(@path)
135
- @client_socket.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
141
+ @client_socket.extend ::LogStash::Util::SocketPeer
136
142
  @logger.debug("Opened connection", :client => @path)
137
143
  handle_socket(@client_socket, output_queue)
138
144
  else
139
- @logger.warn("Socket not present, wait for #{@subscription_retry_interval_seconds} seconds for socket to appear", :client => @path)
140
- sleep @socket_not_present_retry_interval_seconds
145
+ @logger.warn("Socket not present, wait for #{socket_not_present_retry_interval_seconds} seconds for socket to appear", :client => @path)
146
+ sleep socket_not_present_retry_interval_seconds
141
147
  end
142
148
  end
143
149
  end
@@ -158,6 +164,6 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
158
164
  rescue IOError
159
165
  # if socket with @mode == client was closed by the client, an other call to @client_socket.close
160
166
  # will raise an IOError. We catch IOError here and do nothing, just let logstash terminate
161
- @logger.warn("Cloud not close socket while Logstash is shutting down. Socket already closed by the other party?", :path => @path)
167
+ @logger.warn("Could not close socket while Logstash is shutting down. Socket already closed by the other party?", :path => @path)
162
168
  end # def stop
163
169
  end # class LogStash::Inputs::Unix
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-unix'
4
- s.version = '3.0.5'
4
+ s.version = '3.1.1'
5
5
  s.licenses = ['Apache License (2.0)']
6
- s.summary = "Read events over a UNIX socket."
6
+ s.summary = "Reads 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/logstash-plugin install gemname. This gem is not a stand-alone program"
8
8
  s.authors = ["Elastic"]
9
9
  s.email = 'info@elastic.co'
@@ -21,8 +21,9 @@ Gem::Specification.new do |s|
21
21
 
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
25
  s.add_runtime_dependency 'logstash-codec-line'
26
+
26
27
  s.add_development_dependency 'logstash-devutils'
27
28
  end
28
29
 
@@ -1,64 +1,116 @@
1
1
  # encoding: utf-8
2
2
  require_relative "../spec_helper"
3
+ require "logstash/devutils/rspec/shared_examples"
4
+ require 'logstash/plugin_mixins/ecs_compatibility_support/spec_helper'
3
5
  require "stud/temporary"
4
6
  require "tempfile"
5
7
 
6
8
  describe LogStash::Inputs::Unix do
7
9
 
8
- let(:tempfile) { Tempfile.new("/tmp/foo") }
10
+ let(:config) { { 'path' => tempfile.path, 'socket_not_present_retry_interval_seconds' => 1, 'force_unlink' => true } }
11
+ let(:tempfile) { Tempfile.new("unix-input-test") }
12
+
13
+ subject(:input) { described_class.new(config) }
9
14
 
10
15
  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
16
+ expect { subject.register }.to_not raise_error
13
17
  end
14
18
 
15
19
  describe "when mode is client" do
16
20
 
17
- let(:mode) { "client" }
21
+ let(:config) { super().merge("mode" => 'client', "socket_not_present_retry_interval_seconds" => -1) }
18
22
 
19
23
  context "if socket_not_present_retry_interval_seconds is out of bounds" do
20
24
  it "should fallback to default value" do
21
- plugin = LogStash::Plugin.lookup("input", "unix").new({ "path" => tempfile.path, "force_unlink" => true, "mode" => mode, "socket_not_present_retry_interval_seconds" => -1 })
22
- plugin.register
23
- expect(plugin.instance_variable_get(:@socket_not_present_retry_interval_seconds)).to be 5
25
+ subject.register
26
+ expect( subject.socket_not_present_retry_interval_seconds ).to eql 5
24
27
  end
25
28
  end
26
29
  end
27
30
 
28
- describe "when interrupting the plugin" do
31
+ context "#server" do
32
+ it_behaves_like "an interruptible input plugin" do
33
+ let(:config) { super().merge "mode" => 'server' }
34
+ end
35
+ end
36
+
37
+ context "#client", :ecs_compatibility_support do
38
+ let(:temp_path) { "/tmp/sock#{rand(65532)}" }
39
+ let(:config) { super().merge "path" => temp_path, "mode" => "client" }
40
+ let(:unix_socket) { UnixSocketHelper.new('foo').new_socket(temp_path) }
41
+ let(:run_forever) { true }
42
+
43
+ before(:each) do
44
+ unix_socket.loop(run_forever)
45
+ end
46
+
47
+ after(:each) do
48
+ unix_socket.close
49
+ end
29
50
 
30
- context "#server" do
51
+ context "when the unix socket has data to be read" do
31
52
  it_behaves_like "an interruptible input plugin" do
32
- let(:config) { { "path" => tempfile.path, "force_unlink" => true } }
53
+ let(:run_forever) { true }
33
54
  end
34
55
  end
35
56
 
36
- context "#client" do
37
- let(:tempfile) { "/tmp/sock#{rand(65532)}" }
38
- let(:config) { { "path" => tempfile, "mode" => "client" } }
39
- let(:unix_socket) { UnixSocketHelper.new.new_socket(tempfile) }
40
- let(:run_forever) { true }
57
+ context "when the unix socket has no data to be read" do
41
58
 
42
- before(:each) do
43
- unix_socket.loop(run_forever)
44
- end
59
+ let(:run_forever) { false }
45
60
 
46
- after(:each) do
47
- unix_socket.close
48
- end
61
+ it_behaves_like "an interruptible input plugin"
62
+
63
+ context 'with timeout' do
64
+
65
+ let(:config) { super().merge "data_timeout" => 1.0 }
49
66
 
50
- context "when the unix socket has data to be read" do
51
- it_behaves_like "an interruptible input plugin" do
52
- let(:run_forever) { true }
67
+ let(:queue) { SizedQueue.new(10) }
68
+ before(:each) { subject.register }
69
+ after(:each) { subject.do_stop }
70
+
71
+ it "closes socket after timeout" do
72
+ plugin_thread = Thread.new(subject, queue) { |subject, queue| subject.run(queue) }
73
+ sleep 0.5
74
+ client_socket = subject.instance_variable_get :@client_socket
75
+ expect( client_socket.closed? ).to be false
76
+ sleep 1.0 # allow timeout to kick in
77
+ expect( client_socket.closed? ).to be true
78
+ expect( plugin_thread ).to be_alive
53
79
  end
80
+
54
81
  end
82
+ end
83
+
84
+ ecs_compatibility_matrix(:disabled, :v1, :v8) do |ecs_select|
85
+
86
+ let(:config) { super().merge 'ecs_compatibility' => ecs_compatibility }
87
+
88
+ let(:queue) { java.util.Vector.new }
55
89
 
56
- context "when the unix socket has no data to be read" do
57
- it_behaves_like "an interruptible input plugin" do
58
- let(:run_forever) { false }
90
+ it 'generates events with host, path and message set' do
91
+ subject.register
92
+ Thread.new(subject, queue) { |subject, queue| subject.run(queue) }
93
+ try(10) do
94
+ expect( queue.size ).to_not eql 0
59
95
  end
96
+ subject.do_stop # stop the plugin
97
+
98
+ event = queue.first
99
+
100
+ if ecs_select.active_mode == :disabled
101
+ expect( event.get('host') ).to be_a String
102
+ expect( event.get('path') ).to eql temp_path
103
+ else
104
+ expect( event.get('[host][name]') ).to be_a String
105
+ expect( event.get('[file][path]') ).to eql temp_path
106
+ expect( event.include?('path') ).to be false
107
+ end
108
+
109
+ expect( event.get('message') ).to eql 'foo'
60
110
  end
111
+
61
112
  end
62
113
 
63
114
  end
115
+
64
116
  end
data/spec/spec_helper.rb CHANGED
@@ -6,12 +6,13 @@ class UnixSocketHelper
6
6
 
7
7
  attr_reader :path
8
8
 
9
- def initialize
9
+ def initialize(line = 'hi!')
10
10
  @socket = nil
11
+ @line = line
11
12
  end
12
13
 
13
14
  def new_socket(path)
14
- @path = path
15
+ @path = path
15
16
  File.unlink if File.exists?(path) && File.socket?(path)
16
17
  @socket = UNIXServer.new(path)
17
18
  self
@@ -21,16 +22,15 @@ class UnixSocketHelper
21
22
  @thread = Thread.new do
22
23
  begin
23
24
  s = @socket.accept
24
- s.puts "hi" while forever
25
- rescue Errno::EPIPE, Errno::ECONNRESET
26
- # ...
25
+ s.puts @line while forever
26
+ rescue Errno::EPIPE, Errno::ECONNRESET => e
27
+ warn e.inspect if $VERBOSE
27
28
  end
28
29
  end
29
30
  self
30
31
  end
31
32
 
32
33
  def close
33
- @thread.kill
34
34
  @socket.close
35
35
  File.unlink(path)
36
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-unix
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-16 00:00:00.000000000 Z
11
+ date: 2021-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "<="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '1.3'
39
+ name: logstash-mixin-ecs_compatibility_support
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
33
47
  - !ruby/object:Gem::Dependency
34
48
  requirement: !ruby/object:Gem::Requirement
35
49
  requirements:
@@ -58,7 +72,9 @@ dependencies:
58
72
  - - ">="
59
73
  - !ruby/object:Gem::Version
60
74
  version: '0'
61
- 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
75
+ description: This gem is a Logstash plugin required to be installed on top of the
76
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
77
+ gem is not a stand-alone program
62
78
  email: info@elastic.co
63
79
  executables: []
64
80
  extensions: []
@@ -96,11 +112,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
112
  - !ruby/object:Gem::Version
97
113
  version: '0'
98
114
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.4.8
115
+ rubygems_version: 3.1.6
101
116
  signing_key:
102
117
  specification_version: 4
103
- summary: Read events over a UNIX socket.
118
+ summary: Reads events over a UNIX socket
104
119
  test_files:
105
120
  - spec/inputs/unix_spec.rb
106
121
  - spec/spec_helper.rb