logstash-input-httpclient 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dfffe002abaff65c15fae28f60bdb26c96a49296
4
+ data.tar.gz: a0ccb1d87c692aa0a408d1565000a7f758fc28d6
5
+ SHA512:
6
+ metadata.gz: a2d781b3211acb8ccf50e73c1fa8d64fc3edcd8e15d176df3f1787c5596277a3e8cdad396cafb82129858715742709b623284191f670475ca596ca779290bf6e
7
+ data.tar.gz: 41cf27bfe287f24232626b2ee3d82a3a63f53adb5d0dcba29ea836b1e87a4a3254ecbfa978ba60d5f52b13f9df386a652aa330ca9d526be949efac2ef9c3adaf
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ Gemfile.bak
4
+ .bundle
5
+ vendor
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "logstash", :github => "elastic/logstash", :branch => "1.4"
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2015 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,28 @@
1
+ # Logstash HTTP Client Input 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
+ This plugin will open up a http keep-alive connection to any http server and periodically execute GET requests. The response body will be added to the `message` field of the logstash event.
10
+
11
+ This plugin also adds a `X-Logstash-Avg-Queue-Secs` header to every GET request. This indicates the average amount of "wait time" an event is waiting to be added to logstash's intenal bounded/blocking input queue. The server could use this value to determine how many events to send to logstash based on the throughput/wait time.
12
+
13
+ ## Installing
14
+ `{logstash_dir}/bin/plugin install logstash-input-httpclient`
15
+
16
+ ## Need Help?
17
+
18
+ Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
19
+
20
+ ## Contributing
21
+
22
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
23
+
24
+ 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.
25
+
26
+ It is more important to the community that you are able to contribute.
27
+
28
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rake"
@@ -0,0 +1,110 @@
1
+ # encoding: utf-8
2
+ require "logstash/inputs/base"
3
+ require "logstash/namespace"
4
+ require "stud/interval"
5
+ require "net/http"
6
+
7
+ # Query a http server with GET requests at a regular interval.
8
+ #
9
+ #[%hardbreaks]
10
+ # HTTP GET requests are performed using the provided url (which may contain URL parameters).
11
+ # The HTTP Response body will be added to "message" after being decoded by the provided codec.
12
+ # There is an additional header named `X-Logstash-Avg-Queue-Secs` added to each HTTP request. This is the
13
+ # average seconds it took for the past 20 events to be accepted by Logstash's bounded input queue.
14
+ # The HTTP server could use this as a indication of how many events the Logstash instance is able to process (throughput).
15
+
16
+
17
+ class LogStash::Inputs::HttpClient < LogStash::Inputs::Base
18
+ config_name "httpclient"
19
+
20
+ # If undefined, Logstash will complain, even if codec is unused.
21
+ default :codec, "plain"
22
+
23
+ #[%hardbreaks]
24
+ # The full url to execute GET requests on.
25
+ # It may contain URL parameters (you are responsible for URL encoding them)
26
+ # e.g. `https://mywebservice.int/`
27
+ # e.g. `http://mywebservice.int?queue=logstash_events&numevents=10`
28
+ #
29
+ # IMPORTANT: make sure you end with a slash (if not using url params). `http://mywebservice.int` is not valid, it must be `http://myswebservice.int/`
30
+ # todo: auto-append slash if user forgets
31
+ config :url, :validate => :string, :required => true
32
+
33
+ # Set how frequently we should query the url for messages
34
+ #
35
+ # The default, `10`, means send a message every 10 seconds.
36
+ config :interval, :validate => :number, :default => 10
37
+
38
+ # The name of the object that http response meta-data (headers, response code, etc) should be added to.
39
+ config :response_object_name, :validate => :string, :default => "http_response"
40
+
41
+ # Should the http headers be added to the `response_object_name`?
42
+ #
43
+ # If true, there will be a "headers" with all the response headers/values.
44
+ config :include_response_headers, :validate => :boolean, :default => false
45
+
46
+ # Should the http response code be added to the `response_object_name`?
47
+ #
48
+ # If true, there will be a "code" with all the response headers/values.
49
+ config :include_response_code, :validate => :boolean, :default => true
50
+
51
+ # Should the http request elapsed time be added to the `response_object_name`?
52
+ #
53
+ # If true, there will be a "took_secs" with the time it took for the http request to complete
54
+ config :include_http_request_time, :validate => :boolean, :default => true
55
+
56
+ public
57
+ def register
58
+ @uri = URI(@url)
59
+ end # def register
60
+
61
+ def run(queue)
62
+ queue_times = Array.new #track an average of how long it's taking to queue events into logstash
63
+ #::start creates a connection to the HTTP server and keeps it alive for the duration
64
+ Net::HTTP.start @uri.host, @uri.port, :use_ssl => @uri.scheme == 'https' do |http|
65
+ Stud.interval(@interval) do
66
+ begin
67
+ http_start = Time.now
68
+ request = Net::HTTP::Get.new(@uri.path)
69
+ request ["X-Logstash-Avg-Queue-Secs"] = arr_avg(queue_times, 20, 3)
70
+ response = http.request request # Net::HTTPResponse object
71
+ http_elapsed = Time.now - http_start
72
+ rescue => e
73
+ @logger.warn("Http request failed, will retry", :exception => e)
74
+ @logger.warn(e.backtrace)
75
+ sleep(@interval)
76
+ retry
77
+ end
78
+ #event = LogStash::Event.new("message" => response.body)
79
+ @codec.decode(response.body) do |event|
80
+ event[@response_object_name] = {}
81
+ if @include_response_headers
82
+ event[@response_object_name]["headers"] = response
83
+ end
84
+ if @include_response_code
85
+ event[@response_object_name]["code"] = response.code
86
+ end
87
+ if @include_http_request_time
88
+ event[@response_object_name]["took_secs"] = http_elapsed
89
+ end
90
+ decorate(event)
91
+ queue_start = Time.now
92
+ queue << event
93
+ queue_elapsed = Time.now - http_start
94
+ queue_times.push queue_elapsed
95
+ end
96
+ end #interval loop
97
+ end #HTTP keepalive
98
+ end # def run
99
+
100
+ def arr_avg(arr,cutoff,precision)
101
+ if(arr.size == 0)
102
+ return 0
103
+ end
104
+ if(arr.size > cutoff)
105
+ arr.drop(arr.length-cutoff) #removes from beginning of array
106
+ end
107
+ #get the average
108
+ (arr.inject{ |sum, el| sum + el }.to_f / arr.size).round(precision)
109
+ end
110
+ end # class LogStash::Inputs::Example
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-input-httpclient'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This input queries a http url at a regular interval and sends the responses to logstash."
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 = ["bradvido"]
8
+ s.email = 'bradvido+logstash-input-httpclient@bradvido.com'
9
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = `git ls-files`.split($\)
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", '>= 1.4.0', '< 2.0.0'
22
+ s.add_runtime_dependency 'logstash-codec-plain'
23
+ s.add_runtime_dependency 'stud'
24
+ s.add_development_dependency 'logstash-devutils'
25
+ end
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-httpclient
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - bradvido
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ version_requirements: !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
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.0
28
+ - - <
29
+ - !ruby/object:Gem::Version
30
+ version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-codec-plain
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: stud
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ prerelease: false
60
+ type: :runtime
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-devutils
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ prerelease: false
74
+ type: :development
75
+ 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
76
+ email: bradvido+logstash-input-httpclient@bradvido.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - .gitignore
82
+ - Gemfile
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - lib/logstash/inputs/httpclient.rb
87
+ - logstash-input-httpclient.gemspec
88
+ - spec/inputs/httpclient_spec.rb
89
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
90
+ licenses:
91
+ - Apache License (2.0)
92
+ metadata:
93
+ logstash_plugin: 'true'
94
+ logstash_group: input
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.6
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: This input queries a http url at a regular interval and sends the responses to logstash.
115
+ test_files:
116
+ - spec/inputs/httpclient_spec.rb