logstash-input-exec 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/exec.rb +57 -33
- data/logstash-input-exec.gemspec +4 -4
- data/spec/inputs/exec_spec.rb +25 -1
- data/spec/spec_helper.rb +3 -0
- metadata +29 -21
- 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: eec72b75adc610d7f82a3086724de2d114aef6a2
|
4
|
+
data.tar.gz: 8c3c01dcaa78bcf8f58984e33d94ed94810788d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 027c87842ed7a3959208afdb526a47fd094aebcea09b19579489dc049d7f1f6b9c61692d79436587f9efcd39b55bbdc23ee990477732277f090ad14f173b5e44
|
7
|
+
data.tar.gz: 265a6eecd2a5ab515ba66276e0c17d1ca1a4da7f9cf54a4c44181cbdb0608b79d0aee06e192fdf581dee61e7514c4ed9c3bd00327d0356bbcf80adef90b68611
|
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/exec.rb
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
require "logstash/inputs/base"
|
3
3
|
require "logstash/namespace"
|
4
4
|
require "socket" # for Socket.gethostname
|
5
|
+
require "stud/interval"
|
5
6
|
|
6
|
-
#
|
7
|
+
# Periodically run a shell command and capture the whole output as an event.
|
7
8
|
#
|
8
9
|
# Notes:
|
9
10
|
#
|
10
|
-
# * The
|
11
|
-
# * The
|
12
|
-
# as one event.
|
11
|
+
# * The `command` field of this event will be the command run.
|
12
|
+
# * The `message` field of this event will be the entire stdout of the command.
|
13
13
|
#
|
14
14
|
class LogStash::Inputs::Exec < LogStash::Inputs::Base
|
15
15
|
|
@@ -26,42 +26,66 @@ class LogStash::Inputs::Exec < LogStash::Inputs::Base
|
|
26
26
|
# Interval to run the command. Value is in seconds.
|
27
27
|
config :interval, :validate => :number, :required => true
|
28
28
|
|
29
|
-
public
|
30
29
|
def register
|
31
|
-
@logger.info("Registering Exec Input", :type => @type,
|
32
|
-
|
30
|
+
@logger.info("Registering Exec Input", :type => @type, :command => @command, :interval => @interval)
|
31
|
+
@hostname = Socket.gethostname
|
32
|
+
@io = nil
|
33
33
|
end # def register
|
34
34
|
|
35
|
-
public
|
36
35
|
def run(queue)
|
37
|
-
|
38
|
-
|
36
|
+
|
37
|
+
while !stop?
|
39
38
|
start = Time.now
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@
|
39
|
+
execute(@command)
|
40
|
+
duration = Time.now - start
|
41
|
+
|
42
|
+
@logger.info? && @logger.info("Command completed", :command => @command, :duration => duration)
|
43
|
+
|
44
|
+
wait_until_end_of_interval(duration)
|
45
|
+
end # loop
|
46
|
+
end # def run
|
47
|
+
|
48
|
+
def stop
|
49
|
+
if @io
|
50
|
+
@io.close
|
51
|
+
@io = nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# Wait until the end of the interval
|
58
|
+
# @param [Integer] the duration of the last command executed
|
59
|
+
def wait_until_end_of_interval(duration)
|
60
|
+
# Sleep for the remainder of the interval, or 0 if the duration ran
|
61
|
+
# longer than the interval.
|
62
|
+
sleeptime = [0, @interval - duration].max
|
63
|
+
if sleeptime == 0
|
64
|
+
@logger.warn("Execution ran longer than the interval. Skipping sleep.",
|
65
|
+
:command => @command, :duration => duration, :interval => @interval)
|
66
|
+
else
|
67
|
+
Stud.stoppable_sleep(sleeptime) { stop? }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Execute a given command
|
72
|
+
# @param [String] A command string
|
73
|
+
def execute(command)
|
74
|
+
@logger.info? && @logger.info("Running exec", :command => command)
|
75
|
+
begin
|
76
|
+
@io = IO.popen(command)
|
77
|
+
@codec.decode(@io.read) do |event|
|
44
78
|
decorate(event)
|
45
|
-
event["host"]
|
46
|
-
event["command"] =
|
79
|
+
event["host"] = @hostname
|
80
|
+
event["command"] = command
|
47
81
|
queue << event
|
48
82
|
end
|
49
|
-
|
83
|
+
rescue Exception => e
|
84
|
+
@logger.error("Exception while running command", :e => e, :backtrace => e.backtrace)
|
85
|
+
ensure
|
86
|
+
@io.close
|
87
|
+
@io = nil
|
88
|
+
end
|
89
|
+
end
|
50
90
|
|
51
|
-
duration = Time.now - start
|
52
|
-
@logger.info? && @logger.info("Command completed", :command => @command,
|
53
|
-
:duration => duration)
|
54
|
-
|
55
|
-
# Sleep for the remainder of the interval, or 0 if the duration ran
|
56
|
-
# longer than the interval.
|
57
|
-
sleeptime = [0, @interval - duration].max
|
58
|
-
if sleeptime == 0
|
59
|
-
@logger.warn("Execution ran longer than the interval. Skipping sleep.",
|
60
|
-
:command => @command, :duration => duration,
|
61
|
-
:interval => @interval)
|
62
|
-
else
|
63
|
-
sleep(sleeptime)
|
64
|
-
end
|
65
|
-
end # loop
|
66
|
-
end # def run
|
67
91
|
end # class LogStash::Inputs::Exec
|
data/logstash-input-exec.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-input-exec'
|
4
|
-
s.version = '
|
4
|
+
s.version = '2.0.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Run command line tools and capture the whole output 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/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,8 +20,8 @@ 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",
|
24
|
-
|
23
|
+
s.add_runtime_dependency "logstash-core", "~> 2.0.0.snapshot"
|
24
|
+
s.add_runtime_dependency 'stud', '~> 0.0.22'
|
25
25
|
s.add_runtime_dependency 'logstash-codec-plain'
|
26
26
|
|
27
27
|
s.add_development_dependency 'logstash-devutils'
|
data/spec/inputs/exec_spec.rb
CHANGED
@@ -1 +1,25 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative "../spec_helper"
|
3
|
+
|
4
|
+
describe LogStash::Inputs::Exec do
|
5
|
+
|
6
|
+
it "should register" do
|
7
|
+
input = LogStash::Plugin.lookup("input", "exec").new("command" => "uptime", "interval" => 0)
|
8
|
+
|
9
|
+
# register will try to load jars and raise if it cannot find jars or if org.apache.log4j.spi.LoggingEvent class is not present
|
10
|
+
expect {input.register}.to_not raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when interrupting the plugin" do
|
14
|
+
|
15
|
+
it_behaves_like "an interruptible input plugin" do
|
16
|
+
let(:config) { { "command" => "uptime", "interval" => 0 } }
|
17
|
+
end
|
18
|
+
|
19
|
+
it_behaves_like "an interruptible input plugin" do
|
20
|
+
let(:config) { { "command" => "uptime", "interval" => 100 } }
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,80 +1,87 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-exec
|
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
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ~>
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 2.0.0.snapshot
|
14
19
|
name: logstash-core
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
15
22
|
version_requirements: !ruby/object:Gem::Requirement
|
16
23
|
requirements:
|
17
|
-
- -
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.4.0
|
20
|
-
- - <
|
24
|
+
- - ~>
|
21
25
|
- !ruby/object:Gem::Version
|
22
|
-
version: 2.0.0
|
26
|
+
version: 2.0.0.snapshot
|
27
|
+
- !ruby/object:Gem::Dependency
|
23
28
|
requirement: !ruby/object:Gem::Requirement
|
24
29
|
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: 1.4.0
|
28
|
-
- - <
|
30
|
+
- - ~>
|
29
31
|
- !ruby/object:Gem::Version
|
30
|
-
version:
|
32
|
+
version: 0.0.22
|
33
|
+
name: stud
|
31
34
|
prerelease: false
|
32
35
|
type: :runtime
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: logstash-codec-plain
|
35
36
|
version_requirements: !ruby/object:Gem::Requirement
|
36
37
|
requirements:
|
37
|
-
- -
|
38
|
+
- - ~>
|
38
39
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
+
version: 0.0.22
|
41
|
+
- !ruby/object:Gem::Dependency
|
40
42
|
requirement: !ruby/object:Gem::Requirement
|
41
43
|
requirements:
|
42
44
|
- - '>='
|
43
45
|
- !ruby/object:Gem::Version
|
44
46
|
version: '0'
|
47
|
+
name: logstash-codec-plain
|
45
48
|
prerelease: false
|
46
49
|
type: :runtime
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: logstash-devutils
|
49
50
|
version_requirements: !ruby/object:Gem::Requirement
|
50
51
|
requirements:
|
51
52
|
- - '>='
|
52
53
|
- !ruby/object:Gem::Version
|
53
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
54
56
|
requirement: !ruby/object:Gem::Requirement
|
55
57
|
requirements:
|
56
58
|
- - '>='
|
57
59
|
- !ruby/object:Gem::Version
|
58
60
|
version: '0'
|
61
|
+
name: logstash-devutils
|
59
62
|
prerelease: false
|
60
63
|
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
61
69
|
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
70
|
email: info@elastic.co
|
63
71
|
executables: []
|
64
72
|
extensions: []
|
65
73
|
extra_rdoc_files: []
|
66
74
|
files:
|
67
|
-
- .gitignore
|
68
75
|
- CHANGELOG.md
|
69
76
|
- CONTRIBUTORS
|
70
77
|
- Gemfile
|
71
78
|
- LICENSE
|
72
79
|
- NOTICE.TXT
|
73
80
|
- README.md
|
74
|
-
- Rakefile
|
75
81
|
- lib/logstash/inputs/exec.rb
|
76
82
|
- logstash-input-exec.gemspec
|
77
83
|
- spec/inputs/exec_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
78
85
|
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
79
86
|
licenses:
|
80
87
|
- Apache License (2.0)
|
@@ -97,9 +104,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
104
|
version: '0'
|
98
105
|
requirements: []
|
99
106
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.4.8
|
101
108
|
signing_key:
|
102
109
|
specification_version: 4
|
103
110
|
summary: Run command line tools and capture the whole output as an event.
|
104
111
|
test_files:
|
105
112
|
- spec/inputs/exec_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
data/.gitignore
DELETED