fluent-plugin-deskcom 0.0.1 → 0.0.2

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: 5641dbda7a204f52d882965061aea9a383f83730
4
- data.tar.gz: 9170d67ca166201d7bc734efec235d927c92a017
3
+ metadata.gz: 952794ba64a64955c3fbd9f599c5faedc81c3374
4
+ data.tar.gz: 8619e94793db9f42d657b19e0f30207233a7e8bc
5
5
  SHA512:
6
- metadata.gz: 9057d3893407ec129cc8cf68f6280fb329ce1578c51628085ac5c19bc61a5f2dc970c28ec47d6414fe0ca05529522fe9894e3fee4f24ce2c3363f03a0384f0aa
7
- data.tar.gz: 3ccee42a011fa0a5c40fb3c3890c8808b0bcde0a52b971764746303757749750bccb5f061017660763553a1fccf06adc706341ab5504d50e742c17e1b70777db
6
+ metadata.gz: b2e0bc35b53bfdb8fd92fee8ffe933ded9d45c3d2d276d6202542ac0bacf5e4dfcac526df97ca32f805806df8037db295ff4d5264cb0edd6b43a0fb5bc9bcd29
7
+ data.tar.gz: 55e0f6aba3af35167ff91d506b0faa0a516cf3b18cc7908d4beb2779da639327f84267557dec8982310d32c9a1257763491aae21ab339242457113cd9714b1d0
data/README.md CHANGED
@@ -7,6 +7,12 @@ This plugin is still experimental.
7
7
  This plugin depends on [desk library](https://github.com/chriswarren/desk)
8
8
  Also, please see [Desk API v2](http://dev.desk.com/)
9
9
 
10
+ ## Quick Start
11
+
12
+ If you want to use fluent-plugin-deskcom on Heroku, you can start easily.
13
+ Please see the following page, and click Deploy to Heroku button!
14
+ https://github.com/toru-takahashi/heroku-td-agent
15
+
10
16
  ## Installation
11
17
 
12
18
  Add this line to your application's Gemfile:
@@ -23,8 +29,26 @@ Or install it yourself as:
23
29
 
24
30
  $ gem install fluent-plugin-deskcom
25
31
 
32
+ ### Get Desk.com API key
33
+
34
+ Your Desk.com API key, secret, token and token secret can be found by following this guide:
35
+
36
+ 1. Log in to your Desk.com admin panel using your personal URL (http://your-account.desk.com/admin).
37
+ 2. Click on Settings:
38
+ ![step2](http://gyazo.com/020298636ef217e0d3bb7ee7b6a0bd31.png)
39
+ 3. From the left menu select API > My Applications.
40
+ 4. If you don’t already have an application defined for TreasureData, create one by clicking on the “Add API Application” button and enter the following information:
41
+ ![step4-1](http://gyazo.com/803b486ed3a86c77af55819e83d4d85b.png)
42
+ ![step4-2](http://gyazo.com/97a5624030f1bc05fe040e386d30f7dd.png)
43
+ 5. Find your Key and Secret codes for the TreasureData API application:
44
+ ![step5](http://gyazo.com/895bf963f01b65254e38c534855a1914.png)
45
+ 6. Find your Token and Token secret by clicking on the Your Access Token link:
46
+ ![step6](http://gyazo.com/7f057fb4b6b88b616f9895d4d5b69e9d.png)
47
+
26
48
  ## Usage
27
49
 
50
+ The followings are examples of fluentd.conf(td-agent.conf)
51
+
28
52
  ### Cases Config Sample
29
53
 
30
54
  ```ruby
@@ -151,8 +175,6 @@ Or install it yourself as:
151
175
  </match>
152
176
  ```
153
177
 
154
- Please check store_file's permission to write by fluentd.
155
-
156
178
  ## TO DO
157
179
 
158
180
  - Allows over 2 input_api (Ex. input_api cases,replies)
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-deskcom"
6
- spec.version = "0.0.1"
6
+ spec.version = "0.0.2"
7
7
  spec.authors = ["Toru Takahashi"]
8
8
  spec.email = ["torutakahashi.ayashi@gmail.com"]
9
9
  spec.summary = %q{Input plugin to collect data from Deskcom.}
@@ -18,6 +18,7 @@ class DeskcomInput < Fluent::Input
18
18
  config_param :input_api, :string, :default => 'cases'
19
19
  config_param :tag, :string, :default => nil
20
20
  config_param :time_column, :string, :default => nil
21
+ config_param :interval, :integer,:default => 5
21
22
 
22
23
  def initialize
23
24
  super
@@ -45,9 +46,9 @@ class DeskcomInput < Fluent::Input
45
46
  $log.warn("stored_time_file path is missing")
46
47
  end
47
48
 
49
+ @tick = @interval * 60
48
50
 
49
51
  @stored_time = load_store_file
50
- @started_time = Time.now.to_i
51
52
  @per_page = DEFAULT_PER_PAGE
52
53
 
53
54
  Desk.configure do |config|
@@ -65,32 +66,56 @@ class DeskcomInput < Fluent::Input
65
66
  end
66
67
 
67
68
  def shutdown
68
- @thread.kill
69
+ super
70
+ @thread.terminate
71
+ @thread.join
69
72
  end
70
73
 
71
74
  def run
72
- page = 1
75
+ while true
76
+ @started_time = Time.now.to_i
77
+ get_stream
78
+ save_store_file unless !@store_file
79
+ sleep @tick
80
+ end
81
+ end
82
+
83
+ def get_stream()
84
+ page = 0
73
85
  if @input_api == 'cases' then
74
86
  begin
87
+ page = page + 1
75
88
  cases = Desk.cases(:since_updated_at => @stored_time, :page => page, :per_page => @per_page)
89
+ # Sleep for rate limit
90
+ # ToDo: Check body "Too Many Requests" and Sleep
91
+ sleep(2)
92
+
76
93
  cases.each do |c|
77
94
  get_content(c)
78
95
  end
79
- page = page + 1
80
- end while cases.total_entries > (@per_page*page)
96
+ $log.info "Case total entry: #{cases.total_entries} page: #{page}"
97
+ end while (cases.total_entries/@per_page.to_f).ceil > page
81
98
  elsif @input_api == 'replies'
82
99
  begin
83
- cases = Desk.cases(:since_updated_at => @stored_time, :page => page, :per_page => @per_page)
100
+ page = page + 1
101
+ cases = Desk.cases(:since_updated_at => @stored_time, :page => page, :per_page => @per_page)
102
+ # Sleep for rate limit
103
+ # ToDo: Check body "Too Many Requests" and Sleep
104
+ sleep(2)
105
+
84
106
  cases.each do |c|
85
107
  Desk.case_replies(c.id).each do |r|
108
+ # Sleep for rate limit
109
+ # ToDo: Check body "Too Many Requests" and Sleep
110
+ sleep(2)
111
+
86
112
  r[:case_id] = c.id
87
113
  get_content(r) if c.count > 0
88
114
  end
89
115
  end
90
- page = page + 1
91
- end while cases.total_entries > (@per_page*page)
116
+ $log.info "Case total entry include reply #{cases.total_entries} page: #{page}"
117
+ end while (cases.total_entries/@per_page.to_f).ceil > page
92
118
  end
93
- save_store_file unless !@store_file
94
119
  rescue => e
95
120
  $log.error "deskcom run: #{e.message}"
96
121
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-deskcom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toru Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-02 00:00:00.000000000 Z
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler