logstash-input-mongoprofile 0.0.4 → 0.1.0

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: ff2afb9b35036f4258d7f1f2793b950fd6843d44
4
- data.tar.gz: 08f4206ddfa0e4e07e8958c92fcf7262a6551935
3
+ metadata.gz: 4b3cd711a6ed934de468e847d9cf8332d297e8b7
4
+ data.tar.gz: 90a64c5755513607ddf40ec43069541cdc1bda65
5
5
  SHA512:
6
- metadata.gz: 9323eb8fcf4f9ece741410133757299bc7b7d5536a55207841e3222e59e2ce110cc780f223096ab34c32b4836626c1e1385e34287bb30d859dd5af604013cc45
7
- data.tar.gz: a2acdaedb5030cd36f77552423c3237080811b409c022f80b3b5099722386804ba9c290854bd634f17762fc2d459780a820fb5d9c4f0e8110034d10dd5eae769
6
+ metadata.gz: 45477101f490427149e3c484dd57ee71e36f96e09002b2a1536f03f6550f940e1699513345cb1fd336d170504d9228c94615288acc7a3d25bf7723679e5dff08
7
+ data.tar.gz: 09c5fd423b4279cfcee47dcbf241b88e2ea5fc9104a2dcc4f591b531f92bef817577c89dbe191ef3c1463cac09205419d035020fbfff599584b3e5500981fdfc
@@ -1,9 +1,2 @@
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
-
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
@@ -0,0 +1,10 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Artem Antonov - aantonov.develop@gmail.com
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ Logstash, and you aren't on the list above and want to be, please let us know
9
+ and we'll make sure you're here. Contributions from folks like you are what make
10
+ open source awesome.
@@ -1,2 +1,2 @@
1
- # logstash-input-example
1
+ # logstash-input-mongoprofile
2
2
  Example input plugin. This should help bootstrap your effort to write your own input plugin!
data/Gemfile CHANGED
@@ -1,2 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
+
data/LICENSE CHANGED
@@ -1,5 +1,3 @@
1
- Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
-
3
1
  Licensed under the Apache License, Version 2.0 (the "License");
4
2
  you may not use this file except in compliance with the License.
5
3
  You may obtain a copy of the License at
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Logstash Plugin
2
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
3
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
4
 
7
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.
@@ -55,12 +53,7 @@ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
53
  ```
56
54
  - Install plugin
57
55
  ```sh
58
- # Logstash 2.3 and higher
59
56
  bin/logstash-plugin install --no-verify
60
-
61
- # Prior to Logstash 2.3
62
- bin/plugin install --no-verify
63
-
64
57
  ```
65
58
  - Run Logstash with your plugin
66
59
  ```sh
@@ -78,12 +71,7 @@ gem build logstash-filter-awesome.gemspec
78
71
  ```
79
72
  - Install the plugin from the Logstash home
80
73
  ```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
