sensu-cli 0.2.2 → 0.2.3
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.
- checksums.yaml +15 -0
- data/bin/sensu +1 -3
- data/bin/sensu-cli +1 -3
- data/lib/sensu-cli/api.rb +5 -1
- data/lib/sensu-cli/base.rb +11 -7
- data/lib/sensu-cli/cli.rb +10 -8
- data/lib/sensu-cli/pretty.rb +82 -50
- data/lib/sensu-cli/settings.rb +2 -2
- data/lib/sensu-cli/version.rb +1 -1
- data/sensu-cli.gemspec +4 -0
- metadata +47 -15
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjBmYzYyYmQ2MzI3Y2M1YmRjNjU4OWQ5NDg3NmE3Yzg0M2UyODE4ZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzhmYThlNmExMGM2NzlkMmMyYWZmZDY4YmY3MGY3NGVjMTExMjJjMw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjkxYWI5MjRlOTY1NzY2NGUxZTNhN2JhNmViYzRlYTdmYjQ3MDYwZGZhOWRm
|
10
|
+
NzNmZDlmMjFlY2QyMWM3ZTBkYjAzMDhhNTYxMjRkMmM4OWU0ZDBiODZkM2M2
|
11
|
+
MzAxODU0ZGM1MDliMzI3MDQyOWRlYWJkYWI4ZDhhMzNkNDlkYTA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDA1ZjIwYjFiYjYxOGE5YzAxNDQxNWQ3Y2M5NmFkNjk4OGM4YTVhMTAwMzg4
|
14
|
+
NTlkODA5YzRhNzgxNTY0NjdiOTFkZmQyZGZhNGY2NmM1N2U0YjEyYjgwMjg0
|
15
|
+
MDU5MWM5Y2Q2M2FmYThiOTQwZDIyOGM0ZmJiMjA2NzhhYmE0NTQ=
|
data/bin/sensu
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
unless
|
3
|
-
$: << File.dirname(__FILE__) + '/../lib'
|
4
|
-
end
|
2
|
+
$LOAD_PATH << File.dirname(__FILE__) + '/../lib' unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib/')
|
5
3
|
|
6
4
|
require 'sensu-cli'
|
7
5
|
sensu = SensuCli::Base.new
|
data/bin/sensu-cli
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
unless
|
3
|
-
$: << File.dirname(__FILE__) + '/../lib'
|
4
|
-
end
|
2
|
+
$LOAD_PATH << File.dirname(__FILE__) + '/../lib' unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib/')
|
5
3
|
|
6
4
|
require 'sensu-cli'
|
7
5
|
sensu = SensuCli::Base.new
|
data/lib/sensu-cli/api.rb
CHANGED
@@ -53,7 +53,11 @@ module SensuCli
|
|
53
53
|
when '404'
|
54
54
|
puts 'The item did not exist.'.color(:cyan)
|
55
55
|
else
|
56
|
-
|
56
|
+
if command == 'health'
|
57
|
+
puts 'Sensu is not healthy.'.color(:red)
|
58
|
+
else
|
59
|
+
puts "There was an error while trying to complete your request. Response code: #{code}".color(:red)
|
60
|
+
end
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
data/lib/sensu-cli/base.rb
CHANGED
@@ -3,10 +3,9 @@ module SensuCli
|
|
3
3
|
|
4
4
|
def setup
|
5
5
|
clis = Cli.new
|
6
|
-
cli = clis.global
|
7
|
-
@format = cli[:fields][:format] || 'long'
|
6
|
+
@cli = clis.global
|
8
7
|
settings
|
9
|
-
api_path(cli)
|
8
|
+
api_path(@cli)
|
10
9
|
make_call
|
11
10
|
end
|
12
11
|
|
@@ -26,7 +25,7 @@ module SensuCli
|
|
26
25
|
|
27
26
|
def api_path(cli)
|
28
27
|
p = PathCreator.new
|
29
|
-
p.respond_to?(cli[:command]) ? path = p.send(cli[:command], cli) : (puts 'Something Bad Happened'; exit)
|
28
|
+
p.respond_to?(cli[:command]) ? path = p.send(cli[:command], cli) : (puts 'Something Bad Happened'; exit) # rubocop:disable Semicolon
|
30
29
|
@api = { :path => path[:path], :method => cli[:method], :command => cli[:command], :payload => (path[:payload] || false) }
|
31
30
|
end
|
32
31
|
|
@@ -46,12 +45,17 @@ module SensuCli
|
|
46
45
|
msg = api.response(res.code, res.body, @api[:command])
|
47
46
|
if res.code != '200'
|
48
47
|
exit
|
49
|
-
elsif @format == 'single'
|
50
|
-
Pretty.
|
48
|
+
elsif @cli[:fields][:format] == 'single'
|
49
|
+
Pretty.single(msg)
|
50
|
+
Pretty.count(msg)
|
51
|
+
elsif @cli[:fields][:format] == 'table'
|
52
|
+
endpoint = @api[:command]
|
53
|
+
fields = nil || @cli[:fields][:fields]
|
54
|
+
Pretty.table(msg, endpoint, fields)
|
51
55
|
else
|
52
56
|
Pretty.print(msg)
|
57
|
+
Pretty.count(msg)
|
53
58
|
end
|
54
|
-
Pretty.count(msg)
|
55
59
|
end
|
56
60
|
|
57
61
|
end
|
data/lib/sensu-cli/cli.rb
CHANGED
@@ -93,7 +93,7 @@ module SensuCli
|
|
93
93
|
stop_on SUB_COMMANDS
|
94
94
|
end
|
95
95
|
|
96
|
-
|
96
|
+
Trollop::with_standard_exception_handling global_opts do
|
97
97
|
global_opts.parse ARGV
|
98
98
|
raise Trollop::HelpNeeded if ARGV.empty? # show help screen
|
99
99
|
end
|
@@ -103,7 +103,7 @@ module SensuCli
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def explode(opts)
|
106
|
-
|
106
|
+
Trollop::with_standard_exception_handling opts do
|
107
107
|
raise Trollop::HelpNeeded # show help screen
|
108
108
|
end
|
109
109
|
end
|
@@ -113,7 +113,7 @@ module SensuCli
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def parser(cli)
|
116
|
-
|
116
|
+
Trollop::Parser.new do
|
117
117
|
banner Cli.const_get("#{cli}_BANNER")
|
118
118
|
stop_on Cli.const_get("#{cli}_COMMANDS")
|
119
119
|
end
|
@@ -136,9 +136,11 @@ module SensuCli
|
|
136
136
|
p = Trollop::options do
|
137
137
|
opt :limit, 'The number if clients to return', :short => 'l', :type => :string
|
138
138
|
opt :offset, 'The number of clients to offset before returning', :short => 'o', :type => :string
|
139
|
-
opt :format, 'Available formats; single
|
139
|
+
opt :format, 'Available formats; single, table', :short => 'f', :type => :string
|
140
|
+
opt :fields, 'Fields for table ouput: -F name,address,subscriptions', :short => 'F', :type => :string
|
140
141
|
end
|
141
|
-
Trollop::die :format, 'Available optional formats: single'.color(:red) if p[:format] && p[:format] != 'single'
|
142
|
+
Trollop::die :format, 'Available optional formats: single, table'.color(:red) if p[:format] != 'table' && p[:format] != 'single' && p[:format]
|
143
|
+
Trollop::die :fields, 'Fields must be used in conjunction with --format table'.color(:red) if p[:format] != 'table' && p[:fields]
|
142
144
|
Trollop::die :offset, 'Offset depends on the limit option --limit ( -l )'.color(:red) if p[:offset] && !p[:limit]
|
143
145
|
{ :command => 'clients', :method => 'Get', :fields => p }
|
144
146
|
when 'delete'
|
@@ -165,7 +167,7 @@ module SensuCli
|
|
165
167
|
end
|
166
168
|
|
167
169
|
def health
|
168
|
-
|
170
|
+
parser('HEALTH')
|
169
171
|
p = Trollop::options do
|
170
172
|
opt :consumers, 'The minimum number of consumers', :short => 'c', :type => :string, :required => true
|
171
173
|
opt :messages, 'The maximum number of messages', :short => 'm', :type => :string, :required => true
|
@@ -199,9 +201,9 @@ module SensuCli
|
|
199
201
|
case command
|
200
202
|
when 'list'
|
201
203
|
p = Trollop::options do
|
202
|
-
opt :format, 'Available formats; single
|
204
|
+
opt :format, 'Available formats; single, table', :short => 'f', :type => :string
|
203
205
|
end
|
204
|
-
Trollop::die :format, 'Available optional formats: single'.color(:red) if p[:format] && p[:format] != 'single'
|
206
|
+
Trollop::die :format, 'Available optional formats: single, table'.color(:red) if p[:format] != 'table' && p[:format] != 'single' && p[:format]
|
205
207
|
{ :command => 'events', :method => 'Get', :fields => p }
|
206
208
|
when 'show'
|
207
209
|
p = Trollop::options do
|
data/lib/sensu-cli/pretty.rb
CHANGED
@@ -1,77 +1,109 @@
|
|
1
1
|
require 'rainbow'
|
2
|
+
require 'hirb'
|
3
|
+
require 'terminfo'
|
2
4
|
|
3
5
|
module SensuCli
|
4
6
|
class Pretty
|
7
|
+
class << self
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
def print(res)
|
10
|
+
if !res.empty?
|
11
|
+
if res.is_a?(Hash)
|
12
|
+
res.each do |key, value|
|
13
|
+
puts "#{key}: ".color(:cyan) + "#{value}".color(:green)
|
14
|
+
end
|
15
|
+
elsif res.is_a?(Array)
|
16
|
+
res.each do |item|
|
17
|
+
puts '-------'.color(:yellow)
|
18
|
+
if item.is_a?(Hash)
|
19
|
+
item.each do |key, value|
|
20
|
+
puts "#{key}: ".color(:cyan) + "#{value}".color(:green)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
puts item.to_s.color(:cyan)
|
18
24
|
end
|
19
|
-
else
|
20
|
-
puts item.to_s.color(:cyan)
|
21
25
|
end
|
22
26
|
end
|
27
|
+
else
|
28
|
+
self.no_values
|
23
29
|
end
|
24
|
-
|
30
|
+
end
|
31
|
+
|
32
|
+
def count(res)
|
33
|
+
res.is_a?(Hash) ? count = res.length : count = res.count
|
34
|
+
puts "#{count} total items".color(:yellow) if count
|
35
|
+
end
|
36
|
+
|
37
|
+
def clean(thing)
|
38
|
+
thing = thing.gsub("\n", '/\n') if thing.is_a?(String)
|
39
|
+
thing
|
40
|
+
end
|
41
|
+
|
42
|
+
def no_values
|
25
43
|
puts 'no values for this request'.color(:cyan)
|
26
44
|
end
|
27
|
-
end
|
28
45
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
46
|
+
def single(res)
|
47
|
+
if !res.empty?
|
48
|
+
if res.is_a?(Array)
|
49
|
+
keys = res.map { |item| item.keys }.flatten.uniq.sort
|
33
50
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
51
|
+
# Remove fields with spaces (breaks awkage)
|
52
|
+
keys.select! do |key|
|
53
|
+
res.none? { |item| item[key].to_s.include?(' ') }
|
54
|
+
end
|
38
55
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
56
|
+
# Find max value lengths
|
57
|
+
value_lengths = {}
|
58
|
+
keys.each do |key|
|
59
|
+
max_value_length = res.map { |item| item[key].to_s.length }.max
|
60
|
+
value_lengths[key] = [max_value_length, key.length].max
|
61
|
+
end
|
43
62
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
63
|
+
# Print header
|
64
|
+
format = keys.map { |key| "%-#{value_lengths[key]}s" }.join(' ')
|
65
|
+
puts sprintf(format, *keys)
|
48
66
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
67
|
+
# Print value rows
|
68
|
+
res.each do |item|
|
69
|
+
if item.is_a?(Hash)
|
70
|
+
values = keys.map { |key| item[key] }
|
71
|
+
format = keys.map { |key| "%-#{value_lengths[key]}s" }.join(' ')
|
72
|
+
puts sprintf(format, *values)
|
73
|
+
else
|
74
|
+
puts item.to_s.color(:cyan)
|
75
|
+
end
|
76
|
+
end
|
54
77
|
end
|
78
|
+
else
|
79
|
+
self.no_values
|
80
|
+
end
|
81
|
+
end
|
55
82
|
|
56
|
-
|
57
|
-
|
58
|
-
|
83
|
+
def parse_fields(fields)
|
84
|
+
fields.split(',')
|
85
|
+
end
|
59
86
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
87
|
+
def table(res, endpoint, fields = nil)
|
88
|
+
if !res.empty?
|
89
|
+
if res.is_a?(Array)
|
90
|
+
terminal_size = TermInfo.screen_size
|
91
|
+
if endpoint == 'events'
|
92
|
+
keys = %w[check client status flapping occurrences handlers issued output]
|
66
93
|
else
|
67
|
-
|
94
|
+
if fields
|
95
|
+
keys = self.parse_fields(fields)
|
96
|
+
else
|
97
|
+
keys = res.map { |item| item.keys }.flatten.uniq
|
98
|
+
end
|
68
99
|
end
|
100
|
+
puts Hirb::Helpers::AutoTable.render(res, { :max_width => terminal_size[1], :fields => keys })
|
69
101
|
end
|
102
|
+
else
|
103
|
+
self.no_values
|
70
104
|
end
|
71
|
-
else
|
72
|
-
puts 'no values for this request'.color(:cyan)
|
73
105
|
end
|
74
|
-
end
|
75
106
|
|
107
|
+
end
|
76
108
|
end
|
77
109
|
end
|
data/lib/sensu-cli/settings.rb
CHANGED
@@ -6,11 +6,11 @@ module SensuCli
|
|
6
6
|
class Settings
|
7
7
|
|
8
8
|
def is_file?(file)
|
9
|
-
!File.readable?(file) ? false : true
|
9
|
+
!File.readable?(file) ? false : true # rubocop:disable FavorUnlessOverNegatedIf
|
10
10
|
end
|
11
11
|
|
12
12
|
def create(directory, file)
|
13
|
-
FileUtils.mkdir_p(directory)
|
13
|
+
FileUtils.mkdir_p(directory) unless File.directory?(directory)
|
14
14
|
FileUtils.cp(File.join(File.dirname(__FILE__), '../../settings.example.rb'), file)
|
15
15
|
puts "We created the configuration file for you at #{file}. You can also place this in /etc/sensu/sensu-cli. Edit the settings as needed.".color(:red)
|
16
16
|
exit
|
data/lib/sensu-cli/version.rb
CHANGED
data/sensu-cli.gemspec
CHANGED
@@ -11,11 +11,15 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.has_rdoc = false
|
12
12
|
s.licenses = ['MIT','APACHE']
|
13
13
|
s.homepage ='http://github.com/agent462/sensu-cli'
|
14
|
+
|
14
15
|
s.add_dependency('rainbow', '1.1.4')
|
15
16
|
s.add_dependency('trollop', '2.0')
|
16
17
|
s.add_dependency('mixlib-config', '1.1.2')
|
18
|
+
s.add_dependency('hirb', '0.7.1')
|
19
|
+
s.add_dependency('ruby-terminfo', '0.1.1')
|
17
20
|
|
18
21
|
s.add_development_dependency('rspec')
|
22
|
+
s.add_development_dependency('rubocop')
|
19
23
|
|
20
24
|
s.files = Dir.glob('{bin,lib}/**/*') + %w[sensu-cli.gemspec README.md settings.example.rb]
|
21
25
|
s.executables = Dir.glob('bin/**/*').map { |file| File.basename(file) }
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bryan Brandau
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rainbow
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - '='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - '='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: trollop
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - '='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - '='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: mixlib-config
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - '='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,15 +48,41 @@ dependencies:
|
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - '='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: 1.1.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hirb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.7.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ruby-terminfo
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.1.1
|
62
83
|
- !ruby/object:Gem::Dependency
|
63
84
|
name: rspec
|
64
85
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
86
|
requirements:
|
67
87
|
- - ! '>='
|
68
88
|
- !ruby/object:Gem::Version
|
@@ -70,7 +90,20 @@ dependencies:
|
|
70
90
|
type: :development
|
71
91
|
prerelease: false
|
72
92
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
107
|
requirements:
|
75
108
|
- - ! '>='
|
76
109
|
- !ruby/object:Gem::Version
|
@@ -101,26 +134,25 @@ homepage: http://github.com/agent462/sensu-cli
|
|
101
134
|
licenses:
|
102
135
|
- MIT
|
103
136
|
- APACHE
|
137
|
+
metadata: {}
|
104
138
|
post_install_message:
|
105
139
|
rdoc_options: []
|
106
140
|
require_paths:
|
107
141
|
- lib
|
108
142
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
143
|
requirements:
|
111
144
|
- - ! '>='
|
112
145
|
- !ruby/object:Gem::Version
|
113
146
|
version: '0'
|
114
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
-
none: false
|
116
148
|
requirements:
|
117
149
|
- - ! '>='
|
118
150
|
- !ruby/object:Gem::Version
|
119
151
|
version: '0'
|
120
152
|
requirements: []
|
121
153
|
rubyforge_project:
|
122
|
-
rubygems_version:
|
154
|
+
rubygems_version: 2.0.3
|
123
155
|
signing_key:
|
124
|
-
specification_version:
|
156
|
+
specification_version: 4
|
125
157
|
summary: A command line utility for Sensu.
|
126
158
|
test_files: []
|