logstash-input-toggl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTORS +12 -0
- data/Gemfile +3 -0
- data/LICENSE +13 -0
- data/README.md +95 -0
- data/Rakefile +7 -0
- data/lib/logstash/inputs/toggl.rb +89 -0
- data/logstash-input-toggl.gemspec +27 -0
- data/spec/inputs/toggl_spec.rb +1 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6a54e8b13e920b374dde9f8cff6a8b70c2116c0f
|
4
|
+
data.tar.gz: 71ee9b11ebfb90ec582e2333765efe600b693817
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc7af47f98e1f277e10c62574f8c6759974f5fc48dab062fe6ab6f014e0097a79d414521e58ac505a4edc97f0717d8ecb3a05a37607dea58b4e67e1245155e93
|
7
|
+
data.tar.gz: 7636d1689d27ab5363abec29363f89c6e012034ecafcc2551a9a01ae103c05dc8885ac283f5f12fee5149a1d8912707c4a7d00d1bcd36c14bd26e918d33951c9
|
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,12 @@
|
|
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
|
+
* Jason Kendall (coolacid)
|
6
|
+
* Pier-Hugues Pellerin (ph)
|
7
|
+
* Suyog Rao (suyograo)
|
8
|
+
|
9
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
10
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
11
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
12
|
+
open source awesome.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012-2015 Elasticsearch <http://www.elasticsearch.org>
|
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/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
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.
|
26
|
+
|
27
|
+
- Install dependencies
|
28
|
+
```sh
|
29
|
+
bundle install
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Test
|
33
|
+
|
34
|
+
```sh
|
35
|
+
bundle exec rspec
|
36
|
+
```
|
37
|
+
|
38
|
+
The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to:
|
39
|
+
```ruby
|
40
|
+
gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
|
41
|
+
```
|
42
|
+
To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example:
|
43
|
+
```ruby
|
44
|
+
gem "logstash", :github => "elasticsearch/logstash", :ref => "master"
|
45
|
+
```
|
46
|
+
```ruby
|
47
|
+
gem "logstash", :path => "/your/local/logstash"
|
48
|
+
```
|
49
|
+
|
50
|
+
Then update your dependencies and run your tests:
|
51
|
+
|
52
|
+
```sh
|
53
|
+
bundle install
|
54
|
+
bundle exec rspec
|
55
|
+
```
|
56
|
+
|
57
|
+
### 2. Running your unpublished Plugin in Logstash
|
58
|
+
|
59
|
+
#### 2.1 Run in a local Logstash clone
|
60
|
+
|
61
|
+
- Edit Logstash `tools/Gemfile` and add the local plugin path, for example:
|
62
|
+
```ruby
|
63
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
64
|
+
```
|
65
|
+
- Update Logstash dependencies
|
66
|
+
```sh
|
67
|
+
rake vendor:gems
|
68
|
+
```
|
69
|
+
- Run Logstash with your plugin
|
70
|
+
```sh
|
71
|
+
bin/logstash -e 'filter {awesome {}}'
|
72
|
+
```
|
73
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
74
|
+
|
75
|
+
#### 2.2 Run in an installed Logstash
|
76
|
+
|
77
|
+
- Build your plugin gem
|
78
|
+
```sh
|
79
|
+
gem build logstash-filter-awesome.gemspec
|
80
|
+
```
|
81
|
+
- Install the plugin from the Logstash home
|
82
|
+
```sh
|
83
|
+
bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
|
84
|
+
```
|
85
|
+
- Start Logstash and proceed to test the plugin
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
90
|
+
|
91
|
+
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.
|
92
|
+
|
93
|
+
It is more important to me that you are able to contribute.
|
94
|
+
|
95
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
|
data/Rakefile
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/inputs/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require "socket" # for Socket.gethostname
|
5
|
+
|
6
|
+
# Pull time entries from detailed report Toggl API.
|
7
|
+
#
|
8
|
+
# Detailed report URL: GET https://toggl.com/reports/api/v2/details
|
9
|
+
class LogStash::Inputs::Toggl < LogStash::Inputs::Base
|
10
|
+
|
11
|
+
config_name "toggl"
|
12
|
+
|
13
|
+
milestone 1
|
14
|
+
|
15
|
+
# Interval to run the command. Value is in seconds.
|
16
|
+
config :interval, :validate => :number, :required => true
|
17
|
+
|
18
|
+
# API Token
|
19
|
+
config :api_token, :validate => :string, :required => true
|
20
|
+
|
21
|
+
# Workspace ID
|
22
|
+
#
|
23
|
+
# The workspace which data you want to access.
|
24
|
+
config :workspace_id, :validate => :string, :required => true
|
25
|
+
|
26
|
+
# User Agent
|
27
|
+
#
|
28
|
+
# The name of your application or your email address so we can get in touch in case you're doing something wrong.
|
29
|
+
config :user_agent, :validate => :string, :required => true
|
30
|
+
|
31
|
+
# Since
|
32
|
+
#
|
33
|
+
# ISO 8601 date (YYYY-MM-DD), by default until - 6 days.
|
34
|
+
config :since, :validate => :string, :required => false
|
35
|
+
|
36
|
+
public
|
37
|
+
def register
|
38
|
+
require "faraday"
|
39
|
+
require "json"
|
40
|
+
|
41
|
+
if since
|
42
|
+
addon = "since=#{ @since }"
|
43
|
+
else
|
44
|
+
addon = ""
|
45
|
+
end
|
46
|
+
|
47
|
+
@url = "https://toggl.com/reports/api/v2/details?workspace_id=#{ @workspace_id }&user_agent=#{ @user_agent }&#{ addon }"
|
48
|
+
@logger.info? && @logger.info("Registering Toggl Input", :url => @url, :interval => @interval)
|
49
|
+
end # def register
|
50
|
+
|
51
|
+
public
|
52
|
+
def run(queue)
|
53
|
+
Stud.interval(@interval) do
|
54
|
+
start = Time.now
|
55
|
+
@logger.info? && @logger.info("Polling Toggl", :url => @url, :time => start)
|
56
|
+
|
57
|
+
conn = Faraday.new do |builder|
|
58
|
+
builder.use Faraday::Request::Retry
|
59
|
+
builder.use Faraday::Request::BasicAuthentication, @api_token, 'api_token'
|
60
|
+
builder.use Faraday::Response::Logger
|
61
|
+
builder.use Faraday::Adapter::NetHttp
|
62
|
+
end
|
63
|
+
|
64
|
+
page = 1
|
65
|
+
|
66
|
+
while true
|
67
|
+
new_url = @url + "&page=#{ page }"
|
68
|
+
|
69
|
+
response = conn.get new_url
|
70
|
+
result = JSON.parse(response.body)
|
71
|
+
|
72
|
+
if result["data"].nil? || result["data"].empty?
|
73
|
+
break
|
74
|
+
end
|
75
|
+
|
76
|
+
result["data"].each do |rawevent|
|
77
|
+
event = LogStash::Event.new(rawevent)
|
78
|
+
decorate(event)
|
79
|
+
queue << event
|
80
|
+
end
|
81
|
+
|
82
|
+
page += 1
|
83
|
+
end
|
84
|
+
|
85
|
+
duration = Time.now - start
|
86
|
+
@logger.info? && @logger.info("Poll completed", :command => @command, :duration => duration)
|
87
|
+
end # loop
|
88
|
+
end # def run
|
89
|
+
end # class LogStash::Inputs::Exec
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-input-toggl'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.licenses = ['Apache License (2.0)']
|
5
|
+
s.summary = "Pull time entries from a detailed report Toggl API."
|
6
|
+
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"
|
7
|
+
s.authors = ["Shoutem"]
|
8
|
+
s.email = 'kristijan@shoutem.com'
|
9
|
+
s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html"
|
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', '>= 1.4.0', '< 2.0.0'
|
23
|
+
|
24
|
+
s.add_runtime_dependency 'addressable'
|
25
|
+
|
26
|
+
s.add_development_dependency 'logstash-devutils'
|
27
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Empty
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-input-toggl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shoutem
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash
|
15
|
+
requirement: !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
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.4.0
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: addressable
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: logstash-devutils
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
description: This gem is a logstash plugin required to be installed on top of the
|
62
|
+
Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
|
63
|
+
a stand-alone program
|
64
|
+
email: kristijan@shoutem.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- CONTRIBUTORS
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/logstash/inputs/toggl.rb
|
75
|
+
- logstash-input-toggl.gemspec
|
76
|
+
- spec/inputs/toggl_spec.rb
|
77
|
+
homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
|
78
|
+
licenses:
|
79
|
+
- Apache License (2.0)
|
80
|
+
metadata:
|
81
|
+
logstash_plugin: 'true'
|
82
|
+
logstash_group: input
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Pull time entries from a detailed report Toggl API.
|
103
|
+
test_files:
|
104
|
+
- spec/inputs/toggl_spec.rb
|