site_status 0.0.6
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/.gitignore +9 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +17 -0
- data/README.md +60 -0
- data/Rakefile +8 -0
- data/lib/site_status.rb +20 -0
- data/lib/site_status/configuration.rb +12 -0
- data/lib/site_status/file_reader.rb +26 -0
- data/lib/site_status/request.rb +39 -0
- data/site_status.gemspec +19 -0
- data/test/test_status.rb +5 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
site_status
|
2
|
+
============
|
3
|
+
|
4
|
+
[Project description and any badges]
|
5
|
+

|
6
|
+
|
7
|
+
If your app depends on any external services or endpoints, you've probably needed to ensure those services were properly responding.
|
8
|
+
|
9
|
+
site_status is a light weight gem which checks the HTTP status of any website(s).
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# ./lib/tasks/status.rake
|
13
|
+
namespace :status do
|
14
|
+
task :check do
|
15
|
+
require 'site_status'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
In your shell:
|
21
|
+
|
22
|
+
```shell
|
23
|
+
rake status:check
|
24
|
+
```
|
25
|
+
|
26
|
+
## Requirements
|
27
|
+
site_status is configured by default to look for a file name `config/status_check.yml` in your project root.
|
28
|
+
|
29
|
+
```yaml
|
30
|
+
# ./config/status_check.yml
|
31
|
+
endpoints:
|
32
|
+
- 'http://www.b3ta.com/404'
|
33
|
+
- 'http://github.com/'
|
34
|
+
other_endpoints:
|
35
|
+
- 'http://canyoufixmycomputer.com/'
|
36
|
+
```
|
37
|
+
|
38
|
+
If you prefer a different file path, configuration is simple:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
SiteStat.configure do |config|
|
42
|
+
config.yml_path = 'path/to/file.yml'
|
43
|
+
end
|
44
|
+
```
|
45
|
+
Configuration must be run prior to `require site_status`
|
46
|
+
|
47
|
+
## Limitations
|
48
|
+
Does not play well with ssl and unresolvable dns
|
49
|
+
|
50
|
+
## Installation
|
51
|
+
add `gem "site_status"` to your gemfile or `gem install site_status`
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
## Credits
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
site_status is released under the MIT License. See the bundled LICENSE file for
|
60
|
+
details.
|
data/Rakefile
ADDED
data/lib/site_status.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'rainbow'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
require_relative 'site_status/configuration'
|
6
|
+
require_relative 'site_status/request'
|
7
|
+
require_relative 'site_status/file_reader'
|
8
|
+
|
9
|
+
module SiteStat
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
yield(configuration) if block_given?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
SiteStat::Request.new
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SiteStat
|
2
|
+
class FileReader
|
3
|
+
|
4
|
+
attr_reader :url_hash
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@url_hash = loaded_file
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def file_path
|
13
|
+
SiteStat.configuration.yml_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def loaded_file
|
17
|
+
begin
|
18
|
+
YAML.load(File.read(file_path))
|
19
|
+
rescue
|
20
|
+
SiteStat.configure
|
21
|
+
YAML.load(File.read(file_path))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SiteStat
|
2
|
+
class Request
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
ping_urls
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def ping_urls
|
11
|
+
services = FileReader.new.url_hash
|
12
|
+
services.each { |svc, urls| get_status_for(svc, urls) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_status_for(service, urls)
|
16
|
+
urls.each do |url|
|
17
|
+
escaped_url = URI.parse(url.to_s)
|
18
|
+
begin
|
19
|
+
res = Net::HTTP.get_response(escaped_url)
|
20
|
+
handle_response(res, service, url)
|
21
|
+
rescue Timeout::Error => exc
|
22
|
+
msg = "#{service}: #{url} | #{exc.message}"
|
23
|
+
$stdout.puts msg.color(:red)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def handle_response(res, service, url)
|
29
|
+
if res.code =~ /2|3\d{2}/
|
30
|
+
msg = "#{service}: #{res.code} | #{url} | #{res.message}"
|
31
|
+
$stdout.puts msg.color(:green)
|
32
|
+
else
|
33
|
+
msg = "#{service}: #{res.code} | #{url} | #{res.message}"
|
34
|
+
$stdout.puts msg.color(:red)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/site_status.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "site_status"
|
5
|
+
s.version = "0.0.6"
|
6
|
+
s.default_executable = "site_status"
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Luke Fender, Mike Fischer"]
|
9
|
+
s.date = %q{2013-10-08}
|
10
|
+
s.description = %q{site_status is a light weight gem which checks the HTTP status of any website(s).}
|
11
|
+
s.email = %q{lfender@rentpath.com}
|
12
|
+
s.files = `git ls-files`.split($/)
|
13
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.homepage = %q{https://github.com/primedia/site_status}
|
16
|
+
s.summary = %q{Site Status!}
|
17
|
+
s.add_dependency 'rainbow'
|
18
|
+
end
|
19
|
+
|
data/test/test_status.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: site_status
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Luke Fender, Mike Fischer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rainbow
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: site_status is a light weight gem which checks the HTTP status of any
|
31
|
+
website(s).
|
32
|
+
email: lfender@rentpath.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/site_status.rb
|
43
|
+
- lib/site_status/configuration.rb
|
44
|
+
- lib/site_status/file_reader.rb
|
45
|
+
- lib/site_status/request.rb
|
46
|
+
- site_status.gemspec
|
47
|
+
- test/test_status.rb
|
48
|
+
homepage: https://github.com/primedia/site_status
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.25
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Site Status!
|
72
|
+
test_files:
|
73
|
+
- test/test_status.rb
|
74
|
+
has_rdoc:
|