what 0.2.2 → 0.2.4
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/bin/whatsup +49 -0
- data/lib/what/helpers.rb +6 -10
- data/lib/what/sup.rb +91 -0
- data/lib/what/version.rb +1 -1
- data/what.gemspec +2 -2
- metadata +7 -3
data/bin/whatsup
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'optparse'
|
5
|
+
require 'what/version'
|
6
|
+
require 'what/sup'
|
7
|
+
|
8
|
+
options = Struct.new(:oks, :warnings, :alerts, :servers, :hide).new
|
9
|
+
options.alerts = true
|
10
|
+
options.servers = []
|
11
|
+
|
12
|
+
opts = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: what [options]"
|
14
|
+
opts.separator ""
|
15
|
+
|
16
|
+
opts.on_tail('-v', '--version', 'Show the version number.') do
|
17
|
+
puts What::VERSION
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on_tail('-h', '--help', 'Show this message.') do
|
22
|
+
puts opts
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on('-o', '--ok', 'Show details for ok, warning and alert levels.') do
|
27
|
+
options.oks = true
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on('-w', '--warning', 'Show details for warning and alert levels.') do
|
31
|
+
options.warnings = true
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('-a', '--alert', 'Show details for alert levels (default).') do
|
35
|
+
options.alerts = true
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on('-s', '--server host:port', 'Show details from What server at host:port (default 127.0.0.1:9428). Multiple servers are supported.') do |s|
|
39
|
+
options.servers << s
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on('-d', '--hide', 'When showing multiple servers, hide servers who have nothing to show at the level set by -o, -w, or -a') do
|
43
|
+
options.hide = true
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
opts.parse!(ARGV)
|
48
|
+
|
49
|
+
What::Sup.run(options)
|
data/lib/what/helpers.rb
CHANGED
@@ -2,17 +2,13 @@ module What
|
|
2
2
|
module Helpers
|
3
3
|
# Take an array of healths and determine overall health, on
|
4
4
|
# the principle that overall health == the worst sub-health.
|
5
|
+
HEALTH = %w(ok warning alert)
|
5
6
|
def self.overall_health(healths)
|
6
|
-
healths.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
'warning' if overall != 'alert'
|
12
|
-
else
|
13
|
-
'alert'
|
14
|
-
end
|
15
|
-
end
|
7
|
+
worst_health = healths.map do |health|
|
8
|
+
HEALTH.index(health) || HEALTH.index('alert')
|
9
|
+
end.max
|
10
|
+
|
11
|
+
HEALTH[worst_health]
|
16
12
|
end
|
17
13
|
|
18
14
|
# Stolen from Rails (http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html)
|
data/lib/what/sup.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
## Impletments the whatsup CLI for querying what servers
|
5
|
+
|
6
|
+
module What
|
7
|
+
class Sup
|
8
|
+
|
9
|
+
LEVELS = ['unknown', 'ok', 'warning', 'alert']
|
10
|
+
|
11
|
+
def self.run(opts)
|
12
|
+
new(opts).run
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(opts)
|
16
|
+
@opts = opts
|
17
|
+
@statuses = []
|
18
|
+
@servers = if opts.servers.size > 0
|
19
|
+
opts.servers
|
20
|
+
else
|
21
|
+
['127.0.0.1']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
##@@ TODO: Make this multi-threaded
|
26
|
+
def fetch_statuses
|
27
|
+
@servers.each do |s|
|
28
|
+
@statuses << self.fetch_status(*s.split(':'))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def fetch_status(host, port='9428')
|
33
|
+
status = { 'host' => host, 'health' => 'unknown', 'oks' => [], 'warnings' => [], 'alerts' => [] }
|
34
|
+
begin
|
35
|
+
response = JSON.parse(Net::HTTP.get(host, '/', port))
|
36
|
+
#status['details'] = response['details']
|
37
|
+
response['details'].each do |d|
|
38
|
+
if LEVELS.index(d['health']) > LEVELS.index(status['health'])
|
39
|
+
status['health'] = d['health']
|
40
|
+
end
|
41
|
+
status["#{d['health']}s"] << [d['type'], d['details']]
|
42
|
+
end
|
43
|
+
rescue
|
44
|
+
end
|
45
|
+
status
|
46
|
+
end
|
47
|
+
|
48
|
+
def print_status(status)
|
49
|
+
sections_to_show = self.sections_to_show
|
50
|
+
if !@opts.hide || sections_to_show.any?{|s| status[s[1]].size > 0} || (status['health'] == 'unknown')
|
51
|
+
puts "#{status['host']} | #{status['health'].upcase}"
|
52
|
+
puts
|
53
|
+
sections_to_show.each do |s|
|
54
|
+
print_status_section(s[1], status[s[1]])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def print_status_section(section, details)
|
60
|
+
puts " #{section}:"
|
61
|
+
details.each do |d|
|
62
|
+
puts " #{d[0]}"
|
63
|
+
puts " #{d[1].inspect}"
|
64
|
+
end
|
65
|
+
puts
|
66
|
+
end
|
67
|
+
|
68
|
+
def sections_to_show
|
69
|
+
sections = []
|
70
|
+
if @opts.alerts
|
71
|
+
sections << ['Alerts', 'alerts']
|
72
|
+
end
|
73
|
+
if @opts.warnings || @opts.oks
|
74
|
+
sections << ['Warnings', 'warnings']
|
75
|
+
end
|
76
|
+
if @opts.oks
|
77
|
+
sections << ['OKs', 'oks']
|
78
|
+
end
|
79
|
+
sections
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def run
|
84
|
+
self.fetch_statuses
|
85
|
+
@statuses.each do |status|
|
86
|
+
self.print_status(status)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
data/lib/what/version.rb
CHANGED
data/what.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "what"
|
7
7
|
s.version = What::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Ryan Fitzgerald", "Ryan Lower"]
|
10
|
-
s.email = ["rwfitzge@gmail.com", "rpjlower@gmail.com"]
|
9
|
+
s.authors = ["Ryan Fitzgerald", "Ryan Lower", "Colin Curtin"]
|
10
|
+
s.email = ["rwfitzge@gmail.com", "rpjlower@gmail.com", "colin.t.curtin@gmail.com"]
|
11
11
|
s.homepage = "http://academia.edu/"
|
12
12
|
s.summary = %q{Simple server monitoring tool}
|
13
13
|
s.description = <<-EOS
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Fitzgerald
|
9
9
|
- Ryan Lower
|
10
|
+
- Colin Curtin
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2012-
|
14
|
+
date: 2012-11-17 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: rack
|
@@ -73,8 +74,10 @@ description: ! 'What uses WEBrick to serve a JSON object representing the state
|
|
73
74
|
email:
|
74
75
|
- rwfitzge@gmail.com
|
75
76
|
- rpjlower@gmail.com
|
77
|
+
- colin.t.curtin@gmail.com
|
76
78
|
executables:
|
77
79
|
- what
|
80
|
+
- whatsup
|
78
81
|
extensions: []
|
79
82
|
extra_rdoc_files: []
|
80
83
|
files:
|
@@ -84,6 +87,7 @@ files:
|
|
84
87
|
- README.md
|
85
88
|
- Rakefile
|
86
89
|
- bin/what
|
90
|
+
- bin/whatsup
|
87
91
|
- example/modules/custom_module.rb
|
88
92
|
- example/what.yml
|
89
93
|
- lib/what.rb
|
@@ -104,6 +108,7 @@ files:
|
|
104
108
|
- lib/what/monitor.rb
|
105
109
|
- lib/what/server.rb
|
106
110
|
- lib/what/status.rb
|
111
|
+
- lib/what/sup.rb
|
107
112
|
- lib/what/version.rb
|
108
113
|
- what.gemspec
|
109
114
|
homepage: http://academia.edu/
|
@@ -131,4 +136,3 @@ signing_key:
|
|
131
136
|
specification_version: 3
|
132
137
|
summary: Simple server monitoring tool
|
133
138
|
test_files: []
|
134
|
-
has_rdoc:
|