http-pulse 0.0.1
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.
- data/LICENSE.md +20 -0
- data/README.md +3 -0
- data/Rakefile +43 -0
- data/bin/http-pulse +64 -0
- data/lib/http-pulse.rb +6 -0
- data/lib/http-pulse/request.rb +42 -0
- data/lib/http-pulse/response.rb +33 -0
- metadata +89 -0
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Corey Donohoe <atmos@atmos.org>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
require 'rubygems/specification'
|
3
|
+
require 'bundler'
|
4
|
+
require 'date'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
spec = Gem::Specification.new do |s|
|
8
|
+
s.name = "http-pulse"
|
9
|
+
s.version = "0.0.1"
|
10
|
+
s.author = "Corey Donohoe"
|
11
|
+
s.email = "atmos@atmos.org"
|
12
|
+
s.homepage = "http://www.atmos.org/http-pulse"
|
13
|
+
s.description = s.summary = "A gem that provides interaction with the http-pulse service"
|
14
|
+
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.extra_rdoc_files = ["README.md", "LICENSE.md"]
|
18
|
+
s.summary = "A CLI tools for http-pulse"
|
19
|
+
|
20
|
+
bundle = Bundler::Definition.from_gemfile('Gemfile')
|
21
|
+
bundle.dependencies.each do |dep|
|
22
|
+
next unless dep.groups.include?(:runtime)
|
23
|
+
s.add_dependency(dep.name, dep.version_requirements.to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
s.bindir = "bin"
|
27
|
+
s.executables = %w( http-pulse )
|
28
|
+
|
29
|
+
s.require_path = 'lib'
|
30
|
+
s.files = %w(LICENSE.md README.md Rakefile) + Dir.glob("{bin,lib}/**/*")
|
31
|
+
end
|
32
|
+
|
33
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
34
|
+
pkg.gem_spec = spec
|
35
|
+
end
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
desc "Run specs"
|
40
|
+
Spec::Rake::SpecTask.new do |t|
|
41
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
42
|
+
t.spec_opts = %w(-fs --color)
|
43
|
+
end
|
data/bin/http-pulse
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "http-pulse"
|
5
|
+
require "optparse"
|
6
|
+
|
7
|
+
options = { :environment => :production }
|
8
|
+
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: http-pulse [options]"
|
11
|
+
|
12
|
+
opts.on("--environment [environment]", [:dev],
|
13
|
+
"What environment to run against") do |action|
|
14
|
+
options[:environment] = action.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("--create [URL]", "The url to monitor") do |action|
|
18
|
+
options[:action] = :create
|
19
|
+
options[:url] = action.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on("--delete [URL]", "The url to stop monitoring") do |action|
|
23
|
+
options[:action] = :delete
|
24
|
+
options[:url] = action.to_s
|
25
|
+
end
|
26
|
+
end.parse!
|
27
|
+
|
28
|
+
begin
|
29
|
+
token = File.read(File.expand_path("~/.http-pulse"))
|
30
|
+
api = HttpPulse::Monitor.new(token.chomp, options[:environment])
|
31
|
+
case options[:action]
|
32
|
+
when :create
|
33
|
+
response = api.create(options[:url])
|
34
|
+
puts "Successfully added #{options[:url]}"
|
35
|
+
when :delete
|
36
|
+
raise ArgumentError, "Unimplemented on the server"
|
37
|
+
else
|
38
|
+
response = api.get
|
39
|
+
if response.any?
|
40
|
+
puts "Your Monitors"
|
41
|
+
puts "-" * 78
|
42
|
+
response.each do |monitor|
|
43
|
+
puts HttpPulse::Response::Monitor.new(monitor).to_s
|
44
|
+
end
|
45
|
+
else
|
46
|
+
puts "You have no monitors in place, create some!"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
rescue Errno::ECONNREFUSED => e
|
50
|
+
puts "http-pulse seems to be down ATM :("
|
51
|
+
exit(1)
|
52
|
+
rescue RestClient::ResourceNotFound => e
|
53
|
+
puts "Your token is likely invalid. :("
|
54
|
+
puts "Please visit http://http-pulse.herok.com to verify"
|
55
|
+
exit(1)
|
56
|
+
rescue => e
|
57
|
+
puts e.class.to_s
|
58
|
+
puts e.message
|
59
|
+
$stderr.puts "Please get your API token from http://http-pulse.heroku.com"
|
60
|
+
$stderr.puts "Once you have it, drop it in ~/.http-pulse"
|
61
|
+
exit(1)
|
62
|
+
end
|
63
|
+
|
64
|
+
# vim:ft=ruby
|
data/lib/http-pulse.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module HttpPulse
|
2
|
+
class RequestError < StandardError; end
|
3
|
+
class Monitor
|
4
|
+
def initialize(token, environment = :production)
|
5
|
+
raise RequestError, "Token not configured" if token.nil? || token.empty?
|
6
|
+
@token, @environment = token, environment
|
7
|
+
end
|
8
|
+
|
9
|
+
def get
|
10
|
+
response = RestClient.get(endpoint, {:accept => :json})
|
11
|
+
handle_response(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(url)
|
15
|
+
response = RestClient.post(endpoint, {:url => url}, {:content_type => :json, :accept => :json})
|
16
|
+
handle_response(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(url)
|
20
|
+
response = RestClient.delete(endpoint, {:url => url}, {:content_type => :json, :accept => :json})
|
21
|
+
handle_response(response)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def handle_response(response)
|
26
|
+
raise RequestError, response.inspect unless (200...299).include?(response.code)
|
27
|
+
JSON.parse(response.to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
def endpoint
|
31
|
+
"#{endpoint_host}/v1/#{@token}/monitors"
|
32
|
+
end
|
33
|
+
|
34
|
+
def endpoint_host
|
35
|
+
endpoints = {
|
36
|
+
:dev => 'http://localhost:9393',
|
37
|
+
:production => 'http://http-pulse.heroku.com'
|
38
|
+
}
|
39
|
+
endpoints[@environment.to_sym] || raise(ArgumentError, "Unknown Environment #{@environment}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module HttpPulse
|
2
|
+
module Response
|
3
|
+
class Monitor
|
4
|
+
def initialize(json)
|
5
|
+
@json = json
|
6
|
+
end
|
7
|
+
|
8
|
+
def url
|
9
|
+
@json['url']
|
10
|
+
end
|
11
|
+
|
12
|
+
def up?
|
13
|
+
@json['httpStatus'] == 200
|
14
|
+
end
|
15
|
+
|
16
|
+
def status
|
17
|
+
up? ? "UP" : "DOWN"
|
18
|
+
end
|
19
|
+
|
20
|
+
def checked_at
|
21
|
+
checked_at_time.strftime("%Y/%m/%d %H:%M %Z")
|
22
|
+
end
|
23
|
+
|
24
|
+
def checked_at_time
|
25
|
+
Time.parse(@json['lastChecked']).localtime
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
"%-45s %5s as of %s" % [url, status, checked_at]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http-pulse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Corey Donohoe
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-14 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 5
|
32
|
+
- 0
|
33
|
+
version: 1.5.0
|
34
|
+
requirement: *id001
|
35
|
+
type: :runtime
|
36
|
+
name: rest-client
|
37
|
+
description: A gem that provides interaction with the http-pulse service
|
38
|
+
email: atmos@atmos.org
|
39
|
+
executables:
|
40
|
+
- http-pulse
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README.md
|
45
|
+
- LICENSE.md
|
46
|
+
files:
|
47
|
+
- LICENSE.md
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- bin/http-pulse
|
51
|
+
- lib/http-pulse/request.rb
|
52
|
+
- lib/http-pulse/response.rb
|
53
|
+
- lib/http-pulse.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://www.atmos.org/http-pulse
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: A CLI tools for http-pulse
|
88
|
+
test_files: []
|
89
|
+
|