logstash-input-signalsciences 0.1.1 → 0.2.0

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: 7677c8fd764c77486906ebebb98b7d95a5d5d557
4
- data.tar.gz: dc4601ef183dde9d4b8d4014d6cd0a06732b6b09
3
+ metadata.gz: 62c7c90326f3b048fd6059c9b97067b8033ec918
4
+ data.tar.gz: 0fd2c6793585ba90130075bfad296a01339f1611
5
5
  SHA512:
6
- metadata.gz: 20b7b7971d2f708fbfa0f866f80851770eba97c77e00176135ea4f1b2de098d598d587b3254cc4ed93ac2076aa37f26575c819d8176e3360c0623e9305774101
7
- data.tar.gz: 7fccc04bca6c78d89918f8b16c1fb456c0c5d66ecc9ee1d5e993d301e1e892a991d815ef64537c9306fb92c3ad96cfb5c98eb3b2546607ab534066b5df32d714
6
+ metadata.gz: cc4c953e8386b244b09d6797f814036ed410442456269292ec7dad0ad5652ea0294ef089071d76a664dcaaf2cbe1dee1fed1440848db75e8d445545c5a7be911
7
+ data.tar.gz: 500b60c32af0408b6e51e87ef0d2346e6aaeace213b447e5a38e4576a7d7a8611e380ed41a3019ea0868a69eee7961fcde680867304c2471c385cf0954cdddc8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
+ ## 0.2.0
2
+
3
+ - Changed time to UTC
4
+ - Changed default from value to 5 min
5
+ - Updated from value to allow for pulling data every 1 min
6
+ - Added additional logging for debug
7
+
1
8
  ## 0.1.1
2
- - Fixed references to vulnerable dependencieas in Gemfile.lock
9
+
10
+ - Fixed references to vulnerable dependencieas in Gemfile.lock
3
11
 
4
12
  ## 0.1.0
5
- - Plugin created with the logstash plugin generator
13
+
14
+ - Plugin created with the logstash plugin generator
data/INSTRUCTIONS.md CHANGED
@@ -8,7 +8,7 @@ There are two methods of installing this plugin.
8
8
 
