logstash-input-exec 3.3.3 → 3.4.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: 6572d99615f87ace8db0908a038f652de0e5c97c5bf0792f2f195ed6191243e5
4
- data.tar.gz: c716f2124922141458bb4ace432389adbdf45dd9fe18a1eddec3aa29b9960b3e
3
+ metadata.gz: 9c34902b8be4e548af7df0fa8a539ca5c795e9faeff9d4dccaa9d357e080c424
4
+ data.tar.gz: d4d9f5e6aa8d1afd53e7d6fcb37f5e84277c3ea0038a44d0ec27577497447f8f
5
5
  SHA512:
6
- metadata.gz: 7d940aee8ca85ceee0baba1feda840ceb8f0cf1bf17977393692f3ba4ad8c2b1523a82e4b3bea5df0d17ad7b402c1e7b0f6d10741d7b4c459bcc869bc2c57090
7
- data.tar.gz: 27ce9c58c67b1bdd8093851bbe9d0b20852fcff2ec5fe4c05dbd358cc296400e5e6abcca9a021594931cf342b3ea72805e3d8d42f38b63ce5c0d8d978e105979
6
+ metadata.gz: 7ff940ad3f3a22894d5242d1ee3b5238e805af2e629c1aa7a93f1f7d5986cf70140c519c859abb2776101550b80b80c40c0669a60e9e0b6b1a2aa21ad8d19865
7
+ data.tar.gz: 18f68b20afd72dde8384d8c5d39a468436666d3a43014425a1f17ffa6d42bdcd23e27dce2721f0f97ded83159375a2e9aec2d11de95b88fbc74475cd4107eeef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.4.0
2
+ - Feat: adjust fields for ECS compatibility [#28](https://github.com/logstash-plugins/logstash-input-exec/pull/28)
3
+ - Plugin will no longer override fields if they exist in the decoded payload.
4
+ (It no longer sets the `host` field if decoded from the command's output.)
5
+
1
6
  ## 3.3.3
2
7
  - Docs: improved doc on memory usage [#27](https://github.com/logstash-plugins/logstash-input-exec/pull/27)
3
8
 
data/LICENSE CHANGED
@@ -1,13 +1,202 @@
1
- Copyright (c) 2012-2018 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-exec.svg)](https://travis-ci.org/logstash-plugins/logstash-input-exec)
3
+ [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-input-exec.svg)](https://travis-ci.com/logstash-plugins/logstash-input-exec)
4
4
 
5
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
6
 
data/docs/index.asciidoc CHANGED
@@ -23,14 +23,13 @@ include::{include_path}/plugin_header.asciidoc[]
23
23
 
24
24
  Periodically run a shell command and capture the whole output as an event.
25
25
 
26
- Notes:
27
-
26
+ [NOTE]
27
+ ========
28
28
  * The `command` field of this event will be the command run.
29
29
  * The `message` field of this event will be the entire stdout of the command.
30
+ ========
30
31
 
31
- ===== IMPORTANT
32
-
33
- The exec input ultimately uses `fork` to spawn a child process.
32
+ IMPORTANT: The exec input ultimately uses `fork` to spawn a child process.
34
33
  Using fork duplicates the parent process address space (in our case, **logstash and the JVM**); this is mitigated with OS copy-on-write but ultimately you can end up allocating lots of memory just for a "simple" executable.
35
34
  If the exec input fails with errors like `ENOMEM: Cannot allocate memory` it is an indication that there is not enough non-JVM-heap physical memory to perform the fork.
36
35
 
@@ -41,17 +40,36 @@ Example:
41
40
  ----------------------------------
42
41
  input {
43
42
  exec {
44
- command => "ls"
43
+ command => "echo 'hi!'"
45
44
  interval => 30
46
45
  }
47
46
  }
48
47
  ----------------------------------
49
48
 
50
- This will execute `ls` command every 30 seconds.
49
+ This will execute `echo` command every 30 seconds.
50
+
51
+ [id="plugins-{type}s-{plugin}-ecs"]
52
+ ==== Compatibility with the Elastic Common Schema (ECS)
53
+
54
+ This plugin adds metadata about the event's source, and can be configured to do so
55
+ in an {ecs-ref}[ECS-compatible] way with <<plugins-{type}s-{plugin}-ecs_compatibility>>.
56
+ This metadata is added after the event has been decoded by the appropriate codec,
57
+ and will not overwrite existing values.
58
+
59
+ |========
60
+ | ECS Disabled | ECS v1 , v8 | Description
61
+
62
+ | `host` | `[host][name]` | The name of the {ls} host that processed the event
63
+ | `command` | `[process][command_line]` | The command run by the plugin
64
+ | `[@metadata][exit_status]` | `[process][exit_code]` | The exit code of the process
65
+ | -- | `[@metadata][input][exec][process][elapsed_time]`
66
+ | The elapsed time the command took to run in nanoseconds
67
+ | `[@metadata][duration]` | -- | Command duration in seconds as a floating point number (deprecated)
68
+ |========
51
69
 
52
70
 
53
71
  [id="plugins-{type}s-{plugin}-options"]
54
- ==== Exec Input Configuration Options
72
+ ==== Exec Input configuration options
55
73
 
56
74
  This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
57
75
 
@@ -59,6 +77,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
59
77
  |=======================================================================
60
78
  |Setting |Input type|Required
61
79
  | <<plugins-{type}s-{plugin}-command>> |<<string,string>>|Yes
80
+ | <<plugins-{type}s-{plugin}-ecs_compatibility>> |<<string,string>>|No
62
81
  | <<plugins-{type}s-{plugin}-interval>> |<<number,number>>|No
63
82
  | <<plugins-{type}s-{plugin}-schedule>> |<<string,string>>|No
64
83
  |=======================================================================
@@ -77,6 +96,58 @@ input plugins.
77
96
 
78
97
  Command to run. For example, `uptime`
79
98
 
99
+ [id="plugins-{type}s-{plugin}-ecs_compatibility"]
100
+ ===== `ecs_compatibility`
101
+
102
+ * Value type is <<string,string>>
103
+ * Supported values are:
104
+ ** `disabled`: uses backwards compatible field names, such as `[host]`
105
+ ** `v1`, `v8`: uses fields that are compatible with ECS, such as `[host][name]`
106
+
107
+ Controls this plugin's compatibility with the {ecs-ref}[Elastic Common Schema (ECS)].
108
+ See <<plugins-{type}s-{plugin}-ecs>> for detailed information.
109
+
110
+
111
+ **Sample output: ECS enabled**
112
+ [source,ruby]
113
+ -----
114
+ {
115
+ "message" => "hi!\n",
116
+ "process" => {
117
+ "command_line" => "echo 'hi!'",
118
+ "exit_code" => 0
119
+ },
120
+ "host" => {
121
+ "name" => "deus-ex-machina"
122
+ },
123
+
124
+ "@metadata" => {
125
+ "input" => {
126
+ "exec" => {
127
+ "process" => {
128
+ "elapsed_time"=>3042
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+ -----
135
+
136
+ **Sample output: ECS disabled**
137
+ [source,ruby]
138
+ -----
139
+ {
140
+ "message" => "hi!\n",
141
+ "command" => "echo 'hi!'",
142
+ "host" => "deus-ex-machina",
143
+
144
+ "@metadata" => {
145
+ "exit_status" => 0,
146
+ "duration" => 0.004388
147
+ }
148
+ }
149
+ -----
150
+
80
151
  [id="plugins-{type}s-{plugin}-interval"]
81
152
  ===== `interval`
82
153
 
@@ -5,6 +5,8 @@ require "socket" # for Socket.gethostname
5
5
  require "stud/interval"
6
6
  require "rufus/scheduler"
7
7
 
8
+ require 'logstash/plugin_mixins/ecs_compatibility_support'
9
+
8
10
  # Periodically run a shell command and capture the whole output as an event.
9
11
  #
10
12
  # Notes:
@@ -14,6 +16,8 @@ require "rufus/scheduler"
14
16
  #
15
17
  class LogStash::Inputs::Exec < LogStash::Inputs::Base
16
18
 
19
+ include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1, :v8 => :v1)
20
+
17
21
  config_name "exec"
18
22
 
19
23
  default :codec, "plain"
@@ -31,13 +35,20 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
31
35
  config :schedule, :validate => :string
32
36
 
33
37
  def register
34
- @logger.info("Registering Exec Input", :type => @type, :command => @command, :interval => @interval, :schedule => @schedule)
35
- @hostname = Socket.gethostname
38
+ @hostname = Socket.gethostname.freeze
36
39
  @io = nil
37
40
 
38
41
  if (@interval.nil? && @schedule.nil?) || (@interval && @schedule)
39
42
  raise LogStash::ConfigurationError, "exec input: either 'interval' or 'schedule' option must be defined."
40
43
  end
44
+
45
+ @host_name_field = ecs_select[disabled: 'host', v1: '[host][name]']
46
+ @process_command_line_field = ecs_select[disabled: 'command', v1: '[process][command_line]']
47
+ @process_exit_code_field = ecs_select[disabled: '[@metadata][exit_status]', v1: '[process][exit_code]']
48
+
49
+ # migrate elapsed time tracking to whole nanos, from legacy floating-point fractional seconds
50
+ @process_elapsed_time_field = ecs_select[disabled: nil, v1: '[@metadata][input][exec][process][elapsed_time]'] # in nanos
51
+ @legacy_duration_field = ecs_select[disabled: '[@metadata][duration]', v1: nil] # in seconds
41
52
  end # def register
42
53
 
43
54
  def run(queue)
@@ -61,8 +72,7 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
61
72
  end
62
73
 
63
74
  # Execute a given command
64
- # @param [String] A command string
65
- # @param [Array or Queue] A queue to append events to
75
+ # @param queue the LS queue to append events to
66
76
  def execute(queue)
67
77
  start = Time.now
68
78
  output = exit_status = nil
@@ -71,20 +81,21 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
71
81
  output, exit_status = run_command()
72
82
  rescue StandardError => e
73
83
  @logger.error("Error while running command",
74
- :command => @command, :e => e, :backtrace => e.backtrace)
84
+ :command => @command, :exception => e, :backtrace => e.backtrace)
75
85
  rescue Exception => e
76
86
  @logger.error("Exception while running command",
77
- :command => @command, :e => e, :backtrace => e.backtrace)
87
+ :command => @command, :exception => e, :backtrace => e.backtrace)
78
88
  end
79
- duration = Time.now - start
80
- @logger.debug? && @logger.debug("Command completed", :command => @command, :duration => duration)
89
+ duration = Time.now.to_r - start.to_r
90
+ @logger.debug? && @logger.debug("Command completed", :command => @command, :duration => duration.to_f)
81
91
  if output
82
92
  @codec.decode(output) do |event|
83
93
  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)
94
+ event.set(@host_name_field, @hostname) unless event.include?(@host_name_field)
95
+ event.set(@process_command_line_field, @command) unless event.include?(@process_command_line_field)
96
+ event.set(@process_exit_code_field, exit_status) unless event.include?(@process_exit_code_field)
97
+ event.set(@process_elapsed_time_field, to_nanos(duration)) if @process_elapsed_time_field
98
+ event.set(@legacy_duration_field, duration.to_f) if @legacy_duration_field
88
99
  queue << event
89
100
  end
90
101
  end
@@ -97,7 +108,7 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
97
108
  @io = IO.popen(@command)
98
109
  output = @io.read
99
110
  @io.close # required in order to read $?
100
- exit_status = $?.exitstatus # should be threadsafe as per rb_thread_save_context
111
+ exit_status = $?.exitstatus
101
112
  [output, exit_status]
102
113
  ensure
103
114
  close_io()
@@ -111,7 +122,7 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
111
122
  end
112
123
 
113
124
  # Wait until the end of the interval
114
- # @param [Integer] the duration of the last command executed
125
+ # @param duration [Integer] the duration of the last command executed
115
126
  def wait_until_end_of_interval(duration)
116
127
  # Sleep for the remainder of the interval, or 0 if the duration ran
117
128
  # longer than the interval.
@@ -124,5 +135,10 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
124
135
  end
125
136
  end
126
137
 
138
+ # convert seconds to nanoseconds
139
+ # @param time_diff [Numeric] the (rational value) difference to convert
140
+ def to_nanos(time_diff)
141
+ (time_diff * 1_000_000).to_i
142
+ end
127
143
 
128
144
  end # class LogStash::Inputs::Exec
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-exec'
4
- s.version = '3.3.3'
4
+ s.version = '3.4.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"
@@ -21,6 +21,8 @@ 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
+ s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~> 1.3'
25
+
24
26
  s.add_runtime_dependency 'stud', '~> 0.0.22'
25
27
  s.add_runtime_dependency 'logstash-codec-plain'
26
28
  s.add_runtime_dependency 'rufus-scheduler'
@@ -2,75 +2,104 @@
2
2
  require "timecop"
3
3
  require "time"
4
4
  require_relative "../spec_helper"
5
+ require "logstash/devutils/rspec/shared_examples"
6
+ require 'logstash/plugin_mixins/ecs_compatibility_support/spec_helper'
5
7
 
6
- describe LogStash::Inputs::Exec do
8
+ describe LogStash::Inputs::Exec, :ecs_compatibility_support do
7
9
 
8
- context "when register" do
9
- let(:input) { described_class.new("command" => "ls", "interval" => 0) }
10
- it "should not raise error if config is valid" do
11
- # register will try to load jars and raise if it cannot find jars or if org.apache.log4j.spi.LoggingEvent class is not present
12
- expect {input.register}.to_not raise_error
10
+ ecs_compatibility_matrix(:disabled, :v1, :v8) do |ecs_select|
11
+
12
+ before(:each) do
13
+ allow_any_instance_of(described_class).to receive(:ecs_compatibility).and_return(ecs_compatibility)
13
14
  end
14
- context "with an invalid config" do
15
- let(:input) { described_class.new("command" => "ls") }
16
- it "should raise error" do
17
- expect {input.register}.to raise_error(LogStash::ConfigurationError)
15
+
16
+ context "when register" do
17
+ let(:input) { described_class.new("command" => "ls", "interval" => 0) }
18
+
19
+ it "should not raise error if config is valid" do
20
+ # register will try to load jars and raise if it cannot find jars or if org.apache.log4j.spi.LoggingEvent class is not present
21
+ expect { input.register }.to_not raise_error
18
22
  end
19
- end
20
- end
21
23
 
22
- context "when operating normally" do
23
- let(:input) { described_class.new("command" => "ls", "interval" => 0) }
24
- let(:queue) { [] }
25
- let(:loggr) { double('loggr') }
26
-
27
- before :each do
28
- expect(described_class).to receive(:logger).and_return(loggr).exactly(7).times
29
- allow(loggr).to receive(:info)
30
- allow(loggr).to receive(:info?)
31
- allow(loggr).to receive(:warn)
32
- allow(loggr).to receive(:warn?)
33
- allow(loggr).to receive(:debug)
34
- allow(loggr).to receive(:debug?)
24
+ context "with an invalid config" do
25
+ let(:input) { described_class.new("command" => "ls") }
26
+ it "should raise error" do
27
+ expect { input.register }.to raise_error(LogStash::ConfigurationError)
28
+ end
29
+ end
35
30
  end
36
31
 
37
- it "enqueues some events" do
38
- input.register
39
- expect(loggr).not_to receive(:error)
32
+ context "when operating normally" do
33
+ let(:input) { described_class.new("command" => "echo 'hi!'", "interval" => 0) }
34
+ let(:queue) { [] }
40
35
 
41
- input.execute(queue)
36
+ before :each do
37
+ input.register
38
+ end
42
39
 
43
- expect(queue.size).not_to be_zero
44
- end
45
- end
40
+ it "enqueues some events" do
41
+ expect(input.logger).not_to receive(:error)
46
42
 
47
- context "when a command runs normally" do
48
- let(:input) { described_class.new("command" => "/bin/sh -c 'sleep 1; /bin/echo -n two; exit 3'", "interval" => 0) }
49
- let(:queue) { [] }
43
+ input.execute(queue)
50
44
 
51
- before do
52
- input.register
53
- input.execute(queue)
45
+ expect(queue.size).not_to be_zero
46
+ end
54
47
  end
55
48
 
56
- after do
57
- input.stop
58
- end
49
+ context "when a command runs normally" do
50
+ let(:command) { "/bin/sh -c 'sleep 1; /bin/echo -n two; exit 3'" }
51
+ let(:input) { described_class.new("command" => command, "interval" => 0) }
52
+ let(:queue) { [] }
53
+
54
+ before do
55
+ input.register
56
+ input.execute(queue)
57
+ end
58
+
59
+ after do
60
+ input.stop
61
+ end
62
+
63
+ it "has duration (in seconds)" do
64
+ duration = queue.pop.get('[@metadata][duration]')
65
+ expect(duration).to be_a Float
66
+ expect(duration).to be > 1
67
+ expect(duration).to be < 3
68
+ end if ecs_select.active_mode == :disabled
69
+
70
+ it "reports process elapsed time (in nanos)" do
71
+ elapsed_time = queue.pop.get('[@metadata][input][exec][process][elapsed_time]')
72
+ expect(elapsed_time).to be_a Integer
73
+ expect(elapsed_time).to be > 1 * 1_000_000
74
+ expect(elapsed_time).to be < 3 * 1_000_000
75
+ end if ecs_select.active_mode != :disabled
76
+
77
+ it "has output as expected" do
78
+ expect(queue.pop.get('message')).to eq "two"
79
+ end
80
+
81
+ it "reports process command_line " do
82
+ if ecs_select.active_mode == :disabled
83
+ expect(queue.pop.get('command')).to eql command
84
+ else
85
+ expect(queue.pop.get('[process][command_line]')).to eql command
86
+ end
87
+ end
88
+
89
+ it "reports process exit_code" do
90
+ if ecs_select.active_mode == :disabled
91
+ expect(queue.pop.get('[@metadata][exit_status]')).to eq 3
92
+ else
93
+ expect(queue.pop.get('[process][exit_code]')).to eq 3
94
+ end
95
+ end
59
96
 
60
- it "has duration tracked" do
61
- expect(queue.pop.get('[@metadata][duration]')).to be > 1
62
- end
63
- it "has output as expected" do
64
- expect(queue.pop.get('message')).to eq "two"
65
- end
66
- it "has exit_status tracked" do
67
- expect(queue.pop.get('[@metadata][exit_status]')).to eq 3
68
97
  end
69
98
 
70
99
  end
71
100
 
72
101
  context "when scheduling" do
73
- let(:input) { described_class.new("command" => "ls", "schedule" => "* * * * * UTC") }
102
+ let(:input) { described_class.new("command" => "ls --help", "schedule" => "* * * * * UTC") }
74
103
  let(:queue) { [] }
75
104
 
76
105
  before 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.3.3
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-10 00:00:00.000000000 Z
11
+ date: 2021-11-16 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:
@@ -140,8 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
154
  - !ruby/object:Gem::Version
141
155
  version: '0'
142
156
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.6.13
157
+ rubygems_version: 3.1.6
145
158
  signing_key:
146
159
  specification_version: 4
147
160
  summary: Captures the output of a shell command as an event