logstash-input-mongoprofile 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: cd0889730d84a5ca705d75deb849163985c2fc99
4
+ data.tar.gz: 2378ae1b19f5bdb762db38d904d164bed3f689d7
5
+ SHA512:
6
+ metadata.gz: 0c589f5fe8f5fc7ac3c8d9a4115a53a4e32c5e46237033dd723ba8f35387507046d77c9aeaf1e5b14a33c7b365d72c75b04fca07b322b7a413aeb90c2c950868
7
+ data.tar.gz: 3b2e460a21216cc892881f64f37f8d8b05ada665d32c8bb713295d9aa1343c8a5d9caf648c6cf3d0dcc0f74116311788adcb01d01588b90528a8e3f766acc12d
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## 2.0.4
2
+ - Add encoding: utf-8 line to spec file. This can prevent issues with tests.
3
+ ## 2.0.1
4
+ - Simplify the shutdown implementation a bit for easier understanding
5
+ ## 2.0.0
6
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
7
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
8
+ - Dependency on logstash-core update to 2.0
9
+
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-input-example
2
+ Example input plugin. This should help bootstrap your effort to write your own input plugin!
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
+
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
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
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.
data/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Logstash Plugin
2
+
3
+ [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-input-example.svg)](https://travis-ci.org/logstash-plugins/logstash-input-example)
4
+
5
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
+
7
+ 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.
8
+
9
+ ## Documentation
10
+
11
+ 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/).
12
+
13
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
14
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
15
+
16
+ ## Need Help?
17
+
18
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
19
+
20
+ ## Developing
21
+
22
+ ### 1. Plugin Developement and Testing
23
+
24
+ #### Code
25
+ - To get started, you'll need JRuby with the Bundler gem installed.
26
+
27
+ - 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).
28
+
29
+ - Install dependencies
30
+ ```sh
31
+ bundle install
32
+ ```
33
+
34
+ #### Test
35
+
36
+ - Update your dependencies
37
+
38
+ ```sh
39
+ bundle install
40
+ ```
41
+
42
+ - Run tests
43
+
44
+ ```sh
45
+ bundle exec rspec
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ # Logstash 2.3 and higher
59
+ bin/logstash-plugin install --no-verify
60
+
61
+ # Prior to Logstash 2.3
62
+ bin/plugin install --no-verify
63
+
64
+ ```
65
+ - Run Logstash with your plugin
66
+ ```sh
67
+ bin/logstash -e 'filter {awesome {}}'
68
+ ```
69
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
70
+
71
+ #### 2.2 Run in an installed Logstash
72
+
73
+ 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:
74
+
75
+ - Build your plugin gem
76
+ ```sh
77
+ gem build logstash-filter-awesome.gemspec
78
+ ```
79
+ - Install the plugin from the Logstash home
80
+ ```sh
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
+
87
+ ```
88
+ - Start Logstash and proceed to test the plugin
89
+
90
+ ## Contributing
91
+
92
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
93
+
94
+ 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.
95
+
96
+ It is more important to the community that you are able to contribute.
97
+
98
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+ require 'logstash/inputs/base'
3
+ require 'logstash/namespace'
4
+ require 'stud/interval'
5
+ require 'socket' # for Socket.gethostname
6
+ require '../../../lib/mongo/mongo'
7
+
8
+ # Generate a repeating message.
9
+ #
10
+ # This plugin is intented only as an example.
11
+
12
+ class LogStash::Inputs::Example < LogStash::Inputs::Base
13
+ config_name 'mongoprofile'
14
+
15
+
16
+ # Set how frequently messages should be sent.
17
+ #
18
+ # The default, `1`, means send a message every second.
19
+ config :interval, :validate => :number, :default => 1
20
+ config :url, :validate => :string, :required => true
21
+ config :path, :validate => :string, :required => true
22
+ config :client_host, :validate => :string, :default => '127.0.0.1'
23
+
24
+ public
25
+ def register
26
+ @host = Socket.gethostname
27
+ @controller = Controller.new(@host, @url, 'system.profile', 1000, @path)
28
+ end # def register
29
+
30
+ def run(queue)
31
+ # we can abort the loop if stop? becomes true
32
+ until stop?
33
+ #event = LogStash::Event.new("message" => @message, "host" => @host)
34
+
35
+ @controller.get_next_events.each do |event|
36
+ @logger.info("Send event #{event}")
37
+
38
+ decorate(event)
39
+ queue << event
40
+ end
41
+ # because the sleep interval can be big, when shutdown happens
42
+ # we want to be able to abort the sleep
43
+ # Stud.stoppable_sleep will frequently evaluate the given block
44
+ # and abort the sleep(@interval) if the return value is true
45
+ Stud.stoppable_sleep(@interval) {stop?}
46
+ end # loop
47
+ end # def run
48
+
49
+ def stop
50
+ # nothing to do in this case so it is not necessary to define stop
51
+ # examples of common "stop" tasks:
52
+ # * close sockets (unblocking blocking reads/accepts)
53
+ # * cleanup temporary files
54
+ # * terminate spawned threads
55
+ end
56
+ end # class LogStash::Inputs::Example
@@ -0,0 +1,117 @@
1
+ require 'mongo'
2
+ require 'logstash/inputs/base'
3
+
4
+ class MongoAccessor
5
+ def initialize(url, collection, client_host)
6
+ connection = Mongo::Client.new(url)
7
+
8
+ @mongodb = connection.database
9
+ @collection = @mongodb.collection(collection)
10
+ @client_host = client_host
11
+ end
12
+
13
+ def get_documents_by_ts(date, limit)
14
+ @collection.find({:ts => {:$gt => date}, :client => {:$ne => @client_host}}).limit(limit)
15
+ end
16
+
17
+ def get_documents(limit)
18
+ @collection.find({:client => {:$ne => @client_host}}).limit(limit)
19
+ end
20
+ end
21
+
22
+ class ProfileCollection
23
+ def initialize(documents, parser)
24
+ @documents = documents
25
+ @parser = parser
26
+ end
27
+
28
+ def each
29
+ @documents.each do |document|
30
+ document['_id'] = generate_id
31
+ yield @parser.parse(document)
32
+ end
33
+ end
34
+
35
+ def get_last_document_date
36
+ @documents[-1]['ts']
37
+ end
38
+
39
+ private
40
+ def generate_id
41
+ # noinspection RubyArgCount
42
+ BSON::ObjectId.new
43
+ end
44
+ end
45
+
46
+ class DocumentParser
47
+ def initialize(host)
48
+ @host = host
49
+ end
50
+
51
+ def parse(document)
52
+ event = LogStash::Event.new('host' => @host)
53
+
54
+ document.each do |key, value|
55
+ event.set(key, value)
56
+ end
57
+
58
+ event
59
+ end
60
+ end
61
+
62
+ class LastValueStore
63
+ def initialize(path, name)
64
+ @file_full_name = "#{path}/#{name}"
65
+ end
66
+
67
+ def save_last_value(value)
68
+ file = File.open(@file_full_name, 'a+')
69
+
70
+ file.truncate(0)
71
+ file.puts(value)
72
+
73
+ file.close
74
+ end
75
+
76
+ def get_last_value
77
+ File.read(@file_full_name)
78
+ end
79
+ end
80
+
81
+ class Controller
82
+ def initialize(event, url, collection, limit, path)
83
+ @mongo_accessor = MongoAccessor.new(url, collection)
84
+ @last_value_store = LastValueStore.new(path, collection)
85
+ @document_parser = DocumentParser.new(event)
86
+ @limit = limit
87
+ end
88
+
89
+ def get_next_events
90
+ last_date_value = @last_value_store.get_last_value
91
+
92
+ if last_date_value == ''
93
+ documents = @mongo_accessor.get_documents(@limit)
94
+ else
95
+ documents = @mongo_accessor.get_documents_by_ts(last_date_value, @limit)
96
+ end
97
+
98
+ profile_collection = ProfileCollection.new(documents, @document_parser)
99
+
100
+ @last_value_store.save_last_value(profile_collection.get_last_document_date)
101
+
102
+ profile_collection
103
+ end
104
+ end
105
+
106
+ lv = LastValueStore.new('/home/artem', 'mex.txt')
107
+
108
+ lv.save_last_value("blasaldkfj")
109
+ puts lv.get_last_value
110
+
111
+ #mongo = MongoAccessor.new('mongodb://192.168.1.37/eleet-v2-dev', 'system.profile')
112
+
113
+ #ProfileCollection.new(mongo.get_documents(10)).each do |document|
114
+ #puts document['_id']
115
+ #end
116
+
117
+
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-input-mongoprofile'
3
+ s.version = '0.0.1'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This example input streams a string at a definable interval."
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"
7
+ s.authors = ["Elastic"]
8
+ s.email = 'info@elastic.co'
9
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*', 'spec/**/*', 'vendor/**/*', '*.gemspec', '*.md', 'CONTRIBUTORS', 'Gemfile', 'LICENSE', 'NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = {"logstash_plugin" => "true", "logstash_group" => "input"}
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency 'logstash-core', ">= 5.0"
22
+ s.add_runtime_dependency 'logstash-codec-plain'
23
+ s.add_runtime_dependency 'stud'
24
+ s.add_runtime_dependency 'sequel'
25
+ s.add_runtime_dependency 'mongo', '>= 2.0.0'
26
+ s.add_development_dependency 'logstash-devutils'
27
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/example"
4
+
5
+ describe LogStash::Inputs::Example do
6
+
7
+ it_behaves_like "an interruptible input plugin" do
8
+ let(:config) { { "interval" => 100 } }
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-mongoprofile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Elastic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '5.0'
19
+ name: logstash-core
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-codec-plain
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: stud
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ name: sequel
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.0.0
75
+ name: mongo
76
+ prerelease: false
77
+ type: :runtime
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ name: logstash-devutils
90
+ prerelease: false
91
+ type: :development
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ 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
98
+ email: info@elastic.co
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - CHANGELOG.md
104
+ - DEVELOPER.md
105
+ - Gemfile
106
+ - LICENSE
107
+ - NOTICE.TXT
108
+ - README.md
109
+ - lib/logstash/inputs/example.rb
110
+ - lib/mongo/mongo.rb
111
+ - logstash-input-mongoprofile.gemspec
112
+ - spec/inputs/example_spec.rb
113
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
114
+ licenses:
115
+ - Apache License (2.0)
116
+ metadata:
117
+ logstash_plugin: 'true'
118
+ logstash_group: input
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.4.8
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: This example input streams a string at a definable interval.
139
+ test_files:
140
+ - spec/inputs/example_spec.rb