logstash-input-folder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1ca8f859671c7eaf3ecf3d4e220297f47e50527
4
+ data.tar.gz: 579c754793aa225c2b845ba60aebd869c25fde55
5
+ SHA512:
6
+ metadata.gz: fa7d114fbe6eb2e206007ee84f4bb24b8995ec7bf762d3b7097528610cea7d32466397e386edd4fc28c809712637128355e353ee1fc00fd9914099944ccc9b5e
7
+ data.tar.gz: 324b0b292c2d7bca57df32a7e1d0679dac977104b8a21b9354ec7149d6acb7b65ac3cc8c3dd51954e0a428012d9d4e9d25ea9d5588c277ebba68a220ee8d1e17
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
4
+ vendor
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
4
+
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
+
7
+ ## Documentation
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.elasticsearch.org/guide/en/logstash/current/).
10
+
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/elasticsearch/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {awesome {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ @files=[]
2
+
3
+ task :default do
4
+ system("rake -T")
5
+ end
6
+
7
+ require "logstash/devutils/rake"
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+ require "logstash/inputs/base"
3
+ require "logstash/namespace"
4
+
5
+ require "pathname"
6
+ require "socket"
7
+ require 'thread'
8
+ require "rb-inotify"
9
+
10
+ class LogStash::Inputs::Folder < LogStash::Inputs::Base
11
+ config_name "folder"
12
+
13
+ default :codec, "plain"
14
+
15
+ config :path, :validate => :string, :required => true
16
+
17
+
18
+ public
19
+ def register
20
+ @logger.info("Registering folder input", :path => @path)
21
+
22
+ if Pathname.new(@path).relative?
23
+ raise ArgumentError.new("File paths must be absolute, relative path specified: #{path}")
24
+ end
25
+
26
+ @fileQueue = Queue.new
27
+ end
28
+
29
+ public
30
+ def run(queue)
31
+ hostname = Socket.gethostname
32
+
33
+ @notifier = INotify::Notifier.new
34
+
35
+ @notifier.watch(@path, :create) do |event|
36
+ @logger.debug("new file", :path => event.name)
37
+ @fileQueue << event
38
+ end
39
+
40
+ @consumer = Thread.new do
41
+ while true do
42
+ fileEvent = @fileQueue.pop
43
+ fileName = "#{@path}/#{fileEvent.name}"
44
+ begin
45
+ if File.writable?(fileName)
46
+ @codec.decode(File.read(fileName)) do |event|
47
+ decorate(event)
48
+ event["host"] = hostname if !event.include?("host")
49
+ event["path"] = fileName
50
+ queue << event
51
+ end
52
+ else
53
+ sleep(1)
54
+ @fileQueue << fileEvent
55
+ end
56
+ rescue Exception => e
57
+ @fileQueue << fileEvent
58
+ end
59
+ end
60
+ end
61
+
62
+ @notifier.run
63
+
64
+ finished
65
+
66
+ puts "folder plugin started"
67
+ end
68
+
69
+ public
70
+ def teardown
71
+ @notifier.close
72
+ @consumer
73
+ end
74
+ end
@@ -0,0 +1,31 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-input-folder'
4
+ s.version = '0.0.1'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "Stream events from folder."
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"
8
+ s.authors = ["Lance"]
9
+ s.email = 'carck@foxmail.com'
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
14
+
15
+ # Tests
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+
18
+ # Special flag to let us know this is actually a logstash plugin
19
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
20
+
21
+ # Gem dependencies
22
+ s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
23
+
24
+ s.add_runtime_dependency 'logstash-codec-plain'
25
+ s.add_runtime_dependency 'addressable'
26
+ s.add_runtime_dependency 'rb-inotify', ['0.9.5']
27
+
28
+ s.add_development_dependency 'stud', ['~> 0.0.19']
29
+ s.add_development_dependency 'logstash-devutils'
30
+ end
31
+
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require "logstash/devutils/rspec/spec_helper"
4
+ require "tempfile"
5
+ require "stud/temporary"
6
+
7
+ describe "inputs/folder" do
8
+
9
+ describe "collect new files" do
10
+ tmpfile_path = Stud::Temporary.directory
11
+
12
+ config <<-CONFIG
13
+ input {
14
+ folder {
15
+ path => "#{tmpfile_path}"
16
+ }
17
+ }
18
+ CONFIG
19
+
20
+ input do |pipeline, queue|
21
+ Thread.new { pipeline.run }
22
+ sleep 0.1 while !pipeline.ready?
23
+
24
+ # at this point even if pipeline.ready? == true the plugins
25
+ # threads might still be initializing so we cannot know when the
26
+ # file plugin will have seen the original file, it could see it
27
+ # after the first(s) hello world appends below, hence the
28
+ # retry logic.
29
+ retries = 0
30
+ loop do
31
+ insist { retries } < 20 # 2 secs should be plenty?
32
+
33
+ File.open("#{tmpfile_path}/#{retries}.log", "w") do |fd|
34
+ fd.puts("1")
35
+ end
36
+
37
+ if queue.size >= 1
38
+ events = 1.times.collect { queue.pop }
39
+ insist { events[0]["message"] } == "1\n"
40
+ break
41
+ end
42
+
43
+ sleep(0.1)
44
+ retries += 1
45
+ end
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-folder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lance
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.0
28
+ - - "<"
29
+ - !ruby/object:Gem::Version
30
+ version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-codec-plain
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: addressable
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ prerelease: false
60
+ type: :runtime
61
+ - !ruby/object:Gem::Dependency
62
+ name: rb-inotify
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '='
66
+ - !ruby/object:Gem::Version
67
+ version: 0.9.5
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '='
71
+ - !ruby/object:Gem::Version
72
+ version: 0.9.5
73
+ prerelease: false
74
+ type: :runtime
75
+ - !ruby/object:Gem::Dependency
76
+ name: stud
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.0.19
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: 0.0.19
87
+ prerelease: false
88
+ type: :development
89
+ - !ruby/object:Gem::Dependency
90
+ name: logstash-devutils
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirement: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ prerelease: false
102
+ type: :development
103
+ 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
104
+ email: carck@foxmail.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - ".gitignore"
110
+ - Gemfile
111
+ - README.md
112
+ - Rakefile
113
+ - lib/logstash/inputs/folder.rb
114
+ - logstash-input-folder.gemspec
115
+ - spec/inputs/folder_spec.rb
116
+ homepage:
117
+ licenses:
118
+ - Apache License (2.0)
119
+ metadata:
120
+ logstash_plugin: 'true'
121
+ logstash_group: input
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.5
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Stream events from folder.
142
+ test_files:
143
+ - spec/inputs/folder_spec.rb