sensu-cli 0.2.1 → 0.2.2
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/lib/sensu-cli/api.rb +14 -13
- data/lib/sensu-cli/base.rb +6 -6
- data/lib/sensu-cli/cli.rb +64 -65
- data/lib/sensu-cli/editor.rb +2 -2
- data/lib/sensu-cli/path.rb +22 -22
- data/lib/sensu-cli/pretty.rb +12 -12
- data/lib/sensu-cli/settings.rb +2 -2
- data/lib/sensu-cli/version.rb +1 -1
- data/settings.example.rb +2 -2
- metadata +1 -1
data/lib/sensu-cli/api.rb
CHANGED
@@ -13,20 +13,21 @@ module SensuCli
|
|
13
13
|
http.use_ssl = true
|
14
14
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
15
15
|
end
|
16
|
+
proxy_header = { 'api-proxy' => 'true' }
|
16
17
|
case opts[:method]
|
17
18
|
when 'Get'
|
18
|
-
req = Net::HTTP::Get.new(opts[:path])
|
19
|
+
req = Net::HTTP::Get.new(opts[:path], initheader = proxy_header)
|
19
20
|
when 'Delete'
|
20
|
-
req = Net::HTTP::Delete.new(opts[:path])
|
21
|
+
req = Net::HTTP::Delete.new(opts[:path], initheader = proxy_header)
|
21
22
|
when 'Post'
|
22
|
-
req = Net::HTTP::Post.new(opts[:path],initheader = {'Content-Type' => 'application/json'})
|
23
|
+
req = Net::HTTP::Post.new(opts[:path], initheader = proxy_header.merge!({ 'Content-Type' => 'application/json' }))
|
23
24
|
req.body = opts[:payload]
|
24
25
|
end
|
25
26
|
req.basic_auth(opts[:user], opts[:password]) if opts[:user] && opts[:password]
|
26
27
|
begin
|
27
28
|
http.request(req)
|
28
29
|
rescue Timeout::Error
|
29
|
-
puts
|
30
|
+
puts 'HTTP request has timed out.'.color(:red)
|
30
31
|
exit
|
31
32
|
rescue StandardError => e
|
32
33
|
puts "An HTTP error occurred. Check your settings. #{e}".color(:red)
|
@@ -34,25 +35,25 @@ module SensuCli
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
def response(code,body,command=nil)
|
38
|
+
def response(code, body, command = nil)
|
38
39
|
case code
|
39
40
|
when '200'
|
40
41
|
JSON.parse(body)
|
41
42
|
when '201'
|
42
|
-
puts
|
43
|
+
puts 'The stash has been created.' if command == 'stashes' || command == 'silence'
|
43
44
|
when '202'
|
44
|
-
puts
|
45
|
+
puts 'The item was submitted for processing.'
|
45
46
|
when '204'
|
46
|
-
puts
|
47
|
-
puts
|
47
|
+
puts 'Sensu is healthy' if command == 'health'
|
48
|
+
puts 'The item was successfully deleted.' if command == 'aggregates' || command == 'stashes'
|
48
49
|
when '400'
|
49
|
-
puts
|
50
|
+
puts 'The payload is malformed.'.color(:red)
|
50
51
|
when '401'
|
51
|
-
puts
|
52
|
+
puts 'The request requires user authentication.'.color(:red)
|
52
53
|
when '404'
|
53
|
-
puts
|
54
|
+
puts 'The item did not exist.'.color(:cyan)
|
54
55
|
else
|
55
|
-
(command == 'health') ? (puts
|
56
|
+
(command == 'health') ? (puts 'Sensu is not healthy.'.color(:red)) : (puts "There was an error while trying to complete your request. Response code: #{code}".color(:red))
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
data/lib/sensu-cli/base.rb
CHANGED
@@ -4,7 +4,7 @@ module SensuCli
|
|
4
4
|
def setup
|
5
5
|
clis = Cli.new
|
6
6
|
cli = clis.global
|
7
|
-
@format = cli[:fields][:format] ||
|
7
|
+
@format = cli[:fields][:format] || 'long'
|
8
8
|
settings
|
9
9
|
api_path(cli)
|
10
10
|
make_call
|
@@ -13,21 +13,21 @@ module SensuCli
|
|
13
13
|
def settings
|
14
14
|
directory = "#{Dir.home}/.sensu"
|
15
15
|
file = "#{directory}/settings.rb"
|
16
|
-
alt =
|
16
|
+
alt = '/etc/sensu/sensu-cli/settings.rb'
|
17
17
|
settings = Settings.new
|
18
18
|
if settings.is_file?(file)
|
19
19
|
SensuCli::Config.from_file(file)
|
20
20
|
elsif settings.is_file?(alt)
|
21
21
|
SensuCli::Config.from_file(alt)
|
22
22
|
else
|
23
|
-
settings.create(directory,file)
|
23
|
+
settings.create(directory, file)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def api_path(cli)
|
28
28
|
p = PathCreator.new
|
29
|
-
p.respond_to?(cli[:command]) ? path = p.send(cli[:command], cli) : (puts
|
30
|
-
@api = {:path => path[:path], :method => cli[:method], :command => cli[:command], :payload => (path[:payload] || false)}
|
29
|
+
p.respond_to?(cli[:command]) ? path = p.send(cli[:command], cli) : (puts 'Something Bad Happened'; exit)
|
30
|
+
@api = { :path => path[:path], :method => cli[:method], :command => cli[:command], :payload => (path[:payload] || false) }
|
31
31
|
end
|
32
32
|
|
33
33
|
def make_call
|
@@ -46,7 +46,7 @@ module SensuCli
|
|
46
46
|
msg = api.response(res.code, res.body, @api[:command])
|
47
47
|
if res.code != '200'
|
48
48
|
exit
|
49
|
-
elsif @format ==
|
49
|
+
elsif @format == 'single'
|
50
50
|
Pretty.table(msg)
|
51
51
|
else
|
52
52
|
Pretty.print(msg)
|
data/lib/sensu-cli/cli.rb
CHANGED
@@ -10,10 +10,10 @@ module SensuCli
|
|
10
10
|
EVENT_COMMANDS = %w(list show delete)
|
11
11
|
STASH_COMMANDS = %w(list show delete create)
|
12
12
|
AGG_COMMANDS = %w(list show delete)
|
13
|
-
SIL_COMMANDS =
|
14
|
-
RES_COMMANDS =
|
15
|
-
INFO_COMMANDS =
|
16
|
-
HEALTH_COMMANDS =
|
13
|
+
SIL_COMMANDS = ''
|
14
|
+
RES_COMMANDS = ''
|
15
|
+
INFO_COMMANDS = ''
|
16
|
+
HEALTH_COMMANDS = ''
|
17
17
|
|
18
18
|
CLIENT_BANNER = <<-EOS.gsub(/^ {10}/, '')
|
19
19
|
** Client Commands **
|
@@ -49,7 +49,6 @@ module SensuCli
|
|
49
49
|
sensu-cli stash delete STASHPATH
|
50
50
|
sensu-cli stash create PATH\n\r
|
51
51
|
EOS
|
52
|
-
#apost '/stashes'
|
53
52
|
AGG_BANNER = <<-EOS.gsub(/^ {10}/, '')
|
54
53
|
** Aggregate Commands **
|
55
54
|
sensu-cli aggregate list (OPTIONS)
|
@@ -110,7 +109,7 @@ module SensuCli
|
|
110
109
|
end
|
111
110
|
|
112
111
|
def deep_merge(hash_one, hash_two)
|
113
|
-
hash_one.merge(hash_two) {|key, hash_one_item, hash_two_item| deep_merge(hash_one_item, hash_two_item)}
|
112
|
+
hash_one.merge(hash_two) { |key, hash_one_item, hash_two_item| deep_merge(hash_one_item, hash_two_item) }
|
114
113
|
end
|
115
114
|
|
116
115
|
def parser(cli)
|
@@ -120,7 +119,7 @@ module SensuCli
|
|
120
119
|
end
|
121
120
|
end
|
122
121
|
|
123
|
-
def explode_if_empty(opts,command)
|
122
|
+
def explode_if_empty(opts, command)
|
124
123
|
explode(opts) if ARGV.empty? && command != 'list'
|
125
124
|
end
|
126
125
|
|
@@ -129,172 +128,172 @@ module SensuCli
|
|
129
128
|
end
|
130
129
|
|
131
130
|
def client
|
132
|
-
opts = parser(
|
131
|
+
opts = parser('CLIENT')
|
133
132
|
command = next_argv
|
134
|
-
explode_if_empty(opts,command)
|
133
|
+
explode_if_empty(opts, command)
|
135
134
|
case command
|
136
135
|
when 'list'
|
137
136
|
p = Trollop::options do
|
138
|
-
opt :limit,
|
139
|
-
opt :offset,
|
140
|
-
opt :format,
|
137
|
+
opt :limit, 'The number if clients to return', :short => 'l', :type => :string
|
138
|
+
opt :offset, 'The number of clients to offset before returning', :short => 'o', :type => :string
|
139
|
+
opt :format, 'Available formats; single (single line formatting)', :short => 'f', :type => :string
|
141
140
|
end
|
142
|
-
Trollop::die :format,
|
143
|
-
Trollop::die :offset,
|
144
|
-
|
141
|
+
Trollop::die :format, 'Available optional formats: single'.color(:red) if p[:format] && p[:format] != 'single'
|
142
|
+
Trollop::die :offset, 'Offset depends on the limit option --limit ( -l )'.color(:red) if p[:offset] && !p[:limit]
|
143
|
+
{ :command => 'clients', :method => 'Get', :fields => p }
|
145
144
|
when 'delete'
|
146
145
|
p = Trollop::options
|
147
|
-
item = next_argv #the ARGV.shift needs to happen after Trollop::options to catch --help
|
148
|
-
deep_merge({:command => 'clients', :method => 'Delete', :fields => {:name => item}},{:fields => p})
|
146
|
+
item = next_argv # the ARGV.shift needs to happen after Trollop::options to catch --help
|
147
|
+
deep_merge({ :command => 'clients', :method => 'Delete', :fields => { :name => item } }, { :fields => p })
|
149
148
|
when 'show'
|
150
149
|
p = Trollop::options
|
151
150
|
item = next_argv
|
152
|
-
deep_merge({:command => 'clients', :method => 'Get', :fields => {:name => item}},{:fields => p})
|
151
|
+
deep_merge({ :command => 'clients', :method => 'Get', :fields => { :name => item } }, { :fields => p })
|
153
152
|
when 'history'
|
154
153
|
p = Trollop::options
|
155
154
|
item = next_argv
|
156
|
-
deep_merge({:command => 'clients', :method => 'Get', :fields => {:name => item, :history => true}},{:fields => p})
|
155
|
+
deep_merge({ :command => 'clients', :method => 'Get', :fields => { :name => item, :history => true } }, { :fields => p })
|
157
156
|
else
|
158
157
|
explode(opts)
|
159
158
|
end
|
160
159
|
end
|
161
160
|
|
162
161
|
def info
|
163
|
-
parser(
|
162
|
+
parser('INFO')
|
164
163
|
p = Trollop::options
|
165
|
-
|
164
|
+
{ :command => 'info', :method => 'Get', :fields => p }
|
166
165
|
end
|
167
166
|
|
168
167
|
def health
|
169
|
-
opts = parser(
|
168
|
+
opts = parser('HEALTH')
|
170
169
|
p = Trollop::options do
|
171
|
-
opt :consumers,
|
172
|
-
opt :messages,
|
170
|
+
opt :consumers, 'The minimum number of consumers', :short => 'c', :type => :string, :required => true
|
171
|
+
opt :messages, 'The maximum number of messages', :short => 'm', :type => :string, :required => true
|
173
172
|
end
|
174
|
-
|
173
|
+
{ :command => 'health', :method => 'Get', :fields => p }
|
175
174
|
end
|
176
175
|
|
177
176
|
def check
|
178
|
-
opts = parser(
|
177
|
+
opts = parser('CHECK')
|
179
178
|
command = next_argv
|
180
|
-
explode_if_empty(opts,command)
|
179
|
+
explode_if_empty(opts, command)
|
181
180
|
p = Trollop::options
|
182
181
|
item = next_argv
|
183
182
|
case command
|
184
183
|
when 'list'
|
185
|
-
|
184
|
+
{ :command => 'checks', :method => 'Get', :fields => p }
|
186
185
|
when 'show'
|
187
|
-
deep_merge({:command => 'checks', :method => 'Get', :fields => {:name => item}},{:fields => p})
|
186
|
+
deep_merge({ :command => 'checks', :method => 'Get', :fields => { :name => item } }, { :fields => p })
|
188
187
|
when 'request'
|
189
|
-
ARGV.empty? ? explode(opts) : subscribers = next_argv.split(
|
190
|
-
deep_merge({:command => 'checks', :method => 'Post', :fields => {:check => item, :subscribers => subscribers}},{:fields => p})
|
188
|
+
ARGV.empty? ? explode(opts) : subscribers = next_argv.split(',')
|
189
|
+
deep_merge({ :command => 'checks', :method => 'Post', :fields => { :check => item, :subscribers => subscribers } }, { :fields => p })
|
191
190
|
else
|
192
191
|
explode(opts)
|
193
192
|
end
|
194
193
|
end
|
195
194
|
|
196
195
|
def event
|
197
|
-
opts = parser(
|
196
|
+
opts = parser('EVENT')
|
198
197
|
command = next_argv
|
199
|
-
explode_if_empty(opts,command)
|
198
|
+
explode_if_empty(opts, command)
|
200
199
|
case command
|
201
200
|
when 'list'
|
202
201
|
p = Trollop::options do
|
203
|
-
opt :format,
|
202
|
+
opt :format, 'Available formats; single (single line formatting)', :short => 'f', :type => :string
|
204
203
|
end
|
205
|
-
Trollop::die :format,
|
206
|
-
|
204
|
+
Trollop::die :format, 'Available optional formats: single'.color(:red) if p[:format] && p[:format] != 'single'
|
205
|
+
{ :command => 'events', :method => 'Get', :fields => p }
|
207
206
|
when 'show'
|
208
207
|
p = Trollop::options do
|
209
|
-
opt :check,
|
208
|
+
opt :check, 'Returns the check associated with the client', :short => 'k', :type => :string
|
210
209
|
end
|
211
210
|
item = next_argv
|
212
|
-
deep_merge({:command => 'events', :method => 'Get', :fields => {:client => item}},{:fields => p})
|
211
|
+
deep_merge({ :command => 'events', :method => 'Get', :fields => { :client => item } }, { :fields => p })
|
213
212
|
when 'delete'
|
214
213
|
p = Trollop::options
|
215
214
|
item = next_argv
|
216
215
|
check = next_argv
|
217
216
|
explode(opts) if check == nil
|
218
|
-
deep_merge({:command => 'events', :method => 'Delete', :fields => {:client => item, :check => check}},{:fields => p})
|
217
|
+
deep_merge({ :command => 'events', :method => 'Delete', :fields => { :client => item, :check => check } }, { :fields => p })
|
219
218
|
else
|
220
219
|
explode(opts)
|
221
220
|
end
|
222
221
|
end
|
223
222
|
|
224
223
|
def stash
|
225
|
-
opts = parser(
|
224
|
+
opts = parser('STASH')
|
226
225
|
command = next_argv
|
227
|
-
explode_if_empty(opts,command)
|
226
|
+
explode_if_empty(opts, command)
|
228
227
|
case command
|
229
228
|
when 'list'
|
230
229
|
p = Trollop::options do
|
231
|
-
opt :limit,
|
232
|
-
opt :offset,
|
230
|
+
opt :limit, 'The number of stashes to return', :short => 'l', :type => :string
|
231
|
+
opt :offset, 'The number of stashes to offset before returning', :short => 'o', :type => :string
|
233
232
|
end
|
234
|
-
Trollop::die :offset,
|
235
|
-
|
233
|
+
Trollop::die :offset, 'Offset depends on the limit option --limit ( -l )'.color(:red) if p[:offset] && !p[:limit]
|
234
|
+
{ :command => 'stashes', :method => 'Get', :fields => p }
|
236
235
|
when 'show'
|
237
236
|
p = Trollop::options
|
238
237
|
item = next_argv
|
239
|
-
deep_merge({:command => 'stashes', :method => 'Get', :fields => {:path => item}},{:fields => p})
|
238
|
+
deep_merge({ :command => 'stashes', :method => 'Get', :fields => { :path => item } }, { :fields => p })
|
240
239
|
when 'delete'
|
241
240
|
p = Trollop::options
|
242
241
|
item = next_argv
|
243
|
-
deep_merge({:command => 'stashes', :method => 'Delete', :fields => {:path => item}},{:fields => p})
|
242
|
+
deep_merge({ :command => 'stashes', :method => 'Delete', :fields => { :path => item } }, { :fields => p })
|
244
243
|
when 'create'
|
245
244
|
p = Trollop::options
|
246
245
|
item = next_argv
|
247
|
-
deep_merge({:command => 'stashes', :method => 'Post', :fields => {:create => true, :create_path => item}},{:fields => p})
|
246
|
+
deep_merge({ :command => 'stashes', :method => 'Post', :fields => { :create => true, :create_path => item } }, { :fields => p })
|
248
247
|
else
|
249
248
|
explode(opts)
|
250
249
|
end
|
251
250
|
end
|
252
251
|
|
253
252
|
def aggregate
|
254
|
-
opts = parser(
|
253
|
+
opts = parser('AGG')
|
255
254
|
command = next_argv
|
256
|
-
explode_if_empty(opts,command)
|
255
|
+
explode_if_empty(opts, command)
|
257
256
|
case command
|
258
257
|
when 'list'
|
259
258
|
p = Trollop::options
|
260
|
-
|
259
|
+
{ :command => 'aggregates', :method => 'Get', :fields => p }
|
261
260
|
when 'show'
|
262
261
|
p = Trollop::options do
|
263
|
-
opt :id,
|
264
|
-
opt :limit,
|
265
|
-
opt :offset,
|
266
|
-
#opt :results,
|
262
|
+
opt :id, 'The id of the check issued.', :short => 'i', :type => :integer
|
263
|
+
opt :limit, 'The number of aggregates to return', :short => 'l', :type => :string
|
264
|
+
opt :offset, 'The number of aggregates to offset before returning', :short => 'o', :type => :string
|
265
|
+
# opt :results, 'Include the check results', :short => 'r', :type => :boolean
|
267
266
|
end
|
268
|
-
Trollop::die :offset,
|
267
|
+
Trollop::die :offset, 'Offset depends on the limit option --limit ( -l )'.color(:red) if p[:offset] && !p[:limit]
|
269
268
|
item = next_argv
|
270
|
-
deep_merge({:command => 'aggregates', :method => 'Get', :fields => {:check => item}},{:fields => p})
|
269
|
+
deep_merge({ :command => 'aggregates', :method => 'Get', :fields => { :check => item } }, { :fields => p })
|
271
270
|
when 'delete'
|
272
271
|
p = Trollop::options
|
273
272
|
item = next_argv
|
274
|
-
deep_merge({:command => 'aggregates', :method => 'Delete', :fields => {:check => item}},{:fields => p})
|
273
|
+
deep_merge({ :command => 'aggregates', :method => 'Delete', :fields => { :check => item } }, { :fields => p })
|
275
274
|
else
|
276
275
|
explode(opts)
|
277
276
|
end
|
278
277
|
end
|
279
278
|
|
280
279
|
def silence
|
281
|
-
opts = parser(
|
280
|
+
opts = parser('SIL')
|
282
281
|
p = Trollop::options do
|
283
|
-
opt :check,
|
284
|
-
opt :reason,
|
285
|
-
opt :expires,
|
282
|
+
opt :check, 'The check to silence (requires --client)', :short => 'k', :type => :string
|
283
|
+
opt :reason, 'The reason this check/node is being silenced', :short => 'r', :type => :string
|
284
|
+
opt :expires, 'The number of minutes the silenced event is valid (must use with check-stashes plugin)', :short => 'e', :type => :integer
|
286
285
|
end
|
287
286
|
command = next_argv
|
288
287
|
explode(opts) if command == nil
|
289
|
-
deep_merge({:command => 'silence', :method => 'Post', :fields => {:client => command}},{:fields => p})
|
288
|
+
deep_merge({ :command => 'silence', :method => 'Post', :fields => { :client => command } }, { :fields => p })
|
290
289
|
end
|
291
290
|
|
292
291
|
def resolve
|
293
|
-
opts = parser(
|
292
|
+
opts = parser('RES')
|
294
293
|
command = next_argv
|
295
294
|
p = Trollop::options
|
296
295
|
ARGV.empty? ? explode(opts) : check = next_argv
|
297
|
-
deep_merge({:command => 'resolve', :method => 'Post', :fields => {:client => command, :check => check}},{:fields => p})
|
296
|
+
deep_merge({ :command => 'resolve', :method => 'Post', :fields => { :client => command, :check => check } }, { :fields => p })
|
298
297
|
end
|
299
298
|
|
300
299
|
end
|
data/lib/sensu-cli/editor.rb
CHANGED
@@ -5,7 +5,7 @@ module SensuCli
|
|
5
5
|
class Editor
|
6
6
|
|
7
7
|
def create_stash(create_path)
|
8
|
-
file = temp_file({:path => create_path, :content => {:timestamp => Time.now.to_i }})
|
8
|
+
file = temp_file({ :path => create_path, :content => { :timestamp => Time.now.to_i } })
|
9
9
|
edit(file)
|
10
10
|
end
|
11
11
|
|
@@ -15,7 +15,7 @@ module SensuCli
|
|
15
15
|
begin
|
16
16
|
JSON.parse(File.read(file))
|
17
17
|
rescue JSON::ParserError
|
18
|
-
puts
|
18
|
+
puts 'The stash you created has Invalid JSON.'
|
19
19
|
exit
|
20
20
|
end
|
21
21
|
end
|
data/lib/sensu-cli/path.rb
CHANGED
@@ -2,15 +2,15 @@ module SensuCli
|
|
2
2
|
class PathCreator
|
3
3
|
|
4
4
|
def clients(cli)
|
5
|
-
path =
|
5
|
+
path = '/clients'
|
6
6
|
path << "/#{cli[:fields][:name]}" if cli[:fields][:name]
|
7
|
-
path <<
|
7
|
+
path << '/history' if cli[:fields][:history]
|
8
8
|
path << pagination(cli)
|
9
9
|
respond(path)
|
10
10
|
end
|
11
11
|
|
12
12
|
def info(cli)
|
13
|
-
path =
|
13
|
+
path = '/info'
|
14
14
|
respond(path)
|
15
15
|
end
|
16
16
|
|
@@ -24,53 +24,53 @@ module SensuCli
|
|
24
24
|
e = Editor.new
|
25
25
|
payload = e.create_stash(cli[:fields][:create_path]).to_json
|
26
26
|
end
|
27
|
-
path =
|
27
|
+
path = '/stashes'
|
28
28
|
path << "/#{cli[:fields][:path]}" if cli[:fields][:path]
|
29
29
|
path << pagination(cli)
|
30
|
-
respond(path,payload)
|
30
|
+
respond(path, payload)
|
31
31
|
end
|
32
32
|
|
33
33
|
def checks(cli)
|
34
34
|
if cli[:fields][:name]
|
35
35
|
path = "/check/#{cli[:fields][:name]}"
|
36
36
|
elsif cli[:fields][:subscribers]
|
37
|
-
payload = {:check => cli[:fields][:check]
|
38
|
-
path =
|
37
|
+
payload = { :check => cli[:fields][:check], :subscribers => cli[:fields][:subscribers] }.to_json
|
38
|
+
path = '/check/request'
|
39
39
|
else
|
40
|
-
path =
|
40
|
+
path = '/checks'
|
41
41
|
end
|
42
|
-
respond(path,payload)
|
42
|
+
respond(path, payload)
|
43
43
|
end
|
44
44
|
|
45
45
|
def events(cli)
|
46
|
-
path =
|
46
|
+
path = '/events'
|
47
47
|
path << "/#{cli[:fields][:client]}" if cli[:fields][:client]
|
48
48
|
path << "/#{cli[:fields][:check]}" if cli[:fields][:check]
|
49
49
|
respond(path)
|
50
50
|
end
|
51
51
|
|
52
52
|
def resolve(cli)
|
53
|
-
payload = {:client => cli[:fields][:client], :check => cli[:fields][:check]}.to_json
|
54
|
-
path =
|
55
|
-
respond(path,payload)
|
53
|
+
payload = { :client => cli[:fields][:client], :check => cli[:fields][:check] }.to_json
|
54
|
+
path = '/event/resolve'
|
55
|
+
respond(path, payload)
|
56
56
|
end
|
57
57
|
|
58
58
|
def silence(cli)
|
59
|
-
payload = {:timestamp => Time.now.to_i}
|
60
|
-
payload.merge!({:reason => cli[:fields][:reason]}) if cli[:fields][:reason]
|
59
|
+
payload = { :timestamp => Time.now.to_i }
|
60
|
+
payload.merge!({ :reason => cli[:fields][:reason] }) if cli[:fields][:reason]
|
61
61
|
if cli[:fields][:expires]
|
62
62
|
expires = Time.now.to_i + (cli[:fields][:expires] * 60)
|
63
|
-
payload.merge!({:expires => expires})
|
63
|
+
payload.merge!({ :expires => expires })
|
64
64
|
end
|
65
65
|
payload = payload.to_json
|
66
|
-
path =
|
66
|
+
path = '/stashes/silence'
|
67
67
|
path << "/#{cli[:fields][:client]}" if cli[:fields][:client]
|
68
68
|
path << "/#{cli[:fields][:check]}" if cli[:fields][:check]
|
69
|
-
respond(path,payload)
|
69
|
+
respond(path, payload)
|
70
70
|
end
|
71
71
|
|
72
72
|
def aggregates(cli)
|
73
|
-
path =
|
73
|
+
path = '/aggregates'
|
74
74
|
path << "/#{cli[:fields][:check]}" if cli[:fields][:check]
|
75
75
|
path << "/#{cli[:fields][:id]}" if cli[:fields][:id]
|
76
76
|
path << pagination(cli)
|
@@ -83,7 +83,7 @@ module SensuCli
|
|
83
83
|
elsif cli[:fields].has_key?(:limit)
|
84
84
|
page = "?limit=#{cli[:fields][:limit]}"
|
85
85
|
else
|
86
|
-
page =
|
86
|
+
page = ''
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -91,8 +91,8 @@ module SensuCli
|
|
91
91
|
puts "Path method: #{method_name} does not exist. "
|
92
92
|
end
|
93
93
|
|
94
|
-
def respond(path,payload=false)
|
95
|
-
{:path => path, :payload => payload}
|
94
|
+
def respond(path, payload = false)
|
95
|
+
{ :path => path, :payload => payload }
|
96
96
|
end
|
97
97
|
|
98
98
|
end
|
data/lib/sensu-cli/pretty.rb
CHANGED
@@ -6,14 +6,14 @@ module SensuCli
|
|
6
6
|
def self.print(res)
|
7
7
|
if !res.empty?
|
8
8
|
if res.is_a?(Hash)
|
9
|
-
res.each do |key,value|
|
9
|
+
res.each do |key, value|
|
10
10
|
puts "#{key}: ".color(:cyan) + "#{value}".color(:green)
|
11
11
|
end
|
12
12
|
elsif res.is_a?(Array)
|
13
13
|
res.each do |item|
|
14
|
-
puts
|
14
|
+
puts '-------'.color(:yellow)
|
15
15
|
if item.is_a?(Hash)
|
16
|
-
item.each do |key,value|
|
16
|
+
item.each do |key, value|
|
17
17
|
puts "#{key}: ".color(:cyan) + "#{value}".color(:green)
|
18
18
|
end
|
19
19
|
else
|
@@ -22,7 +22,7 @@ module SensuCli
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
else
|
25
|
-
puts
|
25
|
+
puts 'no values for this request'.color(:cyan)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -32,36 +32,36 @@ module SensuCli
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.clean(thing)
|
35
|
-
thing = thing.gsub("\n",'/\n') if thing.is_a?(String)
|
35
|
+
thing = thing.gsub("\n", '/\n') if thing.is_a?(String)
|
36
36
|
thing
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.table(res)
|
40
40
|
if !res.empty?
|
41
41
|
if res.is_a?(Array)
|
42
|
-
keys = res.map{|item| item.keys}.flatten.uniq.sort
|
42
|
+
keys = res.map { |item| item.keys }.flatten.uniq.sort
|
43
43
|
|
44
44
|
# Remove fields with spaces (breaks awkage)
|
45
45
|
keys.select! do |key|
|
46
|
-
res.none?{|item| item[key].to_s.include?(' ')}
|
46
|
+
res.none? { |item| item[key].to_s.include?(' ') }
|
47
47
|
end
|
48
48
|
|
49
49
|
# Find max value lengths
|
50
50
|
value_lengths = {}
|
51
51
|
keys.each do |key|
|
52
|
-
max_value_length = res.map{|item| item[key].to_s.length}.max
|
52
|
+
max_value_length = res.map { |item| item[key].to_s.length }.max
|
53
53
|
value_lengths[key] = [max_value_length, key.length].max
|
54
54
|
end
|
55
55
|
|
56
56
|
# Print header
|
57
|
-
format = keys.map {|key| "%-#{value_lengths[key]}s"}.join(' ')
|
57
|
+
format = keys.map { |key| "%-#{value_lengths[key]}s" }.join(' ')
|
58
58
|
puts sprintf(format, *keys)
|
59
59
|
|
60
60
|
# Print value rows
|
61
61
|
res.each do |item|
|
62
62
|
if item.is_a?(Hash)
|
63
|
-
values = keys.map {|key| item[key]}
|
64
|
-
format = keys.map {|key| "%-#{value_lengths[key]}s"}.join(' ')
|
63
|
+
values = keys.map { |key| item[key] }
|
64
|
+
format = keys.map { |key| "%-#{value_lengths[key]}s" }.join(' ')
|
65
65
|
puts sprintf(format, *values)
|
66
66
|
else
|
67
67
|
puts item.to_s.color(:cyan)
|
@@ -69,7 +69,7 @@ module SensuCli
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
else
|
72
|
-
puts
|
72
|
+
puts 'no values for this request'.color(:cyan)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
data/lib/sensu-cli/settings.rb
CHANGED
@@ -9,9 +9,9 @@ module SensuCli
|
|
9
9
|
!File.readable?(file) ? false : true
|
10
10
|
end
|
11
11
|
|
12
|
-
def create(directory,file)
|
12
|
+
def create(directory, file)
|
13
13
|
FileUtils.mkdir_p(directory) if !File.directory?(directory)
|
14
|
-
FileUtils.cp(File.join(File.dirname(__FILE__),
|
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
|
17
17
|
end
|
data/lib/sensu-cli/version.rb
CHANGED
data/settings.example.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
host
|
2
|
-
port
|
1
|
+
host '127.0.0.1'
|
2
|
+
port '4567'
|
3
3
|
ssl false
|