logstash-output-exec 2.0.4 → 2.0.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: 1f7b33fee44ee6c1ab390d0ce6c187ba1a21da76
4
- data.tar.gz: 87e2adfacfc6c4efe76cebe0ea3c2468a018f95d
3
+ metadata.gz: 4fa722dbb26dda585a5bad9fb5c8730c1003351e
4
+ data.tar.gz: cc16d47ab25586b1ea7372e02045043c69d02731
5
5
  SHA512:
6
- metadata.gz: 452d1f513e7d9bb9fc5570d34a332eff130ce1b0ff8ec25a6fd7593a27c6e985898bb9956fef5d21bb247be9888d89aa626bac9bf6ebf1c48008907073325ca4
7
- data.tar.gz: ad6e9e5ac6d896b55b45eb3a7b8588671442b16a444f9f4c9476e638ac17c7be95545621c75ecbeec571a363fe0b64ca76d9275aad2a81baf6d755d13a592274
6
+ metadata.gz: 6b06b2ce9884f534baaa564f3e0ff13e5c1e4765d66ccd98627ee8844a66d8c86d90457e1ff7470faa2aa7b8bf2bc5ad10e6914910a09ac877cc5a204ab92ad6
7
+ data.tar.gz: 92aac26fab00849f14046955ee2ee02ce6403e324469e3b9609cda2d2acca81bfadb4d4f25fbf57921276567fe40eabb08aca98508b91c13be81cc04d8d57624
@@ -1,7 +1,15 @@
1
- # 2.0.4
1
+ ## 2.0.5
2
+ - Replace `Kernel.system` with `Open3.open3` and fixes `ThreadDeath` issues
3
+ - Will now log stdout and stderr of the command when running logstash in debug mode, the response is streamed to the log.
4
+ - Added a `quiet` option to not print the result of the command to stdout, this option is on by default for backward compatibility
5
+ - Added tests
6
+
7
+ ## 2.0.4
2
8
  - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
3
- # 2.0.3
9
+
10
+ ## 2.0.3
4
11
  - New dependency requirements for logstash-core for the 5.0 release
12
+
5
13
  ## 2.0.0
6
14
  - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
7
15
  instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
1
+ Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Logstash Plugin
2
2
 
3
- [![Build
4
- Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-exec-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-exec-unit/)
3
+ [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-output-exec.svg)](https://travis-ci.org/logstash-plugins/logstash-output-exec)
5
4
 
6
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
7
6
 
@@ -56,7 +55,12 @@ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
56
55
  ```
57
56
  - Install plugin
58
57
  ```sh
58
+ # Logstash 2.3 and higher
59
+ bin/logstash-plugin install --no-verify
60
+
61
+ # Prior to Logstash 2.3
59
62
  bin/plugin install --no-verify
63
+
60
64
  ```
61
65
  - Run Logstash with your plugin
62
66
  ```sh
@@ -74,7 +78,12 @@ gem build logstash-filter-awesome.gemspec
74
78
  ```
75
79
  - Install the plugin from the Logstash home
76
80
  ```sh
77
- bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
81
+ # Logstash 2.3 and higher
82
+ bin/logstash-plugin install --no-verify
83
+
84
+ # Prior to Logstash 2.3
85
+ bin/plugin install --no-verify
86
+
78
87
  ```
79
88
  - Start Logstash and proceed to test the plugin
80
89
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/namespace"
3
3
  require "logstash/outputs/base"
4
+ require "open3"
4
5
 
5
6
  # The exec output will run a command for each event received. Ruby's
6
7
  # `system()` function will be used, i.e. the command string will
@@ -34,16 +35,33 @@ class LogStash::Outputs::Exec < LogStash::Outputs::Base
34
35
  # dynamic strings.
35
36
  config :command, :validate => :string, :required => true
36
37
 
38
+ # display the result of the command to the terminal
39
+ config :quiet, :validate => :boolean, :default => false
40
+
37
41
  public
38
42
  def register
39
43
  @logger.debug("exec output registered", :config => @config)
40
- end # def register
44
+ end
41
45
 
42
46
  public
43
47
  def receive(event)
44
-
45
- @logger.debug("running exec command", :command => event.sprintf(@command))
46
- system(event.sprintf(@command))
47
- end # def receive
48
+ cmd = event.sprintf(@command)
49
+ @logger.debug("running exec command", :command => cmd)
50
+
51
+ Open3.popen3(cmd) do |stdin, stdout, stderr|
52
+ if @logger.debug?
53
+ @logger.pipe(stdout => :debug, stderr => :debug)
54
+ else
55
+ # This is for backward compatibility,
56
+ # the previous implementation was using `Kernel#system' and the default behavior
57
+ # of this method is to output the result to the terminal.
58
+ @logger.terminal(stdout.read.chomp) unless quiet?
59
+ end
60
+ end
61
+ end
48
62
 
63
+ private
64
+ def quiet?
65
+ @quiet
66
+ end
49
67
  end
@@ -1,10 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
-
3
2
  s.name = 'logstash-output-exec'
4
- s.version = '2.0.4'
3
+ s.version = '2.0.5'
5
4
  s.licenses = ['Apache License (2.0)']
6
5
  s.summary = "This output will run a command for any matching event."
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"
6
+ 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
7
  s.authors = ["Elastic"]
9
8
  s.email = 'info@elastic.co'
10
9
  s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
@@ -23,5 +22,6 @@ Gem::Specification.new do |s|
23
22
  s.add_runtime_dependency "logstash-core-plugin-api", "~> 1.0"
24
23
 
25
24
  s.add_development_dependency 'logstash-devutils'
25
+ s.add_development_dependency "logstash-codec-plain"
26
26
  end
27
27
 
@@ -1 +1,48 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/exec"
3
+ require "logstash/event"
1
4
  require "logstash/devutils/rspec/spec_helper"
5
+ require "tempfile"
6
+
7
+ describe LogStash::Outputs::Exec do
8
+ let(:event) { LogStash::Event.new({ "params" => "1234" }) }
9
+ let(:output) { "1" }
10
+ let(:command) { "echo #{output}" }
11
+
12
+ let(:config) do
13
+ { "command" => command }
14
+ end
15
+
16
+ let(:error_message) { "Oulala" }
17
+ let(:stderr) { Tempfile.new(error_message) }
18
+ let(:stdout) { Tempfile.new(output) }
19
+ let(:stdin) { Tempfile.new("") }
20
+
21
+ subject { described_class.new(config) }
22
+
23
+ it "receive a command and execute it" do
24
+ expect(Open3).to receive(:popen3).with(command)
25
+ subject.receive(event)
26
+ end
27
+
28
+ context "when debugging" do
29
+ before :each do
30
+ allow(subject.logger).to receive(:debug?).and_return(true)
31
+ expect(Open3).to receive(:popen3).with(command).and_yield(stdin, stdout, stderr)
32
+ end
33
+
34
+ it "register the stdout and stderr to the logger" do
35
+ expect(subject.logger).to receive(:pipe).with(stdout => :debug, stderr => :debug)
36
+ subject.receive(event)
37
+ end
38
+ end
39
+
40
+ context "When debugging is off" do
41
+ context "when quiet is off" do
42
+ it "write output to the terminal" do
43
+ expect(subject.logger).to receive(:terminal).with(output)
44
+ subject.receive(event)
45
+ end
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-exec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -38,7 +38,21 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- 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
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: logstash-codec-plain
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ 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
42
56
  email: info@elastic.co
43
57
  executables: []
44
58
  extensions: []