logstash-input-signalsciences 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/CHANGELOG.md +2 -0
- data/CONTRIBUTORS +10 -0
- data/DEVELOPER.md +2 -0
- data/Gemfile +3 -0
- data/LICENSE +11 -0
- data/README.md +86 -0
- data/lib/logstash/inputs/signalsciences.rb +184 -0
- data/logstash-input-signalsciences.gemspec +24 -0
- data/spec/inputs/signalsciences_spec.rb +11 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: adc669a1475396aeeb25ca851e61b8c69914ad72
|
4
|
+
data.tar.gz: e7cbaf103b9ae261b76cdc3e8488041bf85ee654
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b20bcccc6b23113c25b87e8a0d6274fc5c3c855c69c2b708e90cfe18534896686a77b66f3975125367e793d91e9be01521dc9706fcea6aacfd6c6c7338cd1b9
|
7
|
+
data.tar.gz: 4f93b2eac90ce4fa3a3fe447d9ce3b6eaf4d2bc0330da3e500b3b8609b41fe8020a86ccad1b5a1ac84d157aff00f149a0403c53ed410d70f3557001560638750
|
data/CHANGELOG.md
ADDED
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
|
+
* foospidy - foospidy@users.noreply.github.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.
|
data/DEVELOPER.md
ADDED
data/Gemfile
ADDED
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,184 @@
|
|
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 "json"
|
7
|
+
require "date"
|
8
|
+
|
9
|
+
# Fetch Signal Sciences request data.
|
10
|
+
#
|
11
|
+
|
12
|
+
class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
|
13
|
+
config_name "signalsciences"
|
14
|
+
|
15
|
+
# If undefined, Logstash will complain, even if codec is unused.
|
16
|
+
default :codec, "json"
|
17
|
+
|
18
|
+
# Configurable variables
|
19
|
+
# Signal Sciences API account username.
|
20
|
+
config :email, :validate => :string, :default => "nobody@signalsciences.com"
|
21
|
+
# Signal Sciences API password.
|
22
|
+
config :password, :validate => :string, :default => "nobody"
|
23
|
+
# Corp and site to pull data from.
|
24
|
+
config :corp, :validate => :string, :default => "not_provided"
|
25
|
+
config :site, :validate => :string, :default => "not_provided"
|
26
|
+
# Number of seconds in the past to filter data on
|
27
|
+
# This value will also be used to set the interval at which the API is polled.
|
28
|
+
config :from, :validate => :number, :default => 600
|
29
|
+
config :debug, :validate => :boolean, :default => false
|
30
|
+
|
31
|
+
# Set how frequently messages should be sent.
|
32
|
+
#
|
33
|
+
# The default, `600`, means fetch data every 10 minutes.
|
34
|
+
config :interval, :validate => :number, :default => 600
|
35
|
+
|
36
|
+
public
|
37
|
+
def register
|
38
|
+
@host = Socket.gethostname
|
39
|
+
@http = Net::HTTP.new('dashboard.signalsciences.net', 443)
|
40
|
+
@http.set_debug_output($stdout) if @debug
|
41
|
+
@login = Net::HTTP::Post.new("/api/v0/auth")
|
42
|
+
@get = Net::HTTP::Get.new("/api/v0/corps/#{@corp}/sites/#{@site}/feed/requests")
|
43
|
+
@http.use_ssl = true
|
44
|
+
|
45
|
+
# check if from value is 5 minutes or less
|
46
|
+
if @from <= 300
|
47
|
+
@logger.warn("from value is 5 minutes or less, increasing from value to 10 minutes.")
|
48
|
+
@from = 600
|
49
|
+
end
|
50
|
+
|
51
|
+
# check if from value is greater than 24 hours
|
52
|
+
if @from > 86400
|
53
|
+
@logger.warn("from value is greater than 24 hours, reducing from value to 24 hours.")
|
54
|
+
@from = 86400
|
55
|
+
end
|
56
|
+
|
57
|
+
# set interval to value of from @from minus one minute
|
58
|
+
interval = @from
|
59
|
+
|
60
|
+
@logger.info("Fetching Signal Sciences request data every #{interval / 60} minutes.")
|
61
|
+
end # def register
|
62
|
+
|
63
|
+
def run(queue)
|
64
|
+
# we can abort the loop if stop? becomes true
|
65
|
+
while !stop?
|
66
|
+
@login.body = URI.encode_www_form({"email" => @email, "password" => @password})
|
67
|
+
|
68
|
+
if fetch(queue)
|
69
|
+
@logger.info("Requests feed retreived successfully.")
|
70
|
+
end
|
71
|
+
|
72
|
+
# because the sleep interval can be big, when shutdown happens
|
73
|
+
# we want to be able to abort the sleep
|
74
|
+
# Stud.stoppable_sleep will frequently evaluate the given block
|
75
|
+
# and abort the sleep(@interval) if the return value is true
|
76
|
+
#Stud.stoppable_sleep(@interval) { stop? }
|
77
|
+
Stud.stoppable_sleep(@interval) { stop? }
|
78
|
+
end # loop
|
79
|
+
end # def run
|
80
|
+
|
81
|
+
def fetch(queue)
|
82
|
+
begin
|
83
|
+
response = @http.request(@login)
|
84
|
+
rescue
|
85
|
+
@logger.warn("Could not reach API endpoint to login!")
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
|
89
|
+
json = JSON.parse(response.body)
|
90
|
+
|
91
|
+
if json.has_key? "message"
|
92
|
+
# failed to login
|
93
|
+
@logger.warn("login: #{json['message']}")
|
94
|
+
return false
|
95
|
+
|
96
|
+
else
|
97
|
+
token = json['token']
|
98
|
+
# Both the from and until parameters must fall on full minute boundaries,
|
99
|
+
# see https://docs.signalsciences.net/faq/extract-your-data/.
|
100
|
+
t = Time.now.strftime("%Y-%m-%d %H:%M:0")
|
101
|
+
dt = DateTime.parse(t)
|
102
|
+
timestamp_until = dt.to_time.to_i - 300 # now - 5 minutes
|
103
|
+
timestamp_from = (timestamp_until - @from) - 300 # @from - 5 minutes
|
104
|
+
|
105
|
+
# Set up iniital get request and initial next_uri
|
106
|
+
get = Net::HTTP::Get.new("/api/v0/corps/#{@corp}/sites/#{@site}/feed/requests?from=#{timestamp_from}&until=#{timestamp_until}")
|
107
|
+
next_uri = "not empty on first pass"
|
108
|
+
|
109
|
+
# Loop through results until next_uri is empty.
|
110
|
+
while !next_uri.empty?
|
111
|
+
get["Authorization"] = "Bearer #{token}"
|
112
|
+
|
113
|
+
begin
|
114
|
+
response = @http.request(get)
|
115
|
+
rescue
|
116
|
+
@logger.warn("Could not reach API endpoint to retreive reqeusts feed!")
|
117
|
+
return false
|
118
|
+
end
|
119
|
+
json = JSON.parse(response.body)
|
120
|
+
|
121
|
+
#check for message, error, e.g. missing query string parameter
|
122
|
+
if json.has_key? "message"
|
123
|
+
# some error occured, report it.
|
124
|
+
@logger.warn("get: #{json['message']} #{token}")
|
125
|
+
return false
|
126
|
+
|
127
|
+
else
|
128
|
+
# log json payloads
|
129
|
+
json['data'].each do |payload|
|
130
|
+
|
131
|
+
# explode headersIn out to headerIn entries
|
132
|
+
temp = {}
|
133
|
+
begin
|
134
|
+
payload['headersIn'].each { |k,v| temp[k] = v }
|
135
|
+
payload["headerIn"] = temp
|
136
|
+
rescue NoMethodError
|
137
|
+
@logger.info("payload['headersIn'] is empty for id #{payload['id']}, skipping append.")
|
138
|
+
end
|
139
|
+
|
140
|
+
# explode headersOut out to headerOut entries
|
141
|
+
temp = {}
|
142
|
+
begin
|
143
|
+
payload['headersOut'].each { |k,v| temp[k] = v }
|
144
|
+
payload["headerOut"] = temp
|
145
|
+
rescue NoMethodError
|
146
|
+
@logger.info("payload['headersOut'] is empty for id #{payload['id']}, skipping append.")
|
147
|
+
end
|
148
|
+
|
149
|
+
# explode tags out to tag entries
|
150
|
+
temp = {}
|
151
|
+
payload['tags'].each do |x|
|
152
|
+
temp[x['type']] = x
|
153
|
+
end
|
154
|
+
payload['tag'] = temp
|
155
|
+
|
156
|
+
# add the event
|
157
|
+
event = LogStash::Event.new("message" => payload, "host" => @host)
|
158
|
+
|
159
|
+
decorate(event)
|
160
|
+
queue << event
|
161
|
+
end
|
162
|
+
|
163
|
+
# get the next uri value
|
164
|
+
next_uri = json['next']['uri']
|
165
|
+
|
166
|
+
# continue retreiving next_uri if it exists
|
167
|
+
if !next_uri.empty?
|
168
|
+
get = Net::HTTP::Get.new(next_uri)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
return true
|
175
|
+
end
|
176
|
+
|
177
|
+
def stop
|
178
|
+
# nothing to do in this case so it is not necessary to define stop
|
179
|
+
# examples of common "stop" tasks:
|
180
|
+
# * close sockets (unblocking blocking reads/accepts)
|
181
|
+
# * cleanup temporary files
|
182
|
+
# * terminate spawned threads
|
183
|
+
end
|
184
|
+
end # class LogStash::Inputs::Signalsciences
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-input-signalsciences'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.licenses = ['Apache-2.0']
|
5
|
+
s.summary = 'Logstash input plugin for Signal Sciences.'
|
6
|
+
s.description = 'Logstash input plugin for the Signal Sciences request feed endpoint https://docs.signalsciences.net/api/#get-request-feed'
|
7
|
+
s.homepage = 'https://github.com/foospidy'
|
8
|
+
s.authors = ['foospidy']
|
9
|
+
s.email = 'foospidy@users.noreply.github.com'
|
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 'stud', '~> 0.0', '>= 0.0.22'
|
23
|
+
s.add_development_dependency 'logstash-devutils', '~> 0.0', '>= 0.0.16'
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require "logstash/inputs/signalsciences"
|
4
|
+
|
5
|
+
describe LogStash::Inputs::signalsciences do
|
6
|
+
|
7
|
+
it_behaves_like "an interruptible input plugin" do
|
8
|
+
let(:config) { { "interval" => 600 } }
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-input-signalsciences
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- foospidy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core-plugin-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
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
|
+
name: stud
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.0.22
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.0.22
|
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.0'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.0.16
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0.0'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.0.16
|
67
|
+
description: Logstash input plugin for the Signal Sciences request feed endpoint https://docs.signalsciences.net/api/#get-request-feed
|
68
|
+
email: foospidy@users.noreply.github.com
|
69
|
+
executables: []
|
70
|
+
extensions: []
|
71
|
+
extra_rdoc_files: []
|
72
|
+
files:
|
73
|
+
- CHANGELOG.md
|
74
|
+
- CONTRIBUTORS
|
75
|
+
- DEVELOPER.md
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- lib/logstash/inputs/signalsciences.rb
|
80
|
+
- logstash-input-signalsciences.gemspec
|
81
|
+
- spec/inputs/signalsciences_spec.rb
|
82
|
+
homepage: https://github.com/foospidy
|
83
|
+
licenses:
|
84
|
+
- Apache-2.0
|
85
|
+
metadata:
|
86
|
+
logstash_plugin: 'true'
|
87
|
+
logstash_group: input
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.5.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Logstash input plugin for Signal Sciences.
|
108
|
+
test_files:
|
109
|
+
- spec/inputs/signalsciences_spec.rb
|