observed-http 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZGI2ODA0ZmI1YzJlZTRlMjZjMTQ1M2ZjMDQ0ZTgxOWY2OWY5ZWViMw==
5
+ data.tar.gz: !binary |-
6
+ ZmY0MGMzZTRiYTljMjQzZjg0NjgzZTY1ZTdkN2UzMGQ3ODM5NDAyZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YzdiMmVlNjExYmY2NDQ4ZmViOTI3NzEwODFjMGI5NzFiYTA1MTBmZThiNzQ4
10
+ ODk4MzdiNzI0NTlmM2IzNWYxNDVkY2MzNjQzMWEzNGI0MTk1OWE3YTZhM2Zk
11
+ YjJhNjBmMGQxYWIwZmQ1MmQwODExMTk0OTc3YmNiZDkwNjgyYjY=
12
+ data.tar.gz: !binary |-
13
+ NzUyNTViNzE0ZGI2MjU1OTMxNmI4NjYxNzhkNjhmNzljNmUxOWZjYjI3YTI5
14
+ YjkyM2Q2NTY3ZTNiNTc1NjA4Y2YzYmFjNzBkZjQwNjYwNjJlZWIxNDg2YjM4
15
+ YTcxMDY2NTdlOGU3ZWU5MmY2NzE1NDFjZGQ4MGVkZThiZjM1MzY=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in observed-http.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 GREE, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Observed::Http
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'observed-http'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install observed-http
18
+
19
+ ## Test
20
+
21
+ $ gem build observed.gemspec
22
+ $ gem install observed
23
+ $ cd plugins/observed-http
24
+ $ bundle install
25
+ $ bundle exec rspec
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ Feature: Observe Web services via HTTP
2
+
3
+ In order to observe Web services using Observed,
4
+ I want to the observed-http plugin to send HTTP request and report the result via reporters
5
+
6
+ Scenario: Create a .rb file containing Observed code and run it with the ruby command
7
+ Given a file named "test.rb" with:
8
+ """
9
+ require 'observed'
10
+ require 'observed/http'
11
+
12
+ include Observed
13
+
14
+ observe 'foo_1', via: 'http', with: {
15
+ method: 'get',
16
+ url: 'http://google.com',
17
+ timeout_in_milliseconds: 1000
18
+ }
19
+
20
+ report /foo_\d+/, via: 'stdout'
21
+
22
+ run 'foo_1'
23
+ """
24
+ When I run `ruby test.rb`
25
+ Then the output should contain:
26
+ """
27
+ foo_1.success
28
+ """
29
+ Then the output should contain:
30
+ """
31
+ Get http://google.com
32
+ """
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'aruba/cucumber'
3
+
4
+ World(Aruba::Api)
5
+
6
+ Before do
7
+ @aruba_timeout_seconds = 20
8
+ end
@@ -0,0 +1,5 @@
1
+ module Observed
2
+ module Http
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ require 'observed/http/version'
2
+ require 'observed/observer_helpers/timer'
3
+ require 'timeout'
4
+ require 'net/http'
5
+
6
+ module Observed
7
+ module Plugins
8
+ class HTTP < Observed::Observer
9
+
10
+ include Observed::ObserverHelpers::Timer
11
+
12
+ attribute :timeout_in_milliseconds, default: 5000
13
+
14
+ attribute :method
15
+ attribute :url
16
+
17
+ def observe
18
+ logger.debug "method: #{method}, url: #{url}"
19
+
20
+ uri = URI.parse(url)
21
+
22
+ logger.debug "uri: #{uri}, uri.host: #{uri.host}, uri.port:#{uri.port}, uri.path: #{uri.path}"
23
+
24
+ http_method = method.capitalize
25
+ path = if uri.path.size == 0
26
+ '/'
27
+ else
28
+ uri.path
29
+ end
30
+ req = Net::HTTP::const_get(http_method.intern).new(path)
31
+
32
+ timeout_in_seconds = timeout_in_milliseconds / 1000.0
33
+ if timeout_in_seconds.nan?
34
+ fail "Invalid configuration on timeout: `timeout` must be a number but it was not(=#{timeout_in_seconds})"
35
+ end
36
+
37
+ time_and_report(tag: self.tag, timeout_in_seconds: timeout_in_seconds) do
38
+
39
+ logger.debug "Sending a HTTP request with the timeout of #{timeout_in_seconds} seconds"
40
+
41
+ body = Net::HTTP.start(uri.host, uri.port) {|http|
42
+ http.request(req)
43
+ }.body
44
+
45
+ logger.debug "Response body: #{body}"
46
+
47
+ "#{http_method} #{uri}"
48
+ end
49
+
50
+ end
51
+
52
+ def logger
53
+ @logger ||= Logger.new(STDOUT)
54
+ end
55
+
56
+ plugin_name 'http'
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'observed/http/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "observed-http"
8
+ spec.version = Observed::Http::VERSION
9
+ spec.authors = ["KUOKA Yusuke"]
10
+ spec.email = ["yusuke.kuoka@gree.net"]
11
+ spec.description = %q{observed-http}
12
+ spec.summary = %q{observed-http is a plugin for Observed to run health-check against Web services talking HTTP.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "observed", "~> 0.1.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "mocha"
27
+ spec.add_development_dependency "fakefs"
28
+ spec.add_development_dependency "simplecov"
29
+ spec.add_development_dependency "cucumber"
30
+ spec.add_development_dependency "aruba"
31
+ end
@@ -0,0 +1,10 @@
1
+ require 'observed/builtin_plugins'
2
+ require 'observed/http'
3
+
4
+ observe 'foo_1', via: 'http', with: {
5
+ method: 'get',
6
+ url: 'http://google.com',
7
+ timeout_in_milliseconds: 1000
8
+ }
9
+
10
+ report /foo_\d+/, via: 'stdout'
data/spec/http_spec.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ require 'observed/application/oneshot'
4
+
5
+ describe Observed::Application::Oneshot do
6
+ subject {
7
+ Observed::Application::Oneshot.create(
8
+ config_file: 'spec/fixtures/observed.conf'
9
+ )
10
+ }
11
+ it 'initializes' do
12
+ expect(subject.run.size).not_to eq(0)
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ require 'fakefs/spec_helpers'
2
+ require 'rspec'
3
+
4
+ Dir["#{File.expand_path('..', __FILE__)}/support/**/*.rb"].each { |f| require f }
5
+
6
+ puts "Please do not update/create files while tests are running."
7
+
8
+ RSpec.configure do |config|
9
+ config.color_enabled = true
10
+ config.order = :random
11
+ config.filter_run :focus => true
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+
15
+ config.before(:each) do
16
+ @fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__))
17
+ end
18
+
19
+ config.mock_framework = :mocha
20
+ end
21
+
22
+ if RUBY_VERSION =~ /^1.9/
23
+ require 'simplecov'
24
+ SimpleCov.start
25
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: observed-http
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - KUOKA Yusuke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: observed
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fakefs
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: cucumber
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: aruba
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: observed-http
140
+ email:
141
+ - yusuke.kuoka@gree.net
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - Gemfile
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - features/observe_web_services_via_http.feature
152
+ - features/support/env.rb
153
+ - lib/observed/http.rb
154
+ - lib/observed/http/version.rb
155
+ - observed-http.gemspec
156
+ - spec/fixtures/observed.conf
157
+ - spec/http_spec.rb
158
+ - spec/spec_helper.rb
159
+ homepage: ''
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.0.5
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: observed-http is a plugin for Observed to run health-check against Web services
183
+ talking HTTP.
184
+ test_files:
185
+ - features/observe_web_services_via_http.feature
186
+ - features/support/env.rb
187
+ - spec/fixtures/observed.conf
188
+ - spec/http_spec.rb
189
+ - spec/spec_helper.rb