overwatch-cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.watchr +18 -0
- data/Gemfile +14 -0
- data/README.md +6 -0
- data/Rakefile +42 -0
- data/bin/overwatch +8 -0
- data/config/overwatchrc +6 -0
- data/lib/overwatch/cli.rb +17 -0
- data/lib/overwatch/cli/command.rb +71 -0
- data/lib/overwatch/cli/command/base.rb +12 -0
- data/lib/overwatch/cli/command/main.rb +14 -0
- data/lib/overwatch/cli/command/resource.rb +11 -0
- data/lib/overwatch/cli/command/resource/create.rb +14 -0
- data/lib/overwatch/cli/command/resource/delete.rb +11 -0
- data/lib/overwatch/cli/command/resource/list.rb +12 -0
- data/lib/overwatch/cli/command/resource/regenerate.rb +11 -0
- data/lib/overwatch/cli/command/resource/show.rb +11 -0
- data/lib/overwatch/cli/command/resource/update.rb +11 -0
- data/lib/overwatch/cli/helpers.rb +95 -0
- data/lib/overwatch/cli/version.rb +5 -0
- data/overwatch-cli.gemspec +32 -0
- data/spec/overwatch_spec.rb +0 -0
- data/spec/spec_helper.rb +25 -0
- metadata +176 -0
data/.gitignore
ADDED
data/.watchr
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
def run_spec(file)
|
2
|
+
unless File.exist?(file)
|
3
|
+
puts "#{file} does not exist"
|
4
|
+
return
|
5
|
+
end
|
6
|
+
|
7
|
+
puts "Running #{file}"
|
8
|
+
system "bundle exec rspec #{file}"
|
9
|
+
puts
|
10
|
+
end
|
11
|
+
|
12
|
+
watch("spec/.*/*_spec\.rb") do |match|
|
13
|
+
run_spec match[0]
|
14
|
+
end
|
15
|
+
|
16
|
+
watch("lib/(.*/.*)\.rb") do |match|
|
17
|
+
run_spec %{spec/#{match[1]}_spec.rb}
|
18
|
+
end
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
# require 'resque/tasks'
|
7
|
+
# require 'resque_scheduler/tasks'
|
8
|
+
|
9
|
+
require 'bundler/gem_tasks'
|
10
|
+
|
11
|
+
require 'rspec/core/rake_task'
|
12
|
+
|
13
|
+
desc "Run specs"
|
14
|
+
RSpec::Core::RakeTask.new do |task|
|
15
|
+
task.pattern = "spec/**/*_spec.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run watchr"
|
19
|
+
task :watchr do
|
20
|
+
sh %{bundle exec watchr .watchr}
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Run spork"
|
24
|
+
task :spork do
|
25
|
+
sh %{bundle exec spork}
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
Bundler.require(:doc)
|
30
|
+
desc "Generate documentation"
|
31
|
+
YARD::Rake::YardocTask.new do |t|
|
32
|
+
t.files = [ 'lib/**/*.rb' ]
|
33
|
+
end
|
34
|
+
|
35
|
+
namespace :overwatch do
|
36
|
+
namespace :test do
|
37
|
+
task :snapshot => :environment do
|
38
|
+
a = Resource.first
|
39
|
+
a.snapshots.create(:data => {:one => rand(10), :two => { :three => rand(10) }})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/bin/overwatch
ADDED
data/config/overwatchrc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'clamp'
|
4
|
+
require 'formatador'
|
5
|
+
require 'hirb'
|
6
|
+
|
7
|
+
require 'overwatch/cli/command'
|
8
|
+
require 'overwatch/cli/helpers'
|
9
|
+
require 'overwatch/cli/version'
|
10
|
+
|
11
|
+
|
12
|
+
module Overwatch
|
13
|
+
module CLI
|
14
|
+
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'clamp'
|
3
|
+
require 'formatador'
|
4
|
+
require 'yajl/json_gem'
|
5
|
+
require 'overwatch/cli/helpers'
|
6
|
+
require 'hirb'
|
7
|
+
|
8
|
+
module Overwatch
|
9
|
+
module CLI
|
10
|
+
class Command < Clamp::Command
|
11
|
+
include Helpers
|
12
|
+
|
13
|
+
option ["-v", "--verbose"], :flag, "be verbose"
|
14
|
+
option "--version", :flag, "show version" do
|
15
|
+
puts "Overwatch v#{Overwatch::CLI::VERSION} (Codename: Snickelfritz)"
|
16
|
+
exit(0)
|
17
|
+
end
|
18
|
+
subcommand "resource", "Resources" do
|
19
|
+
option ["-h", "--host"], "HOST", "overwatch-collection server", :default => "localhost"
|
20
|
+
option ["-p", "--port"], "PORT", "overwatch-collection port", :default => "9001"
|
21
|
+
option ["-f", "--format"], "[FORMAT]", "format (choices: pretty, json, text)", :default => "pretty"
|
22
|
+
|
23
|
+
subcommand "list", "list all resources" do
|
24
|
+
def execute
|
25
|
+
options = { :fields => ['id','name', 'api_key'], :format => format }
|
26
|
+
|
27
|
+
get("http://#{host}:#{port}/resources", options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
subcommand "show", "show a specific resource" do
|
32
|
+
parameter "NAME", "resource name"
|
33
|
+
|
34
|
+
option ['-a', '--attributes'], :flag, "list all resource attributes"
|
35
|
+
|
36
|
+
def execute
|
37
|
+
options = { :fields => ['id','name', 'api_key'], :format => format }
|
38
|
+
get("http://#{host}:#{port}/resources/#{name}", options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
subcommand "create", "create a new resource" do
|
43
|
+
parameter "NAME", "resource name"
|
44
|
+
|
45
|
+
def execute
|
46
|
+
options = { :fields => ['id','name', 'api_key'], :format => format }
|
47
|
+
post("http://#{host}:#{port}/resources", JSON.generate({:name => name}), options)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
subcommand "update", "update an existing resource"
|
52
|
+
subcommand "delete", "delete an existing resource" do
|
53
|
+
parameter "NAME", "resource name"
|
54
|
+
|
55
|
+
def execute
|
56
|
+
# resource = delete("http://#{host}:#{port}/resources/#{name}")
|
57
|
+
display_line "[yellow]Resource deleted![/]"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
subcommand "regenerate", "regenerate a resource's API key"
|
61
|
+
end
|
62
|
+
|
63
|
+
subcommand "snapshot", "Snapshots" do
|
64
|
+
subcommand "show", "show an existing snapshot"
|
65
|
+
subcommand "create", "create a new snapshot"
|
66
|
+
subcommand "delete", "delete an existing snapshot"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Overwatch
|
2
|
+
module CLI
|
3
|
+
module Helpers
|
4
|
+
def f
|
5
|
+
@f ||= Formatador.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def display_line(string)
|
9
|
+
f.display_line(string)
|
10
|
+
end
|
11
|
+
|
12
|
+
def default_headers
|
13
|
+
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(url, options={}, headers={})
|
17
|
+
begin
|
18
|
+
response = JSON.parse(RestClient.get(url, headers.merge!(default_headers)))
|
19
|
+
format_output(response, options)
|
20
|
+
rescue RestClient::Exception => e
|
21
|
+
response = {:code => e.http_code.to_s, :errors => JSON.parse(e.http_body)}
|
22
|
+
options.merge!(:fields => [ :code, :errors ])
|
23
|
+
format_output(response, options)
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def post(url, payload={}, options={}, headers={})
|
29
|
+
begin
|
30
|
+
response = JSON.parse(RestClient.post(url, payload, headers.merge!(default_headers)))
|
31
|
+
format_output(response, options)
|
32
|
+
rescue RestClient::Exception => e
|
33
|
+
response = {:code => e.http_code.to_s, :errors => JSON.parse(e.http_body)}
|
34
|
+
options[:fields] = [ :code, :errors ]
|
35
|
+
format_output(response, options)
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete(url, headers={})
|
41
|
+
begin
|
42
|
+
res = RestClient.delete(url, headers.merge!(default_headers))
|
43
|
+
JSON.parse(res)
|
44
|
+
rescue RestClient::Exception => e
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def format_output(rows, options)
|
49
|
+
data = rows.is_a?(Array) ? rows : [rows]
|
50
|
+
|
51
|
+
case options[:format]
|
52
|
+
when 'text'
|
53
|
+
puts Hirb::Helpers::TextTable.render(data, options)
|
54
|
+
when 'json'
|
55
|
+
pp JSON.generate(data)
|
56
|
+
else
|
57
|
+
puts Hirb::Helpers::Table.render(data, options)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
class Hirb::Helpers::TextTable < Hirb::Helpers::Table
|
66
|
+
CHARS = {
|
67
|
+
:top => {
|
68
|
+
:left => '', :center => '', :right => '', :horizontal => '', :vertical => {
|
69
|
+
:outside => '', :inside => ''
|
70
|
+
}
|
71
|
+
},
|
72
|
+
:middle => {
|
73
|
+
:left => '', :center => '', :right => '', :horizontal => ''
|
74
|
+
},
|
75
|
+
:bottom => {
|
76
|
+
:left => '', :center => '', :right => '', :horizontal => '', :vertical => {
|
77
|
+
:outside => '', :inside => ''
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
def self.render(rows, options={})
|
83
|
+
options.merge!(:headers => false, :description => false)
|
84
|
+
new(rows, options).render
|
85
|
+
end
|
86
|
+
|
87
|
+
def render
|
88
|
+
body = []
|
89
|
+
unless @rows.length == 0
|
90
|
+
setup_field_lengths
|
91
|
+
body += render_rows
|
92
|
+
end
|
93
|
+
body.join("\n")
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require 'overwatch/cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'overwatch-cli'
|
8
|
+
s.version = Overwatch::CLI::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = [ "Dan Ryan" ]
|
11
|
+
s.email = [ "dan@appliedawesome.com" ]
|
12
|
+
s.homepage = "https://github.com/danryan/overwatch-cli"
|
13
|
+
s.summary = "Overwatch command-line interface for configuration and reporting"
|
14
|
+
s.description = "overwatch-cli is the command-line interface to the Overwatch monitoring suite"
|
15
|
+
|
16
|
+
s.rubyforge_project = "overwatch-cli"
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'yajl-ruby', '>= 0.8.2'
|
23
|
+
s.add_dependency 'rest-client', '>= 1.6.3'
|
24
|
+
s.add_dependency 'clamp', '>= 0.2.2'
|
25
|
+
s.add_dependency 'formatador', '>= 0.2.0'
|
26
|
+
s.add_dependency 'hirb', '0.4.5'
|
27
|
+
|
28
|
+
s.add_development_dependency 'rspec', '>= 2.6.0'
|
29
|
+
s.add_development_dependency 'spork', '>= 0.9.0.rc8'
|
30
|
+
s.add_development_dependency 'watchr', '>= 0.7'
|
31
|
+
s.add_development_dependency 'json_spec', '>= 0.5.0'
|
32
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spork'
|
3
|
+
|
4
|
+
Spork.prefork do
|
5
|
+
ENV["RACK_ENV"] ||= 'test'
|
6
|
+
require 'rspec'
|
7
|
+
|
8
|
+
support_files = File.join(File.expand_path(File.dirname(__FILE__)), "spec/support/**/*.rb")
|
9
|
+
Dir[support_files].each {|f| require f}
|
10
|
+
|
11
|
+
ENV['REDIS_URL'] = 'redis://localhost:6379/3'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.color_enabled = true
|
15
|
+
config.formatter = "documentation"
|
16
|
+
config.mock_with :rspec
|
17
|
+
|
18
|
+
config.before :suite do
|
19
|
+
$redis.flushdb
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Spork.each_run do
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: overwatch-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Ryan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-07-22 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yajl-ruby
|
16
|
+
requirement: &2165046360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2165046360
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rest-client
|
27
|
+
requirement: &2165045860 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.6.3
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2165045860
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: clamp
|
38
|
+
requirement: &2165045400 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.2.2
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2165045400
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: formatador
|
49
|
+
requirement: &2165044940 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.0
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2165044940
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: hirb
|
60
|
+
requirement: &2165044480 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - =
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.4.5
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2165044480
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: &2165066520 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.6.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2165066520
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: spork
|
82
|
+
requirement: &2165066060 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.9.0.rc8
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2165066060
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: watchr
|
93
|
+
requirement: &2165065600 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0.7'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2165065600
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: json_spec
|
104
|
+
requirement: &2165065140 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.5.0
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *2165065140
|
113
|
+
description: overwatch-cli is the command-line interface to the Overwatch monitoring
|
114
|
+
suite
|
115
|
+
email:
|
116
|
+
- dan@appliedawesome.com
|
117
|
+
executables:
|
118
|
+
- overwatch
|
119
|
+
extensions: []
|
120
|
+
extra_rdoc_files: []
|
121
|
+
files:
|
122
|
+
- .gitignore
|
123
|
+
- .watchr
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/overwatch
|
129
|
+
- config/overwatchrc
|
130
|
+
- lib/overwatch/cli.rb
|
131
|
+
- lib/overwatch/cli/command.rb
|
132
|
+
- lib/overwatch/cli/command/base.rb
|
133
|
+
- lib/overwatch/cli/command/main.rb
|
134
|
+
- lib/overwatch/cli/command/resource.rb
|
135
|
+
- lib/overwatch/cli/command/resource/create.rb
|
136
|
+
- lib/overwatch/cli/command/resource/delete.rb
|
137
|
+
- lib/overwatch/cli/command/resource/list.rb
|
138
|
+
- lib/overwatch/cli/command/resource/regenerate.rb
|
139
|
+
- lib/overwatch/cli/command/resource/show.rb
|
140
|
+
- lib/overwatch/cli/command/resource/update.rb
|
141
|
+
- lib/overwatch/cli/helpers.rb
|
142
|
+
- lib/overwatch/cli/version.rb
|
143
|
+
- overwatch-cli.gemspec
|
144
|
+
- spec/overwatch_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
homepage: https://github.com/danryan/overwatch-cli
|
147
|
+
licenses: []
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
segments:
|
159
|
+
- 0
|
160
|
+
hash: -974194128470217844
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
segments:
|
168
|
+
- 0
|
169
|
+
hash: -974194128470217844
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project: overwatch-cli
|
172
|
+
rubygems_version: 1.8.5
|
173
|
+
signing_key:
|
174
|
+
specification_version: 3
|
175
|
+
summary: Overwatch command-line interface for configuration and reporting
|
176
|
+
test_files: []
|