bixby-client 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +38 -23
- data/VERSION +1 -1
- data/bin/bixby +6 -0
- data/bixby-client.gemspec +25 -4
- data/lib/bixby-client.rb +2 -1
- data/lib/bixby-client/app.rb +88 -0
- data/lib/bixby-client/app/command.rb +27 -0
- data/lib/bixby-client/app/commands/run.rb +53 -0
- data/lib/bixby-client/app/file_finder.rb +85 -0
- data/lib/bixby-client/client.rb +16 -0
- data/lib/bixby-client/client/version.rb +6 -0
- data/lib/bixby-client/model.rb +6 -0
- data/lib/bixby-client/model/agent.rb +17 -0
- data/lib/bixby-client/model/base.rb +60 -0
- data/lib/bixby-client/model/check.rb +17 -0
- data/lib/bixby-client/model/command.rb +17 -0
- data/lib/bixby-client/model/host.rb +17 -0
- data/lib/bixby-client/model/metric.rb +21 -0
- data/tasks/coverage.rake +2 -0
- data/tasks/coveralls.rake +10 -0
- metadata +46 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72daf8d74d021a0b3c397c5fa8ea3c01fe43e14d
|
4
|
+
data.tar.gz: a5cbd3599ca0c9e3f6dbec98cf8daf2f7f382f85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff267307702818c6a7b9f6969553d27b6b50e905eb8230ad5dd8c693ee90e6daaac975c71978fab0f9475430b4e9d320a32549bab74a53c895efc0ad5c679469
|
7
|
+
data.tar.gz: 09cff927b2e1e93dca72a0e3488873779c90fa192a5823a5023f512649fd09a07cb6630da52758b91be530aa73279cbc3c8ce68b3cfa894c9a5fabd672ecc06a
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -8,6 +8,7 @@ gem 'oj'
|
|
8
8
|
gem 'httpi'
|
9
9
|
gem 'curb'
|
10
10
|
gem 'mixlib-shellout'
|
11
|
+
gem 'fuzzy_file_finder'
|
11
12
|
|
12
13
|
gem "api-auth", :git => "https://github.com/chetan/api_auth.git", :branch => "bixby"
|
13
14
|
|
@@ -24,6 +25,7 @@ group :development do
|
|
24
25
|
|
25
26
|
gem "simplecov", :platforms => [:mri_19, :mri_20, :rbx], :git => "https://github.com/chetan/simplecov.git", :branch => "inline_nocov"
|
26
27
|
gem "micron", :github => "chetan/micron"
|
28
|
+
gem "coveralls", :require => false
|
27
29
|
|
28
30
|
gem "webmock", :require => false
|
29
31
|
gem "mocha", :require => false
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
GIT
|
2
2
|
remote: git://github.com/chetan/micron.git
|
3
|
-
revision:
|
3
|
+
revision: 95399129ce8908484ed92a0de3a7e0ce83d99d2b
|
4
4
|
specs:
|
5
5
|
micron (0.1.0)
|
6
6
|
colorize
|
@@ -40,37 +40,44 @@ GIT
|
|
40
40
|
|
41
41
|
GIT
|
42
42
|
remote: https://github.com/chetan/test_guard.git
|
43
|
-
revision:
|
43
|
+
revision: 6e184096f7713cefe6eab3d250b18d214e09a1ca
|
44
44
|
specs:
|
45
45
|
test_guard (0.2.1)
|
46
46
|
awesome_print
|
47
|
+
easycov
|
47
48
|
growl
|
48
49
|
listen
|
49
50
|
simplecov
|
50
51
|
simplecov-console
|
51
|
-
single_test
|
52
|
-
turn
|
53
52
|
|
54
53
|
GEM
|
55
54
|
remote: https://rubygems.org/
|
56
55
|
specs:
|
57
56
|
addressable (2.3.5)
|
58
|
-
ansi (1.4.3)
|
59
57
|
awesome_print (1.2.0)
|
60
|
-
bixby-common (0.4.
|
58
|
+
bixby-common (0.4.6)
|
61
59
|
api-auth
|
62
60
|
faye-websocket
|
63
61
|
httpi
|
64
62
|
logging
|
65
63
|
multi_json
|
64
|
+
semver2
|
66
65
|
builder (3.2.2)
|
66
|
+
celluloid (0.15.2)
|
67
|
+
timers (~> 1.1.0)
|
67
68
|
coderay (1.0.9)
|
68
69
|
colorize (0.6.0)
|
69
70
|
columnize (0.3.6)
|
71
|
+
coveralls (0.7.0)
|
72
|
+
multi_json (~> 1.3)
|
73
|
+
rest-client
|
74
|
+
simplecov (>= 0.7)
|
75
|
+
term-ansicolor
|
76
|
+
thor
|
70
77
|
crack (0.4.1)
|
71
78
|
safe_yaml (~> 0.9.0)
|
72
|
-
curb (0.8.
|
73
|
-
debugger (1.6.
|
79
|
+
curb (0.8.5)
|
80
|
+
debugger (1.6.2)
|
74
81
|
columnize (>= 0.3.1)
|
75
82
|
debugger-linecache (~> 1.2.0)
|
76
83
|
debugger-ruby_core_source (~> 1.2.3)
|
@@ -79,9 +86,11 @@ GEM
|
|
79
86
|
debugger (~> 1)
|
80
87
|
pry (>= 0.9.9)
|
81
88
|
debugger-ruby_core_source (1.2.3)
|
82
|
-
easycov (0.
|
89
|
+
easycov (0.3.1)
|
83
90
|
multi_json
|
84
91
|
simplecov
|
92
|
+
simplecov-console
|
93
|
+
simplecov-html
|
85
94
|
eventmachine (1.0.3)
|
86
95
|
faraday (0.8.8)
|
87
96
|
multipart-post (~> 1.2.0)
|
@@ -89,6 +98,7 @@ GEM
|
|
89
98
|
eventmachine (>= 0.12.0)
|
90
99
|
websocket-driver (>= 0.3.0)
|
91
100
|
ffi (1.9.0)
|
101
|
+
fuzzy_file_finder (1.0.4)
|
92
102
|
git (1.2.6)
|
93
103
|
github_api (0.10.1)
|
94
104
|
addressable
|
@@ -109,20 +119,21 @@ GEM
|
|
109
119
|
json (1.8.0)
|
110
120
|
jwt (0.1.8)
|
111
121
|
multi_json (>= 1.5)
|
112
|
-
listen (
|
122
|
+
listen (2.0.0)
|
123
|
+
celluloid (>= 0.15.1)
|
113
124
|
rb-fsevent (>= 0.9.3)
|
114
125
|
rb-inotify (>= 0.9)
|
115
|
-
rb-kqueue (>= 0.2)
|
116
126
|
little-plugger (1.1.3)
|
117
127
|
logging (1.8.1)
|
118
128
|
little-plugger (>= 1.1.3)
|
119
129
|
multi_json (>= 1.3.6)
|
120
130
|
metaclass (0.0.1)
|
121
131
|
method_source (0.8.2)
|
132
|
+
mime-types (1.25)
|
122
133
|
mixlib-shellout (1.2.0)
|
123
134
|
mocha (0.14.0)
|
124
135
|
metaclass (~> 0.0.1)
|
125
|
-
multi_json (1.8.
|
136
|
+
multi_json (1.8.1)
|
126
137
|
multi_xml (0.5.5)
|
127
138
|
multipart-post (1.2.0)
|
128
139
|
nokogiri (1.5.10)
|
@@ -133,7 +144,7 @@ GEM
|
|
133
144
|
multi_json (~> 1.0)
|
134
145
|
multi_xml (~> 0.5)
|
135
146
|
rack (~> 1.2)
|
136
|
-
oj (2.1.
|
147
|
+
oj (2.1.6)
|
137
148
|
pry (0.9.12.2)
|
138
149
|
coderay (~> 1.0.5)
|
139
150
|
method_source (~> 0.8)
|
@@ -145,28 +156,30 @@ GEM
|
|
145
156
|
rb-fsevent (0.9.3)
|
146
157
|
rb-inotify (0.9.2)
|
147
158
|
ffi (>= 0.5.0)
|
148
|
-
rb-kqueue (0.2.0)
|
149
|
-
ffi (>= 0.5.0)
|
150
159
|
rdoc (4.0.1)
|
151
160
|
json (~> 1.4)
|
152
161
|
redcarpet (3.0.0)
|
162
|
+
rest-client (1.6.7)
|
163
|
+
mime-types (>= 1.16)
|
153
164
|
rubyntlm (0.3.4)
|
154
|
-
safe_yaml (0.9.
|
155
|
-
|
165
|
+
safe_yaml (0.9.7)
|
166
|
+
semver2 (3.3.2)
|
167
|
+
simplecov-console (0.1.3)
|
156
168
|
colorize
|
157
169
|
hirb
|
158
170
|
simplecov
|
159
171
|
simplecov-html (0.7.1)
|
160
|
-
single_test (0.6.0)
|
161
|
-
rake
|
162
172
|
slop (3.4.6)
|
163
|
-
|
164
|
-
|
165
|
-
|
173
|
+
term-ansicolor (1.2.2)
|
174
|
+
tins (~> 0.8)
|
175
|
+
thor (0.18.1)
|
176
|
+
timers (1.1.0)
|
177
|
+
tins (0.11.0)
|
178
|
+
webmock (1.14.0)
|
166
179
|
addressable (>= 2.2.7)
|
167
180
|
crack (>= 0.3.2)
|
168
181
|
websocket-driver (0.3.0)
|
169
|
-
yard (0.8.7)
|
182
|
+
yard (0.8.7.2)
|
170
183
|
|
171
184
|
PLATFORMS
|
172
185
|
ruby
|
@@ -175,9 +188,11 @@ DEPENDENCIES
|
|
175
188
|
api-auth!
|
176
189
|
bixby-common
|
177
190
|
bundler
|
191
|
+
coveralls
|
178
192
|
curb
|
179
193
|
debugger
|
180
194
|
debugger-pry
|
195
|
+
fuzzy_file_finder
|
181
196
|
httpi
|
182
197
|
jeweler!
|
183
198
|
micron!
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bin/bixby
CHANGED
data/bixby-client.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: bixby-client 0.
|
5
|
+
# stub: bixby-client 0.3.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "bixby-client"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["Chetan Sarva"]
|
13
|
-
s.date = "2013-
|
13
|
+
s.date = "2013-10-30"
|
14
14
|
s.description = "Bixby Client"
|
15
15
|
s.email = "chetan@pixelcop.net"
|
16
16
|
s.executables = ["bixby"]
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
]
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
|
+
".travis.yml",
|
23
24
|
"Gemfile",
|
24
25
|
"Gemfile.lock",
|
25
26
|
"LICENSE",
|
@@ -29,8 +30,20 @@ Gem::Specification.new do |s|
|
|
29
30
|
"bin/bixby",
|
30
31
|
"bixby-client.gemspec",
|
31
32
|
"lib/bixby-client.rb",
|
33
|
+
"lib/bixby-client/app.rb",
|
34
|
+
"lib/bixby-client/app/command.rb",
|
35
|
+
"lib/bixby-client/app/commands/run.rb",
|
36
|
+
"lib/bixby-client/app/file_finder.rb",
|
32
37
|
"lib/bixby-client/client.rb",
|
38
|
+
"lib/bixby-client/client/version.rb",
|
33
39
|
"lib/bixby-client/command.rb",
|
40
|
+
"lib/bixby-client/model.rb",
|
41
|
+
"lib/bixby-client/model/agent.rb",
|
42
|
+
"lib/bixby-client/model/base.rb",
|
43
|
+
"lib/bixby-client/model/check.rb",
|
44
|
+
"lib/bixby-client/model/command.rb",
|
45
|
+
"lib/bixby-client/model/host.rb",
|
46
|
+
"lib/bixby-client/model/metric.rb",
|
34
47
|
"lib/bixby-client/modules.rb",
|
35
48
|
"lib/bixby-client/modules/inventory.rb",
|
36
49
|
"lib/bixby-client/modules/metrics.rb",
|
@@ -39,6 +52,8 @@ Gem::Specification.new do |s|
|
|
39
52
|
"lib/bixby-client/platform_util.rb",
|
40
53
|
"lib/bixby-client/script.rb",
|
41
54
|
"lib/bixby-client/script_util.rb",
|
55
|
+
"tasks/coverage.rake",
|
56
|
+
"tasks/coveralls.rake",
|
42
57
|
"tasks/jeweler.rake",
|
43
58
|
"tasks/test.rake",
|
44
59
|
"tasks/yard.rake",
|
@@ -62,7 +77,7 @@ Gem::Specification.new do |s|
|
|
62
77
|
s.homepage = "http://github.com/chetan/bixby-client"
|
63
78
|
s.licenses = ["MIT"]
|
64
79
|
s.require_paths = ["lib"]
|
65
|
-
s.rubygems_version = "2.1.
|
80
|
+
s.rubygems_version = "2.1.5"
|
66
81
|
s.summary = "Bixby Client"
|
67
82
|
|
68
83
|
if s.respond_to? :specification_version then
|
@@ -75,6 +90,7 @@ Gem::Specification.new do |s|
|
|
75
90
|
s.add_runtime_dependency(%q<httpi>, [">= 0"])
|
76
91
|
s.add_runtime_dependency(%q<curb>, [">= 0"])
|
77
92
|
s.add_runtime_dependency(%q<mixlib-shellout>, [">= 0"])
|
93
|
+
s.add_runtime_dependency(%q<fuzzy_file_finder>, [">= 0"])
|
78
94
|
s.add_runtime_dependency(%q<api-auth>, [">= 0"])
|
79
95
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
80
96
|
s.add_development_dependency(%q<redcarpet>, [">= 0"])
|
@@ -85,6 +101,7 @@ Gem::Specification.new do |s|
|
|
85
101
|
s.add_development_dependency(%q<debugger-pry>, [">= 0"])
|
86
102
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
87
103
|
s.add_development_dependency(%q<micron>, [">= 0"])
|
104
|
+
s.add_development_dependency(%q<coveralls>, [">= 0"])
|
88
105
|
s.add_development_dependency(%q<webmock>, [">= 0"])
|
89
106
|
s.add_development_dependency(%q<mocha>, [">= 0"])
|
90
107
|
s.add_development_dependency(%q<test_guard>, [">= 0"])
|
@@ -98,6 +115,7 @@ Gem::Specification.new do |s|
|
|
98
115
|
s.add_dependency(%q<httpi>, [">= 0"])
|
99
116
|
s.add_dependency(%q<curb>, [">= 0"])
|
100
117
|
s.add_dependency(%q<mixlib-shellout>, [">= 0"])
|
118
|
+
s.add_dependency(%q<fuzzy_file_finder>, [">= 0"])
|
101
119
|
s.add_dependency(%q<api-auth>, [">= 0"])
|
102
120
|
s.add_dependency(%q<yard>, [">= 0"])
|
103
121
|
s.add_dependency(%q<redcarpet>, [">= 0"])
|
@@ -108,6 +126,7 @@ Gem::Specification.new do |s|
|
|
108
126
|
s.add_dependency(%q<debugger-pry>, [">= 0"])
|
109
127
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
110
128
|
s.add_dependency(%q<micron>, [">= 0"])
|
129
|
+
s.add_dependency(%q<coveralls>, [">= 0"])
|
111
130
|
s.add_dependency(%q<webmock>, [">= 0"])
|
112
131
|
s.add_dependency(%q<mocha>, [">= 0"])
|
113
132
|
s.add_dependency(%q<test_guard>, [">= 0"])
|
@@ -122,6 +141,7 @@ Gem::Specification.new do |s|
|
|
122
141
|
s.add_dependency(%q<httpi>, [">= 0"])
|
123
142
|
s.add_dependency(%q<curb>, [">= 0"])
|
124
143
|
s.add_dependency(%q<mixlib-shellout>, [">= 0"])
|
144
|
+
s.add_dependency(%q<fuzzy_file_finder>, [">= 0"])
|
125
145
|
s.add_dependency(%q<api-auth>, [">= 0"])
|
126
146
|
s.add_dependency(%q<yard>, [">= 0"])
|
127
147
|
s.add_dependency(%q<redcarpet>, [">= 0"])
|
@@ -132,6 +152,7 @@ Gem::Specification.new do |s|
|
|
132
152
|
s.add_dependency(%q<debugger-pry>, [">= 0"])
|
133
153
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
134
154
|
s.add_dependency(%q<micron>, [">= 0"])
|
155
|
+
s.add_dependency(%q<coveralls>, [">= 0"])
|
135
156
|
s.add_dependency(%q<webmock>, [">= 0"])
|
136
157
|
s.add_dependency(%q<mocha>, [">= 0"])
|
137
158
|
s.add_dependency(%q<test_guard>, [">= 0"])
|
data/lib/bixby-client.rb
CHANGED
@@ -5,6 +5,7 @@ require "bixby-common"
|
|
5
5
|
|
6
6
|
require "bixby-client/platform_util"
|
7
7
|
require "bixby-client/script_util"
|
8
|
+
require "bixby-client/model"
|
8
9
|
require "bixby-client/modules"
|
9
10
|
require "bixby-client/command"
|
10
11
|
require "bixby-client/client"
|
@@ -27,7 +28,7 @@ module Bixby
|
|
27
28
|
private
|
28
29
|
|
29
30
|
def create_client
|
30
|
-
raise "
|
31
|
+
raise "BIXBY_HOME not set" if not root
|
31
32
|
|
32
33
|
config_file = Bixby.path("etc", "bixby.yml")
|
33
34
|
raise "#{config_file} not found" if not File.exists? config_file
|
@@ -0,0 +1,88 @@
|
|
1
|
+
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
require 'bixby-client'
|
5
|
+
require 'bixby-client/app/command'
|
6
|
+
|
7
|
+
module Bixby
|
8
|
+
class Client
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :app
|
12
|
+
end
|
13
|
+
|
14
|
+
class App
|
15
|
+
|
16
|
+
attr_reader :global_options, :command, :commands
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@global_options = {}
|
20
|
+
@commands = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
|
25
|
+
begin
|
26
|
+
options.order!(ARGV)
|
27
|
+
|
28
|
+
if global_options[:help] then
|
29
|
+
display_help()
|
30
|
+
end
|
31
|
+
|
32
|
+
rescue Exception => ex
|
33
|
+
exit if ex.kind_of? SystemExit
|
34
|
+
STDERR.puts "error: #{ex}"
|
35
|
+
STDERR.puts
|
36
|
+
STDERR.puts parser
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
subcmd = ARGV.shift
|
41
|
+
commands.each do |c|
|
42
|
+
if c.match(subcmd) then
|
43
|
+
ret = c.new.run(global_options, ARGV)
|
44
|
+
exit (ret || 0)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# if we reached here, no cmd given, show help?
|
49
|
+
display_help()
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def display_help
|
54
|
+
puts "Usage: bixby [global options] command [command options] [arguments...]"
|
55
|
+
puts
|
56
|
+
puts "GLOBAL OPTIONS"
|
57
|
+
puts options.summarize
|
58
|
+
puts
|
59
|
+
|
60
|
+
puts "COMMANDS"
|
61
|
+
commands.each do |c|
|
62
|
+
puts " " + c.command_name + " - " + c.desc
|
63
|
+
end
|
64
|
+
|
65
|
+
exit 0
|
66
|
+
end
|
67
|
+
|
68
|
+
def options
|
69
|
+
@options ||= OptionParser.new do |opts|
|
70
|
+
opts.banner = nil
|
71
|
+
|
72
|
+
opts.on_tail("-v", "--verbose", "Enable verbose output") {
|
73
|
+
global_options[:verbose] = true
|
74
|
+
}
|
75
|
+
|
76
|
+
opts.on_tail("-h", "--help", "Display this help") {
|
77
|
+
global_options[:help] = true
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
Bixby::Client.app = Bixby::Client::App.new
|
87
|
+
require 'bixby-client/app/commands/run'
|
88
|
+
Bixby::Client.app.run
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
module Bixby
|
3
|
+
module App
|
4
|
+
class Command
|
5
|
+
|
6
|
+
def self.command_name(str=nil)
|
7
|
+
@command_name = str if !str.nil?
|
8
|
+
@command_name ||= self.name.split(/::/).last.downcase
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.desc(str=nil)
|
12
|
+
@desc = str if !str.nil?
|
13
|
+
@desc
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.match(str)
|
17
|
+
command_name == str
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.options
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
require 'bixby-client/app/file_finder'
|
3
|
+
|
4
|
+
module Bixby
|
5
|
+
module App
|
6
|
+
module Commands
|
7
|
+
|
8
|
+
class Run < Command
|
9
|
+
|
10
|
+
command_name "run"
|
11
|
+
desc "Run a command in the repository"
|
12
|
+
|
13
|
+
def run(global_options, argv)
|
14
|
+
|
15
|
+
str = argv.shift
|
16
|
+
scripts = FileFinder.new(Bixby.repo).find_script(str)
|
17
|
+
|
18
|
+
if scripts.kind_of?(Array)
|
19
|
+
if scripts.size > 1 then
|
20
|
+
$stderr.puts "Found #{scripts.size} scripts matching '#{str}'. Please be more explicit"
|
21
|
+
scripts.each do |s|
|
22
|
+
puts " * #{s}"
|
23
|
+
end
|
24
|
+
return 1
|
25
|
+
elsif scripts.empty? then
|
26
|
+
$stderr.puts "No scripts matched '#{str}'. Try again"
|
27
|
+
return 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
setup_env()
|
32
|
+
exec(scripts.shift, *argv)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Setup the ENV for exec
|
36
|
+
def setup_env
|
37
|
+
# stick ourselves in RUBYLIB to speedup exec time
|
38
|
+
ENV["RUBYLIB"] = File.expand_path("../../../..", __FILE__)
|
39
|
+
ENV["RUBYOPT"] = '-rbixby-client/script'
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.options
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
end # Run
|
47
|
+
Bixby::Client.app.commands << Run
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
require "fuzzy_file_finder"
|
3
|
+
|
4
|
+
module Bixby
|
5
|
+
module App
|
6
|
+
class FileFinder
|
7
|
+
|
8
|
+
def initialize(root)
|
9
|
+
@root = root
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_script(script)
|
13
|
+
# try to locate script
|
14
|
+
return script if File.exists? script
|
15
|
+
|
16
|
+
# try relative path
|
17
|
+
s = File.expand_path(File.join(@root, script))
|
18
|
+
return s if File.exists? s
|
19
|
+
|
20
|
+
# try searching
|
21
|
+
matches = find_all_files(@root).find_all{ |f| f.include? script }.sort { |a,b|
|
22
|
+
ld(script, File.basename(a)) <=> ld(script, File.basename(b))
|
23
|
+
}
|
24
|
+
|
25
|
+
return matches if matches.size == 1 # only one result, just return it
|
26
|
+
|
27
|
+
# fuzzy search
|
28
|
+
fuzzy_matches = FuzzyFileFinder.new(@root).find(script.dup).
|
29
|
+
sort_by { |m| -m[:score] }.
|
30
|
+
map{ |f| f[:path] }.
|
31
|
+
find_all{ |f| keep?(f, @root) }
|
32
|
+
|
33
|
+
# return the union of all unique matches
|
34
|
+
return fuzzy_matches + (matches - fuzzy_matches)
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_all_files(path)
|
38
|
+
ret = []
|
39
|
+
ret += Dir.glob(File.join(path, "**/**")).find_all{ |f|
|
40
|
+
# select only actual script files to look at
|
41
|
+
if File.symlink? f then
|
42
|
+
ret << find_all_files(File.expand_path(f))
|
43
|
+
end
|
44
|
+
|
45
|
+
keep?(f, path)
|
46
|
+
}
|
47
|
+
|
48
|
+
return ret.flatten
|
49
|
+
end
|
50
|
+
|
51
|
+
def keep?(f, path)
|
52
|
+
!File.directory? f and
|
53
|
+
f !~ /\.(json|test.*)|\/digest$/ and
|
54
|
+
File.dirname(f) != path and
|
55
|
+
File.dirname(f) !~ /\/(test|lib)$/
|
56
|
+
end
|
57
|
+
|
58
|
+
# Calculate the levenshtein distance between two strings
|
59
|
+
#
|
60
|
+
# via https://github.com/akirahrkw/levenshtein-distance
|
61
|
+
# http://en.wikipedia.org/wiki/Levenshtein_distance
|
62
|
+
def levenshtein_distance(a, b)
|
63
|
+
a_len = a.length
|
64
|
+
b_len = b.length
|
65
|
+
d = Array.new(a_len + 1).map! {
|
66
|
+
Array.new(b_len + 1).map!{
|
67
|
+
0
|
68
|
+
}
|
69
|
+
}
|
70
|
+
(a_len + 1).times { |i| d[i][0] = i }
|
71
|
+
(b_len + 1).times { |i| d[0][i] = i }
|
72
|
+
|
73
|
+
for i in 1..(a_len)
|
74
|
+
for j in 1..(b_len)
|
75
|
+
cost = (a[i - 1] == b[j - 1]) ? 0 : 1
|
76
|
+
d[i][j] = [ d[i-1][j] + 1 , d[i][j-1] + 1 ,d[i-1][j-1] + cost].min
|
77
|
+
end
|
78
|
+
end
|
79
|
+
d[-1][-1]
|
80
|
+
end
|
81
|
+
alias_method :ld, :levenshtein_distance
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/bixby-client/client.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
require "api-auth"
|
3
3
|
require "curb"
|
4
4
|
|
5
|
+
require "bixby-client/client/version"
|
6
|
+
|
5
7
|
module Bixby
|
6
8
|
|
7
9
|
# Implements the Bixby client API
|
@@ -68,6 +70,20 @@ module Bixby
|
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
73
|
+
# Sign the given request
|
74
|
+
#
|
75
|
+
# @param [HTTPI::Request] request
|
76
|
+
def sign_http_request(request)
|
77
|
+
ApiAuth.sign!(request, @access_key, @secret_key)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Get the manager URI
|
81
|
+
#
|
82
|
+
# @return [String]
|
83
|
+
def manager_uri
|
84
|
+
Bixby.manager_uri
|
85
|
+
end
|
86
|
+
|
71
87
|
|
72
88
|
private
|
73
89
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
module Bixby
|
3
|
+
module Model
|
4
|
+
class Base
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def get(url)
|
9
|
+
req = HTTPI::Request.new(api_uri(url))
|
10
|
+
req.headers["Content-Type"] = "application/json"
|
11
|
+
req.headers["Accept"] = "application/json" # temp workaround, manager should always return JSON on REST urls
|
12
|
+
Bixby.client.sign_http_request(req)
|
13
|
+
res = HTTPI.get(req)
|
14
|
+
if res.error? then
|
15
|
+
raise "error" # TODO
|
16
|
+
end
|
17
|
+
|
18
|
+
data = MultiJson.load(res.body)
|
19
|
+
if data.kind_of? Array then
|
20
|
+
return data.map{ |d| self.new(d) }
|
21
|
+
else
|
22
|
+
return self.new(d)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def api_uri(*args)
|
27
|
+
if args.first !~ %r{^/rest/} then
|
28
|
+
args.unshift "/rest#{args.shift}"
|
29
|
+
end
|
30
|
+
URI.join(Bixby.client.manager_uri, *args).to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
end # self
|
34
|
+
|
35
|
+
def initialize(hash=nil)
|
36
|
+
return if hash.nil?
|
37
|
+
|
38
|
+
hash.each do |k,v|
|
39
|
+
instance_variable_set("@#{k}", v)
|
40
|
+
next if self.respond_to?(k.to_sym)
|
41
|
+
code = <<-EOF
|
42
|
+
def #{k}()
|
43
|
+
@#{k}
|
44
|
+
end
|
45
|
+
EOF
|
46
|
+
eval(code)
|
47
|
+
end
|
48
|
+
|
49
|
+
def [](key)
|
50
|
+
if self.respond_to?(key.to_sym) then
|
51
|
+
return self.send(key.to_sym)
|
52
|
+
end
|
53
|
+
return nil
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
module Bixby
|
3
|
+
module Model
|
4
|
+
|
5
|
+
class Metric < Base
|
6
|
+
|
7
|
+
def self.list(host_id)
|
8
|
+
get("/hosts/#{host_id}/checks")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.list_for_check(host_id, check_id)
|
12
|
+
get("/hosts/#{host_id}/checks/#{check_id}/metrics")
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find(id)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/tasks/coverage.rake
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
# for reporting to coveralls
|
3
|
+
require "coveralls"
|
4
|
+
desc "Report coverage to coveralls"
|
5
|
+
task :coveralls do
|
6
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
7
|
+
if File.exists? File.join(EasyCov.path, ".resultset.json") then
|
8
|
+
SimpleCov::ResultMerger.merged_result.format!
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bixby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chetan Sarva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bixby-common
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fuzzy_file_finder
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: api-auth
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -234,6 +248,20 @@ dependencies:
|
|
234
248
|
- - '>='
|
235
249
|
- !ruby/object:Gem::Version
|
236
250
|
version: '0'
|
251
|
+
- !ruby/object:Gem::Dependency
|
252
|
+
name: coveralls
|
253
|
+
requirement: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - '>='
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: '0'
|
258
|
+
type: :development
|
259
|
+
prerelease: false
|
260
|
+
version_requirements: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - '>='
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: '0'
|
237
265
|
- !ruby/object:Gem::Dependency
|
238
266
|
name: webmock
|
239
267
|
requirement: !ruby/object:Gem::Requirement
|
@@ -328,6 +356,7 @@ extra_rdoc_files:
|
|
328
356
|
- README.rdoc
|
329
357
|
files:
|
330
358
|
- .document
|
359
|
+
- .travis.yml
|
331
360
|
- Gemfile
|
332
361
|
- Gemfile.lock
|
333
362
|
- LICENSE
|
@@ -337,8 +366,20 @@ files:
|
|
337
366
|
- bin/bixby
|
338
367
|
- bixby-client.gemspec
|
339
368
|
- lib/bixby-client.rb
|
369
|
+
- lib/bixby-client/app.rb
|
370
|
+
- lib/bixby-client/app/command.rb
|
371
|
+
- lib/bixby-client/app/commands/run.rb
|
372
|
+
- lib/bixby-client/app/file_finder.rb
|
340
373
|
- lib/bixby-client/client.rb
|
374
|
+
- lib/bixby-client/client/version.rb
|
341
375
|
- lib/bixby-client/command.rb
|
376
|
+
- lib/bixby-client/model.rb
|
377
|
+
- lib/bixby-client/model/agent.rb
|
378
|
+
- lib/bixby-client/model/base.rb
|
379
|
+
- lib/bixby-client/model/check.rb
|
380
|
+
- lib/bixby-client/model/command.rb
|
381
|
+
- lib/bixby-client/model/host.rb
|
382
|
+
- lib/bixby-client/model/metric.rb
|
342
383
|
- lib/bixby-client/modules.rb
|
343
384
|
- lib/bixby-client/modules/inventory.rb
|
344
385
|
- lib/bixby-client/modules/metrics.rb
|
@@ -347,6 +388,8 @@ files:
|
|
347
388
|
- lib/bixby-client/platform_util.rb
|
348
389
|
- lib/bixby-client/script.rb
|
349
390
|
- lib/bixby-client/script_util.rb
|
391
|
+
- tasks/coverage.rake
|
392
|
+
- tasks/coveralls.rake
|
350
393
|
- tasks/jeweler.rake
|
351
394
|
- tasks/test.rake
|
352
395
|
- tasks/yard.rake
|
@@ -386,7 +429,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
386
429
|
version: '0'
|
387
430
|
requirements: []
|
388
431
|
rubyforge_project:
|
389
|
-
rubygems_version: 2.1.
|
432
|
+
rubygems_version: 2.1.5
|
390
433
|
signing_key:
|
391
434
|
specification_version: 4
|
392
435
|
summary: Bixby Client
|