logstash-input-intercom 0.0.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +4 -0
- data/LICENSE +13 -0
- data/README.md +98 -0
- data/lib/logstash/inputs/intercom.rb +156 -0
- data/logstash-input-intercom.gemspec +28 -0
- data/spec/inputs/intercom_spec.rb +9 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 232dd14453ab0a06312dde7fa09bc9e240ecba21
|
4
|
+
data.tar.gz: 9292b28e6cdbce588c7728fc49afb7064eb027dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 04cd065ec0897f3d1718c0cb21996c0be34429a36e1124347dc93da9ccb963f7117c9a062ba70a983fcd8790d88d85fa4b810d7e827dd1f78ac71a3ca4848c28
|
7
|
+
data.tar.gz: 0ed59beed7fc3379c666a43c0b9d152b7769a8ca55b20ea1b4166fa1961ad3b9e35ace992afb5b1f917d6793c3738c19d65325b7ced29d1eaadb70d8f13a62de
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
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/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
[](https://travis-ci.org/logstash-plugins/logstash-input-intercom)
|
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,156 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/inputs/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require "logstash/timestamp"
|
5
|
+
require "logstash/util"
|
6
|
+
require "intercom"
|
7
|
+
|
8
|
+
# This plugin was created as a way to ingest data from Intercom into Logstash.
|
9
|
+
#
|
10
|
+
# ==== Usage:
|
11
|
+
#
|
12
|
+
# Here is an example of setting up the plugin to fetch data from Intercom.
|
13
|
+
#
|
14
|
+
# [source,ruby]
|
15
|
+
# ----------------------------------
|
16
|
+
# input {
|
17
|
+
# intercom {
|
18
|
+
# app_id => ":appId"
|
19
|
+
# app_api_key => ":appApiKey"
|
20
|
+
# }
|
21
|
+
# }
|
22
|
+
# ----------------------------------
|
23
|
+
#
|
24
|
+
class LogStash::Inputs::Intercom < LogStash::Inputs::Base
|
25
|
+
config_name "intercom"
|
26
|
+
|
27
|
+
# If undefined, Logstash will complain, even if codec is unused.
|
28
|
+
default :codec, "plain"
|
29
|
+
|
30
|
+
# Application ID
|
31
|
+
config :app_id, :validate => :string
|
32
|
+
|
33
|
+
# Application API Key
|
34
|
+
config :app_api_key, :validate => :string
|
35
|
+
|
36
|
+
# Set if we want to synchronize events
|
37
|
+
config :sync_events, :validate => :boolean, :default => true
|
38
|
+
|
39
|
+
#Set if we want to synchronize users
|
40
|
+
config :sync_users, :validate => :boolean, :default => true
|
41
|
+
|
42
|
+
public
|
43
|
+
|
44
|
+
def register
|
45
|
+
configure_intercom_client
|
46
|
+
end # def register
|
47
|
+
|
48
|
+
def run(queue)
|
49
|
+
sync_all(queue)
|
50
|
+
end # def run
|
51
|
+
|
52
|
+
def stop
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def configure_intercom_client
|
58
|
+
Intercom.app_id = @app_id
|
59
|
+
Intercom.app_api_key = @app_api_key
|
60
|
+
end
|
61
|
+
|
62
|
+
def sync_all(queue)
|
63
|
+
sync_users queue if @sync_users
|
64
|
+
sync_events queue if @sync_events
|
65
|
+
end
|
66
|
+
|
67
|
+
def sync_users(queue)
|
68
|
+
begin
|
69
|
+
get_users.each { |user| push_event queue, from_user(user) }
|
70
|
+
rescue Intercom::IntercomError => error
|
71
|
+
@logger.error? @logger.error("Failed to sync users", :error => error.to_s)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def sync_events(queue)
|
76
|
+
begin
|
77
|
+
get_users.each { |user| sync_events_for queue, user.id }
|
78
|
+
rescue Intercom::IntercomError => error
|
79
|
+
@logger.error? @logger.error("Failed to sync events", :error => error.to_s)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def sync_events_for(queue, intercom_user_id)
|
84
|
+
begin
|
85
|
+
get_events(intercom_user_id).each { |event| push_event queue, from_event(event) }
|
86
|
+
rescue Intercom::IntercomError => error
|
87
|
+
@logger.error? @logger.error("Failed to sync events for user", :intercom_user_id => intercom_user_id, :error => error.to_s)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_users
|
92
|
+
Intercom::User.all
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_events(intercom_user_id)
|
96
|
+
Intercom::Event.find_all(:type => 'user', :intercom_user_id => intercom_user_id)
|
97
|
+
end
|
98
|
+
|
99
|
+
def from_user(intercom_user)
|
100
|
+
hash = intercom_object_to_hash intercom_user, 'user'
|
101
|
+
hash_to_logstash_event hash, intercom_user.created_at
|
102
|
+
end
|
103
|
+
|
104
|
+
def from_event(intercom_event)
|
105
|
+
hash = intercom_object_to_hash intercom_event, 'event'
|
106
|
+
hash_to_logstash_event hash, intercom_event.created_at
|
107
|
+
end
|
108
|
+
|
109
|
+
def hash_to_logstash_event(hash, timestamp)
|
110
|
+
event = LogStash::Event.new LogStash::Util.stringify_symbols(hash)
|
111
|
+
event.timestamp = LogStash::Timestamp.new timestamp
|
112
|
+
event
|
113
|
+
end
|
114
|
+
|
115
|
+
def intercom_object_to_hash(intercom_object, type)
|
116
|
+
# flatten object
|
117
|
+
hash = flatten_hash intercom_object.to_hash
|
118
|
+
|
119
|
+
# prefix all keys by the object type (avoid collision between fields names)
|
120
|
+
hash = prefix_keys hash, "#{type}_"
|
121
|
+
|
122
|
+
# adds identity
|
123
|
+
hash['type'] = type
|
124
|
+
hash['document_id'] = "#{type}_#{intercom_object.id}"
|
125
|
+
|
126
|
+
hash
|
127
|
+
end
|
128
|
+
|
129
|
+
def prefix_keys(hash, prefix)
|
130
|
+
hash.each_with_object({}) do |(k, v), h|
|
131
|
+
if k.start_with? prefix
|
132
|
+
h[k] = v
|
133
|
+
else
|
134
|
+
h["#{prefix}#{k}"] = v
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def flatten_hash(hash)
|
140
|
+
hash.each_with_object({}) do |(k, v), h|
|
141
|
+
if v.respond_to? :to_hash
|
142
|
+
flatten_hash(v.to_hash).map do |h_k, h_v|
|
143
|
+
h["#{k}_#{h_k}"] = h_v
|
144
|
+
end
|
145
|
+
else
|
146
|
+
h[k] = v
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def push_event(queue, event)
|
152
|
+
decorate(event)
|
153
|
+
queue << event
|
154
|
+
end
|
155
|
+
|
156
|
+
end # class LogStash::Inputs::Intercom
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-input-intercom'
|
4
|
+
s.version = '0.0.1'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "Experimental Logstash input plugin for Intercom API."
|
7
|
+
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"
|
8
|
+
s.authors = ["Cogniteev"]
|
9
|
+
s.email = 'techteam@cogniteev.com'
|
10
|
+
s.homepage = 'https://github.com/cogniteev/logstash-input-intercom'
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
s.platform = "java"
|
13
|
+
|
14
|
+
# Files
|
15
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','Gemfile','LICENSE']
|
16
|
+
|
17
|
+
# Tests
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
|
20
|
+
# Special flag to let us know this is actually a logstash plugin
|
21
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
|
22
|
+
|
23
|
+
# Gem dependencies
|
24
|
+
s.add_runtime_dependency 'logstash-core-plugin-api', '~> 1.0'
|
25
|
+
s.add_runtime_dependency 'logstash-codec-plain'
|
26
|
+
s.add_runtime_dependency 'cogniteev-intercom', '~> 2.3'
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-input-intercom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Cogniteev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-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: '1.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: '1.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: '2.3'
|
47
|
+
name: cogniteev-intercom
|
48
|
+
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
55
|
+
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
|
56
|
+
email: techteam@cogniteev.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- CHANGELOG.md
|
62
|
+
- Gemfile
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- lib/logstash/inputs/intercom.rb
|
66
|
+
- logstash-input-intercom.gemspec
|
67
|
+
- spec/inputs/intercom_spec.rb
|
68
|
+
homepage: https://github.com/cogniteev/logstash-input-intercom
|
69
|
+
licenses:
|
70
|
+
- Apache License (2.0)
|
71
|
+
metadata:
|
72
|
+
logstash_plugin: 'true'
|
73
|
+
logstash_group: input
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.4.8
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Experimental Logstash input plugin for Intercom API.
|
94
|
+
test_files:
|
95
|
+
- spec/inputs/intercom_spec.rb
|