logstash-input-stripe 0.1.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
+ SHA256:
3
+ metadata.gz: 68073b05ae6e308acfc9de915a25d4afbf251576805b3c634c58e5fcf04892e7
4
+ data.tar.gz: 3ff06e583ab3c1c193cc875b85b391dcf285662c31476473131535c9a71ebbea
5
+ SHA512:
6
+ metadata.gz: b42976293bfb814fc14229138dc24bdaac641577cf1223d6231a8b7bf25fe7925f7902c59882f6d3b9cd2534582eb7d982c2b0e7712fd6c406b628f2ab2c5b71
7
+ data.tar.gz: 0fc0f57d01502546535ffc25afe531c7531b8526b9a1b53bd7a3a93b85de3b15ee2a5ed31b42369423e327c195d14f6f1cda61bdd6257b62d1c39bf56f48c7a2
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
data/CONTRIBUTORS ADDED
@@ -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
+ * Marek Wasko - marek@ziin.info
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.
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-input-stripe
2
+ Example input plugin. This should help bootstrap your effort to write your own input plugin!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'stripe', '=3.3.2'
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/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.elastic.co/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/elastic/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
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/logstash-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/logstash-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/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+ require "logstash/inputs/base"
3
+ require "stud/interval"
4
+ require "stripe"
5
+
6
+ # Generate a repeating message.
7
+ #
8
+ # This plugin is intented only as an example.
9
+
10
+ class LogStash::Inputs::Stripe < LogStash::Inputs::Base
11
+ config_name "stripe"
12
+
13
+ # If undefined, Logstash will complain, even if codec is unused.
14
+ default :codec, "plain"
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 => 0.5
20
+
21
+ # Secret key from your Stripe dashboard
22
+ config :secret_key, :validate => :string, :required => true
23
+
24
+ #Elastic Search query url
25
+ config :es_query_url, :validate => :string, :required => true
26
+
27
+ public
28
+ def register
29
+ Stripe.api_key = @secret_key
30
+ end # def register
31
+
32
+ def run(queue)
33
+ # we can abort the loop if stop? becomes true
34
+ starting_after = nil
35
+ while !stop?
36
+ charges = get_charges(starting_after).to_hash
37
+ charges.fetch(:data, []).each do |charge|
38
+ logger.info charge.inspect
39
+ event = LogStash::Event.new(charge)
40
+ decorate(event)
41
+ queue << event
42
+ starting_after = charge[:id]
43
+ end
44
+
45
+ # if doc has been indexed wait 10s and start from begining
46
+ if has_doc?(starting_after)
47
+ starting_after = nil
48
+ @interval = 15
49
+ else
50
+ @interval = 0.5
51
+ end
52
+
53
+ # because the sleep interval can be big, when shutdown happens
54
+ # we want to be able to abort the sleep
55
+ # Stud.stoppable_sleep will frequently evaluate the given block
56
+ # and abort the sleep(@interval) if the return value is true
57
+ Stud.stoppable_sleep(@interval) { stop? }
58
+ end # loop
59
+ end # def run
60
+
61
+ def stop
62
+ # nothing to do in this case so it is not necessary to define stop
63
+ # examples of common "stop" tasks:
64
+ # * close sockets (unblocking blocking reads/accepts)
65
+ # * cleanup temporary files
66
+ # * terminate spawned threads
67
+ end
68
+
69
+ private
70
+ def get_charges(starting_after = nil)
71
+ Stripe::Charge.list(limit: 100, starting_after: starting_after)
72
+ end
73
+
74
+ def format_time(string)
75
+ # salesforce can use different time formats so until we have a higher
76
+ # performance requirement we can just use Time.parse
77
+ # otherwise it's possible to use a sequence of DateTime.strptime, for example
78
+ LogStash::Timestamp.new(Time.strptime(string, '%s'))
79
+ end
80
+
81
+ def has_doc?(id)
82
+ return false if id.blank?
83
+ conn = Faraday.new(url: @es_query_url)
84
+ conn.post '/_refresh'
85
+ response = conn.post do |req|
86
+ req.url '/_search'
87
+ req.headers['Content-Type'] = 'application/json'
88
+ req.body = %Q[{
89
+ "query": {
90
+ "terms": {
91
+ "_id": [ "#{id}" ]
92
+ }
93
+ }
94
+ }]
95
+ end
96
+ JSON.parse(response.body).fetch('hits', {}).fetch('total') == 1
97
+ end
98
+ end # class LogStash::Inputs::Stripe
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-input-stripe'
3
+ s.version = '0.1.1'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Stripe input for logstash'
6
+ s.description = 'Creates events based on stripe charges'
7
+ s.homepage = 'http://ziin.info'
8
+ s.authors = ['Marek Wasko']
9
+ s.email = 'marek@ziin.info'
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-plugin-api", "~> 2.0"
22
+ s.add_runtime_dependency 'logstash-codec-plain'
23
+ s.add_runtime_dependency 'stud', '>= 0.0.22'
24
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
25
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/stripe"
4
+
5
+ describe LogStash::Inputs::Stripe 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,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-stripe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Marek Wasko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-24 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: '2.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.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.0.22
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.0.22
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.16
61
+ name: logstash-devutils
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.16
69
+ description: Creates events based on stripe charges
70
+ email: marek@ziin.info
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - CHANGELOG.md
76
+ - CONTRIBUTORS
77
+ - DEVELOPER.md
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - lib/logstash/inputs/stripe.rb
82
+ - logstash-input-stripe.gemspec
83
+ - spec/inputs/stripe_spec.rb
84
+ homepage: http://ziin.info
85
+ licenses:
86
+ - Apache-2.0
87
+ metadata:
88
+ logstash_plugin: 'true'
89
+ logstash_group: input
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.6.13
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Stripe input for logstash
110
+ test_files:
111
+ - spec/inputs/stripe_spec.rb