9
9
  1. The plugin is published on rubygems.org (https://rubygems.org/gems/logstash-input-signalsciences) so it can be easily installed via Logstash by using the following command:
10
10
 
11
- `logstash-plugin install logstash-input-signalciences`
11
+ `logstash-plugin install logstash-input-signalsciences`
12
12
 
13
13
  2. You can build and install the gem file locally by using the `Makefile` on your system. However, you will need to ensure Ruby requirements for building gem files are met. Use the following commands:
14
14
 
@@ -29,7 +29,7 @@ you can also refer to Elasticsearch's getting started page: https://www.elastic.
29
29
 
30
30
  1. The first requirement is Java 8, run:
31
31
 
32
- ```
32
+ ```shell
33
33
  brew update
34
34
  brew tap caskroom/versions
35
35
  brew cask install java8
@@ -39,7 +39,7 @@ Reference https://stackoverflow.com/questions/24342886/how-to-install-java-8-on-
39
39
 
40
40
  2. Next install Elasticsearch, Logstash, and Kibana, run:
41
41
 
42
- ```
42
+ ```shell
43
43
  brew install elasticsearch
44
44
  brew install logstash
45
45
  brew install kibana
@@ -47,7 +47,7 @@ brew install kibana
47
47
 
48
48
  With brew you can start/stop these services by running:
49
49
 
50
- ```
50
+ ```shell
51
51
  brew services start elasticsearch
52
52
  brew services start logstash
53
53
  brew services start kibana
@@ -67,4 +67,4 @@ If you want to create a new plugin, see:
67
67
 
68
68
  1. Plugin generator https://www.elastic.co/guide/en/logstash/current/plugins-inputs-generator.html, usage: https://github.com/elastic/logstash/blob/master/docs/static/plugin-generator.asciidoc
69
69
 
70
- 2. Submitting your plugin to [RubyGems.org and the Logstash-plugin repository] (https://www.elastic.co/guide/en/logstash/current/submitting-plugin.html).
70
+ 2. Submitting your plugin to [RubyGems.org and the Logstash-plugin repository](https://www.elastic.co/guide/en/logstash/current/submitting-plugin.html).
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Logstash Input Plugin for Signal Sciences
2
2
 
3
+ For more detail on using the Signal Sciences logstash plugin, see [instructions](INSTRUCTIONS.md).
4
+
3
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
6
 
5
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.
@@ -25,12 +25,9 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
25
25
  config :site, :validate => :string, :default => "not_provided"
26
26
  # Number of seconds in the past to filter data on
27
27
  # This value will also be used to set the interval at which the API is polled.
28
- config :from, :validate => :number, :default => 600
28
+ config :from, :validate => :number, :default => 300
29
29
  # Debug for plugin development.
30
30
  config :debug, :validate => :boolean, :default => false
31
-
32
- # Set how frequently messages should be sent.
33
- #
34
31
  # The default, `600`, means fetch data every 10 minutes.
35
32
  config :interval, :validate => :number, :default => 600
36
33
 
@@ -43,10 +40,10 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
43
40
  @get = Net::HTTP::Get.new("/api/v0/corps/#{@corp}/sites/#{@site}/feed/requests")
44
41
  @http.use_ssl = true
45
42
 
46
- # check if from value is 5 minutes or less
47
- if @from <= 300
48
- @logger.warn("from value is 5 minutes or less, increasing from value to 10 minutes.")
49
- @from = 600
43
+ # check if from value is less than 1 min
44
+ if @from < 60
45
+ @logger.warn("from value is less than 1 min, increasing from value to 1 minute.")
46
+ @from = 60
50
47
  end
51
48
 
52
49
  # check if from value is greater than 24 hours
@@ -55,10 +52,10 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
55
52
  @from = 86400
56
53
  end
57
54
 
58
- # set interval to value of from @from minus one minute
59
- interval = @from
55
+ # set interval to value of from @from minus five minutes
56
+ @interval = @from
60
57
 
61
- @logger.info("Fetching Signal Sciences request data every #{interval / 60} minutes.")
58
+ @logger.info("Fetching Signal Sciences request data every #{@interval / 60} minutes.")
62
59
  end # def register
63
60
 
64
61
  def run(queue)
@@ -68,6 +65,8 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
68
65
 
69
66
  if fetch(queue)
70
67
  @logger.info("Requests feed retreived successfully.")
68
+ else
69
+ @logger.warn("Problem retreiving request!")
71
70
  end
72
71
 
73
72
  # because the sleep interval can be big, when shutdown happens
@@ -75,6 +74,7 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
75
74
  # Stud.stoppable_sleep will frequently evaluate the given block
76
75
  # and abort the sleep(@interval) if the return value is true
77
76
  #Stud.stoppable_sleep(@interval) { stop? }
77
+ @logger.info("Sleep #{@interval}")
78
78
  Stud.stoppable_sleep(@interval) { stop? }
79
79
  end # loop
80
80
  end # def run
@@ -82,6 +82,7 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
82
82
  def fetch(queue)
83
83
  begin
84
84
  response = @http.request(@login)
85
+ @logger.warn("login response: #{response.code}")
85
86
  rescue
86
87
  @logger.warn("Could not reach API endpoint to login!")
87
88
  return false
@@ -98,12 +99,19 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
98
99
  token = json['token']
99
100
  # Both the from and until parameters must fall on full minute boundaries,
100
101
  # see https://docs.signalsciences.net/faq/extract-your-data/.
101
- t = Time.now.strftime("%Y-%m-%d %H:%M:0")
102
+ t = Time.now.utc.strftime("%Y-%m-%d %H:%M:0")
102
103
  dt = DateTime.parse(t)
103
104
  timestamp_until = dt.to_time.to_i - 300 # now - 5 minutes
104
- timestamp_from = (timestamp_until - @from) - 300 # @from - 5 minutes
105
+ timestamp_from = (timestamp_until - @from) # @until - @from
106
+
107
+ if @debug
108
+ hfrom = Time.at(timestamp_from).to_datetime
109
+ huntil = Time.at(timestamp_until).to_datetime
110
+ @logger.info("From #{hfrom} Until #{huntil}")
111
+ end
105
112
 
106
113
  # Set up iniital get request and initial next_uri
114
+ @logger.info("Requesting data: /api/v0/corps/#{@corp}/sites/#{@site}/feed/requests?from=#{timestamp_from}&until=#{timestamp_until}")
107
115
  get = Net::HTTP::Get.new("/api/v0/corps/#{@corp}/sites/#{@site}/feed/requests?from=#{timestamp_from}&until=#{timestamp_until}")
108
116
  next_uri = "not empty on first pass"
109
117
 
@@ -122,7 +130,7 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
122
130
  #check for message, error, e.g. missing query string parameter
123
131
  if json.has_key? "message"
124
132
  # some error occured, report it.
125
- @logger.warn("get: #{json['message']} #{token}")
133
+ @logger.warn("Error accessing API (#{token}), status code: #{response.code} with message: #{json['message']}")
126
134
  return false
127
135
 
128
136
  else
@@ -135,7 +143,9 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
135
143
  payload['headersIn'].each { |k,v| temp[k] = v }
136
144
  payload["headerIn"] = temp
137
145
  rescue NoMethodError
138
- @logger.info("payload['headersIn'] is empty for id #{payload['id']}, skipping append.")
146
+ if @debug
147
+ @logger.debug("payload['headersIn'] is empty for id #{payload['id']}, skipping append.")
148
+ end
139
149
  end
140
150
 
141
151
  # explode headersOut out to headerOut entries
@@ -144,7 +154,9 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
144
154
  payload['headersOut'].each { |k,v| temp[k] = v }
145
155
  payload["headerOut"] = temp
146
156
  rescue NoMethodError
147
- @logger.info("payload['headersOut'] is empty for id #{payload['id']}, skipping append.")
157
+ if @debug
158
+ @logger.info("payload['headersOut'] is empty for id #{payload['id']}, skipping append.")
159
+ end
148
160
  end
149
161
 
150
162
  # explode tags out to tag entries
@@ -155,6 +167,7 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
155
167
  payload['tag'] = temp
156
168
 
157
169
  # add the event
170
+
158
171
  event = LogStash::Event.new("message" => payload, "host" => @host)
159
172
 
160
173
  decorate(event)
@@ -163,6 +176,9 @@ class LogStash::Inputs::Signalsciences < LogStash::Inputs::Base
163
176
 
164
177
  # get the next uri value
165
178
  next_uri = json['next']['uri']
179
+ if @debug
180
+ logger.info("Next URI: #{next_uri}")
181
+ end
166
182
 
167
183
  # continue retreiving next_uri if it exists
168
184
  if !next_uri.empty?
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-signalsciences'
3
- s.version = '0.1.1'
3
+ s.version = '0.2.0'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = 'Logstash input plugin for Signal Sciences.'
6
6
  s.description = 'Logstash input plugin for the Signal Sciences request feed endpoint https://docs.signalsciences.net/api/#get-request-feed'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-signalsciences
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - foospidy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-25 00:00:00.000000000 Z
11
+ date: 2020-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core-plugin-api
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  version: '0'
102
102
  requirements: []
103
103
  rubyforge_project:
104
- rubygems_version: 2.5.2
104
+ rubygems_version: 2.6.14
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: Logstash input plugin for Signal Sciences.