-
74
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
87
75
  ```
88
76
  - Start Logstash and proceed to test the plugin
89
77
 
@@ -95,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
95
83
 
96
84
  It is more important to the community that you are able to contribute.
97
85
 
98
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -1,48 +1,43 @@
1
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'
2
+ require "logstash/inputs/base"
3
+ require "logstash/namespace"
4
+ require "stud/interval"
5
+ require "socket" # for Socket.gethostname
7
6
 
8
7
  # Generate a repeating message.
9
8
  #
10
9
  # This plugin is intented only as an example.
11
10
 
12
11
  class LogStash::Inputs::Mongoprofile < LogStash::Inputs::Base
13
- config_name 'mongoprofile'
12
+ config_name "mongoprofile"
13
+
14
+ # If undefined, Logstash will complain, even if codec is unused.
15
+ default :codec, "plain"
16
+
17
+ # The message string to use in the event.
18
+ config :message, :validate => :string, :default => "Hello World!"
14
19
 
15
- default :codec, 'plain'
16
20
  # Set how frequently messages should be sent.
17
21
  #
18
22
  # The default, `1`, means send a message every second.
19
23
  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
 
24
25
  public
25
26
  def register
26
27
  @host = Socket.gethostname
27
- @controller = Controller.new(@host, @url, 'system.profile', 1000, @path, @client_host)
28
28
  end # def register
29
29
 
30
30
  def run(queue)
31
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
32
+ while !stop?
33
+ event = LogStash::Event.new("message" => @message, "host" => @host)
34
+ decorate(event)
35
+ queue << event
41
36
  # because the sleep interval can be big, when shutdown happens
42
37
  # we want to be able to abort the sleep
43
38
  # Stud.stoppable_sleep will frequently evaluate the given block
44
39
  # and abort the sleep(@interval) if the return value is true
45
- Stud.stoppable_sleep(@interval) {stop?}
40
+ Stud.stoppable_sleep(@interval) { stop? }
46
41
  end # loop
47
42
  end # def run
48
43
 
@@ -1,27 +1,25 @@
1
1
  Gem::Specification.new do |s|
2
- s.name = 'logstash-input-mongoprofile'
3
- s.version = '0.0.4'
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"]
2
+ s.name = 'logstash-input-mongoprofile'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = 'MongoDB system.profile input plugin'
6
+ s.description = 'MongoDB system.profile input plugin'
7
+ s.homepage = 'https://github.com/aantonovdevelop/logstash-input-mongoprofile'
8
+ s.authors = ['Artem Antonov']
9
+ s.email = 'aantonov.develop@gmail.com'
10
+ s.require_paths = ['lib']
11
11
 
12
12
  # Files
13
- s.files = Dir['lib/**/*', 'spec/**/*', 'vendor/**/*', '*.gemspec', '*.md', 'CONTRIBUTORS', 'Gemfile', 'LICENSE', 'NOTICE.TXT']
14
- # Tests
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
15
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
16
 
17
17
  # Special flag to let us know this is actually a logstash plugin
18
- s.metadata = {"logstash_plugin" => "true", "logstash_group" => "input"}
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
19
19
 
20
20
  # Gem dependencies
21
- s.add_runtime_dependency 'logstash-core', ">= 5.0"
21
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
22
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'
23
+ s.add_runtime_dependency 'stud', '>= 0.0.22'
24
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
27
25
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-mongoprofile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Elastic
7
+ - Artem Antonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-20 00:00:00.000000000 Z
11
+ date: 2017-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">="
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '5.0'
19
- name: logstash-core
18
+ version: '2.0'
19
+ name: logstash-core-plugin-api
20
20
  prerelease: false
21
21
  type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: 0.0.22
47
47
  name: stud
48
48
  prerelease: false
49
49
  type: :runtime
@@ -51,41 +51,13 @@ dependencies:
51
51
  requirements:
52
52
  - - ">="
53
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'
54
+ version: 0.0.22
69
55
  - !ruby/object:Gem::Dependency
70
56
  requirement: !ruby/object:Gem::Requirement
71
57
  requirements:
72
58
  - - ">="
73
59
  - !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'
60
+ version: 0.0.16
89
61
  name: logstash-devutils
90
62
  prerelease: false
91
63
  type: :development
@@ -93,24 +65,23 @@ dependencies:
93
65
  requirements:
94
66
  - - ">="
95
67
  - !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
68
+ version: 0.0.16
69
+ description: MongoDB system.profile input plugin
70
+ email: aantonov.develop@gmail.com
99
71
  executables: []
100
72
  extensions: []
101
73
  extra_rdoc_files: []
102
74
  files:
103
75
  - CHANGELOG.md
76
+ - CONTRIBUTORS
104
77
  - DEVELOPER.md
105
78
  - Gemfile
106
79
  - LICENSE
107
- - NOTICE.TXT
108
80
  - README.md
109
81
  - lib/logstash/inputs/mongoprofile.rb
110
- - lib/mongo/mongo.rb
111
82
  - logstash-input-mongoprofile.gemspec
112
83
  - spec/inputs/mongoprofile_spec.rb
113
- homepage: http://www.elastic.co/guide/en/logstash/current/index.html
84
+ homepage: https://github.com/aantonovdevelop/logstash-input-mongoprofile
114
85
  licenses:
115
86
  - Apache License (2.0)
116
87
  metadata:
@@ -135,6 +106,6 @@ rubyforge_project:
135
106
  rubygems_version: 2.4.8
136
107
  signing_key:
137
108
  specification_version: 4
138
- summary: This example input streams a string at a definable interval.
109
+ summary: MongoDB system.profile input plugin
139
110
  test_files:
140
111
  - spec/inputs/mongoprofile_spec.rb
data/NOTICE.TXT DELETED
@@ -1,5 +0,0 @@
1
- Elasticsearch
2
- Copyright 2012-2015 Elasticsearch
3
-
4
- This product includes software developed by The Apache Software
5
- Foundation (http://www.apache.org/).
@@ -1,117 +0,0 @@
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, client_host)
83
- @mongo_accessor = MongoAccessor.new(url, collection, client_host)
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
-