logstash-output-pipe 3.0.7 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a835830fb6d2646383cb63699d04c6d55b38c0e142bbd740e54068ab32e3eaaa
4
- data.tar.gz: 6f85588e9cccf73b68152421dc91f8ac7b32a0c53ed40aab8edee3b5d81e5927
3
+ metadata.gz: 30187b18ca17f42c0c76b8da5d75bbc5dc33885f5bbd57a49c79abad8af05f6f
4
+ data.tar.gz: a60dbcb7fd743dcb04ce16742e3a2212ec33f5a26e31869ced82bc42bc717164
5
5
  SHA512:
6
- metadata.gz: 56b9b747a7aa8ae872012110b6ace759170209aa1f6dba92d2c05f153e7d192303b83a942bc0a0958ba77be29a2bbe38f93ced6de60653220611e58d2d10e93b
7
- data.tar.gz: 8f7567edb2a8274fe625044fcc319caf027ce36dea5a9bfc364b5f1612984cab11bbd21c148f4e8844def61592f9a54732d5b3025bd6fefeb8116690654edf39
6
+ metadata.gz: 3317c089fff1821a0a86df0ec0d3e3c6ba5eeb97341e416c185e38fb821374719f8bdb9d4de49fee7a9fa69f9f7dc0fc61729033a0e0b8bcec1421849517985a
7
+ data.tar.gz: 1086fd66ff7c7fe07a1634eda83c73fdf331e8a447e75af36c3cf9a5eb2ccb006383c5a64a42fd0aa10bf4fe86c75406e09817f6c20278012f20d411ce618d10
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 4.0.0
2
+ - [BREAKING] `command` accept array form and no longer invokes a shell [#5](https://github.com/logstash-plugins/logstash-output-pipe/pull/5)
3
+ - Existing string commands with whitespace should be converted to array form
4
+
1
5
  ## 3.0.7
2
6
  - [DOC] Document `command` string form limitation [#6](https://github.com/logstash-plugins/logstash-output-pipe/pull/6)
3
7
 
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 4.0.0
data/docs/index.asciidoc CHANGED
@@ -35,7 +35,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
35
35
  [cols="<,<,<",options="header",]
36
36
  |=======================================================================
37
37
  |Setting |Input type|Required
38
- | <<plugins-{type}s-{plugin}-command>> |<<string,string>>|Yes
38
+ | <<plugins-{type}s-{plugin}-command>> |<<array,array>>|Yes
39
39
  | <<plugins-{type}s-{plugin}-message_format>> |<<string,string>>|No
40
40
  | <<plugins-{type}s-{plugin}-ttl>> |<<number,number>>|No
41
41
  |=======================================================================
@@ -46,21 +46,27 @@ output plugins.
46
46
  &nbsp;
47
47
 
48
48
  [id="plugins-{type}s-{plugin}-command"]
49
- ===== `command`
49
+ ===== `command`
50
50
 
51
51
  * This is a required setting.
52
- * Value type is <<string,string>>
52
+ * Value type is <<array,array>>
53
53
  * There is no default value for this setting.
54
54
 
55
- Command line to launch and pipe to
55
+ Command line to launch and pipe to.
56
+
57
+ Example:
58
+
59
+ [source,ruby]
60
+ ----
61
+ output {
62
+ pipe {
63
+ command => ["tee", "-a", "/tmp/logstash-%{host}.log"]
64
+ }
65
+ }
66
+ ----
56
67
 
57
- NOTE: `command` is passed to `/bin/sh`, so any metacharacters
58
- (`;`, `|`, `>`, `&`, etc.) in field substitutions will be interpreted by the shell.
59
- If `command` contains such character(s), it is recommended
60
- to upgrade to plugin version 4.0.0 or later, which accepts `command`
61
- as an array and invokes the program directly bypassing shell interpretation.
62
68
  [id="plugins-{type}s-{plugin}-message_format"]
63
- ===== `message_format`
69
+ ===== `message_format`
64
70
 
65
71
  * Value type is <<string,string>>
66
72
  * There is no default value for this setting.
@@ -73,7 +79,7 @@ If this setting is omitted, the full json representation of the
73
79
  event will be written as a single line.
74
80
 
75
81
  [id="plugins-{type}s-{plugin}-ttl"]
76
- ===== `ttl`
82
+ ===== `ttl`
77
83
 
78
84
  * Value type is <<number,number>>
79
85
  * Default value is `10`
@@ -85,4 +91,4 @@ Close pipe that hasn't been used for TTL seconds. -1 or 0 means never close.
85
91
  [id="plugins-{type}s-{plugin}-common-options"]
86
92
  include::{include_path}/{type}.asciidoc[]
87
93
 
88
- :default_codec!:
94
+ :default_codec!:
@@ -20,21 +20,23 @@ class LogStash::Outputs::Pipe < LogStash::Outputs::Base
20
20
  config :message_format, :validate => :string
21
21
 
22
22
  # Command line to launch and pipe to
23
- config :command, :validate => :string, :required => true
23
+ config :command, :validate => :array, :required => true
24
24
 
25
25
  # Close pipe that hasn't been used for TTL seconds. -1 or 0 means never close.
26
26
  config :ttl, :validate => :number, :default => 10
27
27
  public
28
28
  def register
29
+ if @command.empty?
30
+ raise LogStash::ConfigurationError, "The 'command' setting must not be empty"
31
+ end
32
+
29
33
  @pipes = {}
30
34
  @last_stale_cleanup_cycle = Time.now
31
35
  end # def register
32
36
 
33
37
  public
34
38
  def receive(event)
35
-
36
-
37
- command = event.sprintf(@command)
39
+ command = @command.map { |part| event.sprintf(part) }
38
40
 
39
41
  if @message_format
40
42
  output = event.sprintf(@message_format) + "\n"
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-pipe'
4
- s.version = ::File.read('version').split("\n").first
4
+ s.version = ::File.read('VERSION').split("\n").first
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Pipes events to another program's standard input"
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"
@@ -32,4 +32,55 @@ describe LogStash::Outputs::Pipe do
32
32
  end
33
33
 
34
34
  end
35
+
36
+ describe "command resolution" do
37
+ let(:pipe) { double("pipe") }
38
+ let(:payload) { "test_message; id > /tmp/INJECTED; #" }
39
+
40
+ before(:each) do
41
+ allow(PipeWrapper).to receive(:new).and_return(pipe)
42
+ allow(pipe).to receive(:puts)
43
+ subject.register
44
+ end
45
+
46
+ shared_examples "resolves command" do
47
+ it "passes the resolved command to PipeWrapper" do
48
+ expect(PipeWrapper).to receive(:new).with(expected_command, anything).and_return(pipe)
49
+ subject.receive(event)
50
+ end
51
+ end
52
+
53
+ context "string command coerced to array" do
54
+ subject { LogStash::Outputs::Pipe.new("command" => "logger -t audit %{message}") }
55
+ let(:event) { LogStash::Event.new("message" => payload) }
56
+ let(:expected_command) { ["logger -t audit #{payload}"] }
57
+
58
+ include_examples "resolves command"
59
+ end
60
+
61
+ context "array command" do
62
+ context "each element resolved independently" do
63
+ subject { LogStash::Outputs::Pipe.new("command" => ["logger", "-t", "%{tag}", "--", "%{message}"]) }
64
+ let(:event) { LogStash::Event.new("tag" => "audit", "message" => "hello") }
65
+ let(:expected_command) { ["logger", "-t", "audit", "--", "hello"] }
66
+
67
+ include_examples "resolves command"
68
+ end
69
+
70
+ context "single-element array" do
71
+ subject { LogStash::Outputs::Pipe.new("command" => ["logger -t audit %{message}"]) }
72
+ let(:event) { LogStash::Event.new("message" => payload) }
73
+ let(:expected_command) { ["logger -t audit #{payload}"] }
74
+
75
+ include_examples "resolves command"
76
+ end
77
+ end
78
+ end
79
+
80
+ describe "validation" do
81
+ it "raises ConfigurationError when command is an empty array" do
82
+ plugin = LogStash::Outputs::Pipe.new("command" => [])
83
+ expect { plugin.register }.to raise_error(LogStash::ConfigurationError)
84
+ end
85
+ end
35
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-pipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.7
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
@@ -71,6 +71,7 @@ files:
71
71
  - LICENSE
72
72
  - NOTICE.TXT
73
73
  - README.md
74
+ - VERSION
74
75
  - docs/index.asciidoc
75
76
  - lib/logstash/outputs/pipe.rb
76
77
  - logstash-output-pipe.gemspec