downrightnow 0.2.0
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 +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +12 -0
- data/LICENSE +22 -0
- data/bin/downrightnow +7 -0
- data/downrightnow.gemspec +25 -0
- data/lib/downrightnow.rb +77 -0
- data/lib/downrightnow/util/command_line.rb +29 -0
- metadata +75 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2011 Barry Allard
|
|
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/bin/downrightnow
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
|
2
|
+
|
|
3
|
+
require 'downrightnow'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.name = "downrightnow"
|
|
7
|
+
gem.version = DownRightNow.version
|
|
8
|
+
gem.platform = Gem::Platform::RUBY
|
|
9
|
+
gem.authors = "Barry Allard (steakknife)"
|
|
10
|
+
gem.email = "barry@barryallard.name"
|
|
11
|
+
gem.homepage = "https://github.com/steakknife/downrightnow"
|
|
12
|
+
gem.summary = "Unofficial Ruby interface and command-line to DownRightnow.com"
|
|
13
|
+
gem.description = "See http://downrightnow.com"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Man files are required because they are ignored by git
|
|
17
|
+
man_files = Dir.glob("lib/downrightnow/man/**/*")
|
|
18
|
+
git_files = `git ls-files`.split("\n") rescue ''
|
|
19
|
+
gem.files = git_files + man_files
|
|
20
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select { |d| d =~ %r{^(README|bin/|data/|ext/|lib/|spec/|test/)} }
|
|
21
|
+
gem.executables = "downrightnow"
|
|
22
|
+
|
|
23
|
+
gem.add_dependency 'nokogiri', '>= 1.4.0'
|
|
24
|
+
gem.add_dependency 'trollop', '>= 1.16'
|
|
25
|
+
end
|
data/lib/downrightnow.rb
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# External runtime dependencies
|
|
4
|
+
require 'nokogiri'
|
|
5
|
+
require 'trollop'
|
|
6
|
+
|
|
7
|
+
# System libraries
|
|
8
|
+
require 'open-uri'
|
|
9
|
+
require 'time'
|
|
10
|
+
|
|
11
|
+
module DownRightNow
|
|
12
|
+
VERSION = '0.2.0'
|
|
13
|
+
|
|
14
|
+
def DownRightNow.version
|
|
15
|
+
VERSION
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class DownRightNow
|
|
19
|
+
# The original document received and parsed.
|
|
20
|
+
attr_reader :doc
|
|
21
|
+
|
|
22
|
+
# List of services as an array of strings.
|
|
23
|
+
attr_reader :services
|
|
24
|
+
|
|
25
|
+
# List of statuses (coresponding to services) as an array of strings.
|
|
26
|
+
attr_reader :statuses
|
|
27
|
+
|
|
28
|
+
# List of updates (coresponding to services) as an array of time objects.
|
|
29
|
+
attr_reader :last_updates
|
|
30
|
+
|
|
31
|
+
# Overall last update as a time object.
|
|
32
|
+
attr_reader :last_updated_all
|
|
33
|
+
|
|
34
|
+
def initialize
|
|
35
|
+
refresh
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Go fetch the status document.
|
|
39
|
+
def refresh
|
|
40
|
+
@doc = Nokogiri::HTML(open('http://www.downrightnow.com'))
|
|
41
|
+
@services = @doc.css('h2.serviceIcon a').map { |x| x.content.sub(/ status/,'') }
|
|
42
|
+
@statuses = @doc.css('span.status').map(&:content)
|
|
43
|
+
@last_updates = @doc.css('p.lastDisruption span.timestamp').map(&:content).map { |x| Time.parse(x) }
|
|
44
|
+
@last_updated_all = Time.parse(@doc.css('form#autoRefreshForm p.sprite span.timestamp')[0].content)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# [ (services, statuses, last_updates) ... ]
|
|
48
|
+
def to_tuple
|
|
49
|
+
services.zip statuses, last_updates
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def any_outages?
|
|
53
|
+
statuses.any? { |x| x != 'Up' }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Return a human-friendly representation.
|
|
57
|
+
def to_s(verbose=false)
|
|
58
|
+
alignment1 = services.map(&:length).max + 2
|
|
59
|
+
alignment2 = statuses.map(&:length).max + 2
|
|
60
|
+
|
|
61
|
+
result = "%*s: %*s " % [alignment1, "Service Name", -alignment2, "Status"]
|
|
62
|
+
result += " Last Update" if verbose
|
|
63
|
+
result += "\n"
|
|
64
|
+
|
|
65
|
+
result += "-"*(alignment1+alignment2+8+(verbose ? 25:0)) + "\n"
|
|
66
|
+
|
|
67
|
+
to_tuple.each { |name, status, last_update|
|
|
68
|
+
result += "%*s: %*s " % [alignment1, name, -alignment2, status]
|
|
69
|
+
result += " #{last_update}" if verbose
|
|
70
|
+
result += "\n"
|
|
71
|
+
}
|
|
72
|
+
result += "\nOverall last update was at: #{last_updated_all}\n"
|
|
73
|
+
result
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
end # class DownRightNow
|
|
77
|
+
end # module DownRightNow
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'downrightnow'
|
|
2
|
+
require 'trollop'
|
|
3
|
+
|
|
4
|
+
module DownRightNow
|
|
5
|
+
module Util
|
|
6
|
+
class CommandLine
|
|
7
|
+
def exec
|
|
8
|
+
begin
|
|
9
|
+
opts = Trollop::options do
|
|
10
|
+
version "DownRightNow (tm) unofficial ruby utility #{version} (c) 2011 Barry Allard"
|
|
11
|
+
banner <<-EOS
|
|
12
|
+
DownRightNow (tm) unofficial ruby utility #{version} (c) 2011 Barry Allard
|
|
13
|
+
|
|
14
|
+
EOS
|
|
15
|
+
opt :verbose, "Verbose display", :default => false
|
|
16
|
+
opt :error_on_outage, "Return error exit code if any outage", :default => false
|
|
17
|
+
end
|
|
18
|
+
drn = DownRightNow.new
|
|
19
|
+
puts drn.to_s opts[:verbose]
|
|
20
|
+
exit 1 if opts[:error_on_outage] && drn.any_outages?
|
|
21
|
+
rescue => e
|
|
22
|
+
# puts e
|
|
23
|
+
# exit 1
|
|
24
|
+
raise e
|
|
25
|
+
end
|
|
26
|
+
end # def exec
|
|
27
|
+
end # class CommandLine
|
|
28
|
+
end # module Util
|
|
29
|
+
end # module DownRightNow
|
metadata
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: downrightnow
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Barry Allard (steakknife)
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2011-10-14 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: nokogiri
|
|
16
|
+
requirement: &70277761828300 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 1.4.0
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *70277761828300
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: trollop
|
|
27
|
+
requirement: &70277761826740 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '1.16'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70277761826740
|
|
36
|
+
description: See http://downrightnow.com
|
|
37
|
+
email: barry@barryallard.name
|
|
38
|
+
executables:
|
|
39
|
+
- downrightnow
|
|
40
|
+
extensions: []
|
|
41
|
+
extra_rdoc_files: []
|
|
42
|
+
files:
|
|
43
|
+
- .gitignore
|
|
44
|
+
- Gemfile
|
|
45
|
+
- Gemfile.lock
|
|
46
|
+
- LICENSE
|
|
47
|
+
- bin/downrightnow
|
|
48
|
+
- downrightnow.gemspec
|
|
49
|
+
- lib/downrightnow.rb
|
|
50
|
+
- lib/downrightnow/util/command_line.rb
|
|
51
|
+
homepage: https://github.com/steakknife/downrightnow
|
|
52
|
+
licenses: []
|
|
53
|
+
post_install_message:
|
|
54
|
+
rdoc_options: []
|
|
55
|
+
require_paths:
|
|
56
|
+
- lib
|
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
|
+
none: false
|
|
59
|
+
requirements:
|
|
60
|
+
- - ! '>='
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
|
+
none: false
|
|
65
|
+
requirements:
|
|
66
|
+
- - ! '>='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
requirements: []
|
|
70
|
+
rubyforge_project:
|
|
71
|
+
rubygems_version: 1.8.11
|
|
72
|
+
signing_key:
|
|
73
|
+
specification_version: 3
|
|
74
|
+
summary: Unofficial Ruby interface and command-line to DownRightnow.com
|
|
75
|
+
test_files: []
|