morpheus-cli 3.1.2.1 → 3.2.0
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 +4 -4
- data/lib/morpheus/api/api_client.rb +6 -2
- data/lib/morpheus/api/license_interface.rb +7 -0
- data/lib/morpheus/api/monitoring_apps_interface.rb +15 -2
- data/lib/morpheus/api/{checks_interface.rb → monitoring_checks_interface.rb} +8 -21
- data/lib/morpheus/api/monitoring_groups_interface.rb +23 -2
- data/lib/morpheus/api/{incidents_interface.rb → monitoring_incidents_interface.rb} +5 -5
- data/lib/morpheus/api/monitoring_interface.rb +4 -4
- data/lib/morpheus/api/user_groups_interface.rb +65 -0
- data/lib/morpheus/cli.rb +1 -0
- data/lib/morpheus/cli/curl_command.rb +9 -7
- data/lib/morpheus/cli/dot_file.rb +11 -5
- data/lib/morpheus/cli/echo_command.rb +27 -3
- data/lib/morpheus/cli/license.rb +109 -20
- data/lib/morpheus/cli/login.rb +2 -0
- data/lib/morpheus/cli/logout.rb +2 -0
- data/lib/morpheus/cli/mixins/monitoring_helper.rb +97 -37
- data/lib/morpheus/cli/mixins/print_helper.rb +5 -2
- data/lib/morpheus/cli/monitoring_apps_command.rb +564 -9
- data/lib/morpheus/cli/monitoring_checks_command.rb +326 -93
- data/lib/morpheus/cli/monitoring_contacts_command.rb +2 -2
- data/lib/morpheus/cli/monitoring_groups_command.rb +540 -10
- data/lib/morpheus/cli/monitoring_incidents_command.rb +88 -56
- data/lib/morpheus/cli/remote.rb +6 -0
- data/lib/morpheus/cli/roles.rb +1 -1
- data/lib/morpheus/cli/set_prompt_command.rb +1 -0
- data/lib/morpheus/cli/shell.rb +17 -8
- data/lib/morpheus/cli/user_groups_command.rb +574 -0
- data/lib/morpheus/cli/users.rb +221 -115
- data/lib/morpheus/cli/version.rb +1 -1
- data/morpheus-cli.gemspec +1 -2
- metadata +11 -8
@@ -5,14 +5,11 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
5
5
|
include Morpheus::Cli::CliCommand
|
6
6
|
include Morpheus::Cli::MonitoringHelper
|
7
7
|
|
8
|
-
set_command_name :
|
9
|
-
register_subcommands :list, :get, :
|
10
|
-
|
8
|
+
set_command_name :'monitor-checks'
|
9
|
+
register_subcommands :list, :get, :add, :update, :remove
|
10
|
+
register_subcommands :mute, :unmute, :history #, :statistics
|
11
|
+
register_subcommands :'list-types' => :list_types
|
11
12
|
|
12
|
-
def initialize()
|
13
|
-
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
14
|
-
end
|
15
|
-
|
16
13
|
def connect(opts)
|
17
14
|
@api_client = establish_remote_appliance_connection(opts)
|
18
15
|
@monitoring_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).monitoring
|
@@ -25,15 +22,16 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
25
22
|
def list(args)
|
26
23
|
options = {}
|
27
24
|
params = {}
|
28
|
-
optparse = OptionParser.new do|opts|
|
25
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
29
26
|
opts.banner = subcommand_usage()
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
# todo: api to load type id by name
|
28
|
+
# opts.on('--type VALUE', Array, "Filter by status. error,healthy,warning,muted") do |val|
|
29
|
+
# params['checkType'] = val
|
30
|
+
# end
|
31
|
+
opts.on('--status VALUE', Array, "Filter by status. error,healthy,warning,muted") do |val|
|
32
|
+
params['status'] = val
|
35
33
|
end
|
36
|
-
build_common_options(opts, options, [:list, :last_updated, :json, :csv, :fields, :json, :dry_run])
|
34
|
+
build_common_options(opts, options, [:list, :last_updated, :json, :yaml, :csv, :fields, :json, :dry_run, :remote])
|
37
35
|
end
|
38
36
|
optparse.parse!(args)
|
39
37
|
connect(options)
|
@@ -41,27 +39,26 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
41
39
|
[:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
|
42
40
|
params[k] = options[k] unless options[k].nil?
|
43
41
|
end
|
44
|
-
# JD: lastUpdated 500ing, checks don't have that property ? =o Fix it!
|
45
|
-
|
46
42
|
if options[:dry_run]
|
47
43
|
print_dry_run @monitoring_interface.checks.dry.list(params)
|
48
44
|
return
|
49
45
|
end
|
50
|
-
|
51
46
|
json_response = @monitoring_interface.checks.list(params)
|
47
|
+
if options[:include_fields]
|
48
|
+
json_response = {"checks" => filter_data(json_response["checks"], options[:include_fields]) }
|
49
|
+
end
|
52
50
|
if options[:json]
|
53
|
-
if options[:include_fields]
|
54
|
-
json_response = {"checks" => filter_data(json_response["checks"], options[:include_fields]) }
|
55
|
-
end
|
56
51
|
puts as_json(json_response, options)
|
57
52
|
return 0
|
58
|
-
|
59
|
-
|
53
|
+
elsif options[:yaml]
|
54
|
+
puts as_yaml(json_response, options)
|
55
|
+
return 0
|
56
|
+
elsif options[:csv]
|
60
57
|
puts records_as_csv(json_response['checks'], options)
|
61
58
|
return 0
|
62
59
|
end
|
63
60
|
checks = json_response['checks']
|
64
|
-
title = "Morpheus Checks"
|
61
|
+
title = "Morpheus Monitoring Checks"
|
65
62
|
subtitles = []
|
66
63
|
# if group
|
67
64
|
# subtitles << "Group: #{group['name']}".strip
|
@@ -88,7 +85,7 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
88
85
|
|
89
86
|
def get(args)
|
90
87
|
options = {}
|
91
|
-
optparse = OptionParser.new do|opts|
|
88
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
92
89
|
opts.banner = subcommand_usage("[id list]")
|
93
90
|
opts.on(nil,'--history', "Display Check History") do |val|
|
94
91
|
options[:show_history] = true
|
@@ -121,13 +118,15 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
121
118
|
end
|
122
119
|
json_response = @monitoring_interface.checks.get(check['id'])
|
123
120
|
check = json_response['check']
|
124
|
-
|
121
|
+
if options[:include_fields]
|
122
|
+
json_response = {'check' => filter_data(check, options[:include_fields]) }
|
123
|
+
end
|
125
124
|
if options[:json]
|
126
|
-
if options[:include_fields]
|
127
|
-
json_response = {"check" => filter_data(json_response["check"], options[:include_fields]) }
|
128
|
-
end
|
129
125
|
puts as_json(json_response, options)
|
130
126
|
return 0
|
127
|
+
elsif options[:yaml]
|
128
|
+
puts as_yaml(json_response, options)
|
129
|
+
return 0
|
131
130
|
elsif options[:csv]
|
132
131
|
puts records_as_csv([json_response['check']], options)
|
133
132
|
return 0
|
@@ -137,16 +136,37 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
137
136
|
print cyan
|
138
137
|
description_cols = {
|
139
138
|
"ID" => lambda {|it| it['id'] },
|
140
|
-
"Status" => lambda {|it| format_monitoring_check_status(it) },
|
139
|
+
"Status" => lambda {|it| format_monitoring_check_status(it, true) },
|
141
140
|
"Name" => lambda {|it| it['name'] },
|
142
|
-
"Time" => lambda {|it| format_local_dt(it['lastRunDate']) },
|
141
|
+
"Time" => lambda {|it| it['lastRunDate'] ? format_local_dt(it['lastRunDate']) : "N/A" },
|
143
142
|
"Availability" => lambda {|it| it['availability'] ? "#{it['availability'].to_f.round(3).to_s}%" : "N/A"},
|
144
143
|
"Response Time" => lambda {|it| it['lastTimer'] ? "#{it['lastTimer']}ms" : "N/A" },
|
145
|
-
"Last Metric" => lambda {|it|
|
146
|
-
|
144
|
+
"Last Metric" => lambda {|it|
|
145
|
+
if it['lastMetric']
|
146
|
+
metric_name = it['checkType'] ? it['checkType']['metricName'] : nil
|
147
|
+
if metric_name
|
148
|
+
"#{it['lastMetric']} #{metric_name}"
|
149
|
+
else
|
150
|
+
"#{it['lastMetric']}"
|
151
|
+
end
|
152
|
+
else
|
153
|
+
"N/A"
|
154
|
+
end
|
155
|
+
},
|
156
|
+
"Type" => lambda {|it| format_monitoring_check_type(it) },
|
157
|
+
"Created By" => lambda {|it| it['createdBy'] ? it['createdBy']['username'] : "System" },
|
158
|
+
"Date Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
159
|
+
"Last Updated" => lambda {|it| format_local_dt(it['lastUpdated']) },
|
160
|
+
# "Last Error" => lambda {|it| format_local_dt(it['lastErrorDate']) },
|
147
161
|
}
|
148
162
|
print_description_list(description_cols, check)
|
149
163
|
|
164
|
+
# Last Error
|
165
|
+
# if check['lastCheckStatus'] == 'error' && check['lastError']
|
166
|
+
# print_h2 "Last Error at #{format_local_dt(check['lastErrorDate'])}"
|
167
|
+
# print red,"#{check['lastError']}",reset,"\n"
|
168
|
+
# end
|
169
|
+
|
150
170
|
## Chart Stats
|
151
171
|
|
152
172
|
|
@@ -156,24 +176,34 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
156
176
|
|
157
177
|
check_groups = json_response["groups"]
|
158
178
|
if check_groups && !check_groups.empty?
|
159
|
-
print_h2 "
|
160
|
-
print as_pretty_table(check_groups, [:id,
|
179
|
+
print_h2 "Groups"
|
180
|
+
#print as_pretty_table(check_groups, [:id, :name], options)
|
181
|
+
print_check_groups_table(check_groups, options)
|
161
182
|
else
|
162
183
|
# print "\n"
|
163
184
|
# puts "This check is not in any check groups."
|
164
185
|
end
|
165
186
|
|
187
|
+
apps = json_response["apps"]
|
188
|
+
if apps && apps.empty?
|
189
|
+
print_h2 "Apps"
|
190
|
+
print as_pretty_table(apps, [:id, :name], options)
|
191
|
+
else
|
192
|
+
# print "\n"
|
193
|
+
# puts "This check is not in any monitoring apps."
|
194
|
+
end
|
195
|
+
|
166
196
|
## Open Incidents
|
167
197
|
|
168
198
|
open_incidents = json_response["openIncidents"]
|
169
199
|
if open_incidents && !open_incidents.empty?
|
170
200
|
print_h2 "Open Incidents"
|
171
201
|
# puts "\n(table coming soon...)\n"
|
172
|
-
puts
|
202
|
+
puts JSON.pretty_generate(open_incidents)
|
173
203
|
# todo: move this to MonitoringHelper ?
|
174
204
|
# print_incidents_table(issues, options)
|
175
205
|
else
|
176
|
-
print "\n"
|
206
|
+
print "\n", cyan
|
177
207
|
puts "No open incidents for this check"
|
178
208
|
end
|
179
209
|
|
@@ -210,15 +240,15 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
210
240
|
def history(args)
|
211
241
|
options = {}
|
212
242
|
params = {}
|
213
|
-
optparse = OptionParser.new do|opts|
|
214
|
-
opts.banner = subcommand_usage("[
|
243
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
244
|
+
opts.banner = subcommand_usage("[name] [options]")
|
215
245
|
# opts.on('--status LIST', Array, "Filter by status. open, closed") do |list|
|
216
246
|
# params['status'] = list
|
217
247
|
# end
|
218
248
|
opts.on('--severity LIST', Array, "Filter by severity. critical, warning, info") do |list|
|
219
249
|
params['severity'] = list
|
220
250
|
end
|
221
|
-
build_common_options(opts, options, [:list, :last_updated, :json, :csv, :fields, :json, :dry_run])
|
251
|
+
build_common_options(opts, options, [:list, :last_updated, :json, :csv, :fields, :json, :dry_run, :remote])
|
222
252
|
end
|
223
253
|
optparse.parse!(args)
|
224
254
|
if args.count < 1
|
@@ -253,7 +283,7 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
253
283
|
return 0
|
254
284
|
end
|
255
285
|
history_items = json_response['history']
|
256
|
-
title = "Check History: #{check['
|
286
|
+
title = "Check History: #{check['name']}"
|
257
287
|
subtitles = []
|
258
288
|
if params[:phrase]
|
259
289
|
subtitles << "Search: #{params[:phrase]}".strip
|
@@ -272,47 +302,142 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
272
302
|
end
|
273
303
|
end
|
274
304
|
|
305
|
+
def add(args)
|
306
|
+
options = {}
|
307
|
+
params = {'inUptime' => true, 'severity' => 'critical'}
|
308
|
+
check_type = nil
|
309
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
310
|
+
opts.banner = subcommand_usage("[name] -t CODE")
|
311
|
+
opts.on('-t', '--type CODE', "Check Type Code or ID") do |val|
|
312
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
313
|
+
params['checkType'] = {'id' => val.to_i}
|
314
|
+
else
|
315
|
+
params['checkType'] = {'code' => val}
|
316
|
+
end
|
317
|
+
end
|
318
|
+
opts.on('--name VALUE', String, "Name") do |val|
|
319
|
+
params['name'] = val
|
320
|
+
end
|
321
|
+
opts.on('--description VALUE', String, "Description") do |val|
|
322
|
+
params['description'] = val
|
323
|
+
end
|
324
|
+
opts.on('--checkInterval MILLIS', String, "Check Interval. Value is in milliseconds. Default varies by type.") do |val|
|
325
|
+
params['checkInterval'] = val.to_i # * 1000
|
326
|
+
end
|
327
|
+
opts.on('--severity VALUE', String, "Max Severity. Determines the maximum severity level this check can incur on an incident when failing. Default is critical") do |val|
|
328
|
+
params['severity'] = val
|
329
|
+
end
|
330
|
+
opts.on('--inUptime [on|off]', String, "Affects Availability. Default is on.") do |val|
|
331
|
+
params['inUptime'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
|
332
|
+
end
|
333
|
+
opts.on('-c', '--config JSON', "Config settings as JSON") do |val|
|
334
|
+
begin
|
335
|
+
params['config'] = JSON.parse(val.to_s)
|
336
|
+
rescue => ex
|
337
|
+
raise ::OptionParser::InvalidOption.new("Failed to parse --config as JSON. Error: #{ex.message}")
|
338
|
+
end
|
339
|
+
end
|
340
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
|
341
|
+
opts.footer = "List monitoring checks."
|
342
|
+
end
|
343
|
+
optparse.parse!(args)
|
344
|
+
if args.count > 1
|
345
|
+
print_error Morpheus::Terminal.angry_prompt
|
346
|
+
puts_error "wrong number of arguments, expected 0-1 and got #{args.count}\n#{optparse}"
|
347
|
+
return 1
|
348
|
+
end
|
349
|
+
if args[0]
|
350
|
+
params['name'] = args[0]
|
351
|
+
end
|
352
|
+
connect(options)
|
353
|
+
begin
|
354
|
+
# construct payload
|
355
|
+
payload = nil
|
356
|
+
if options[:payload]
|
357
|
+
payload = options[:payload]
|
358
|
+
else
|
359
|
+
params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
360
|
+
# todo: load option types based on type and prompt
|
361
|
+
payload = {'check' => params}
|
362
|
+
end
|
363
|
+
if options[:dry_run]
|
364
|
+
print_dry_run @monitoring_interface.checks.dry.create(payload)
|
365
|
+
return
|
366
|
+
end
|
367
|
+
json_response = @monitoring_interface.checks.create(payload)
|
368
|
+
if options[:json]
|
369
|
+
puts as_json(json_response, options)
|
370
|
+
elsif !options[:quiet]
|
371
|
+
check = json_response['check']
|
372
|
+
print_green_success "Added check #{check['name']}"
|
373
|
+
_get(check['id'], {})
|
374
|
+
end
|
375
|
+
return 0
|
376
|
+
rescue RestClient::Exception => e
|
377
|
+
print_rest_exception(e, options)
|
378
|
+
exit 1
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
275
382
|
def update(args)
|
276
383
|
options = {}
|
277
384
|
params = {}
|
278
|
-
optparse = OptionParser.new do|opts|
|
279
|
-
opts.banner = subcommand_usage("[
|
280
|
-
|
385
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
386
|
+
opts.banner = subcommand_usage("[name]")
|
387
|
+
opts.on('--name VALUE', String, "Name") do |val|
|
388
|
+
params['name'] = val
|
389
|
+
end
|
390
|
+
opts.on('--description VALUE', String, "Description") do |val|
|
391
|
+
params['description'] = val
|
392
|
+
end
|
393
|
+
opts.on('--checkInterval VALUE', String, "Check Interval. Value is in milliseconds.") do |val|
|
394
|
+
params['checkInterval'] = val.to_i # * 1000
|
395
|
+
end
|
396
|
+
opts.on('--severity VALUE', String, "Max Severity. Determines the maximum severity level this check can incur on an incident when failing. Default is critical") do |val|
|
397
|
+
params['severity'] = val
|
398
|
+
end
|
399
|
+
opts.on('--inUptime [on|off]', String, "Affects Availability. Default is on.") do |val|
|
400
|
+
params['inUptime'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
|
401
|
+
end
|
402
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
|
403
|
+
opts.footer = "Update a monitoring check." + "\n" +
|
404
|
+
"[name] is required. This is the name or id of a check." + "\n" +
|
405
|
+
"The available options vary by type."
|
281
406
|
end
|
282
407
|
optparse.parse!(args)
|
283
|
-
if args.count
|
284
|
-
|
285
|
-
|
408
|
+
if args.count != 1
|
409
|
+
print_error Morpheus::Terminal.angry_prompt
|
410
|
+
puts_error "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
|
411
|
+
return 1
|
286
412
|
end
|
287
413
|
connect(options)
|
288
|
-
|
289
414
|
begin
|
290
415
|
check = find_check_by_name_or_id(args[0])
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
416
|
+
# construct payload
|
417
|
+
payload = nil
|
418
|
+
if options[:payload]
|
419
|
+
payload = options[:payload]
|
420
|
+
else
|
421
|
+
# merge -O options into normally parsed options
|
422
|
+
params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
423
|
+
if params['checks']
|
424
|
+
params['checks'] = params['checks'].collect {|it| it.to_i }
|
425
|
+
end
|
426
|
+
# todo: prompt?
|
427
|
+
payload = {'check' => params}
|
296
428
|
end
|
297
|
-
|
298
|
-
payload = {
|
299
|
-
'check' => {id: check["id"]}
|
300
|
-
}
|
301
|
-
payload['check'].merge!(params)
|
302
|
-
|
303
429
|
if options[:dry_run]
|
304
430
|
print_dry_run @monitoring_interface.checks.dry.update(check["id"], payload)
|
305
431
|
return
|
306
432
|
end
|
307
|
-
|
308
433
|
json_response = @monitoring_interface.checks.update(check["id"], payload)
|
309
434
|
if options[:json]
|
310
435
|
puts as_json(json_response, options)
|
311
436
|
elsif !options[:quiet]
|
312
|
-
print_green_success "Updated check #{check['
|
437
|
+
print_green_success "Updated check #{check['name']}"
|
313
438
|
_get(check['id'], {})
|
314
439
|
end
|
315
|
-
|
440
|
+
return 0
|
316
441
|
rescue RestClient::Exception => e
|
317
442
|
print_rest_exception(e, options)
|
318
443
|
exit 1
|
@@ -320,55 +445,92 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
320
445
|
end
|
321
446
|
|
322
447
|
|
323
|
-
def
|
448
|
+
def mute(args)
|
324
449
|
options = {}
|
325
450
|
params = {'enabled' => true}
|
326
|
-
optparse = OptionParser.new do|opts|
|
327
|
-
opts.banner = subcommand_usage("[
|
328
|
-
|
329
|
-
# opts.on("--enabled BOOL", String, "Quarantine can be removed with --enabled false") do |val|
|
330
|
-
# params['enabled'] = ['on','true'].include?(val.to_s.downcase)
|
331
|
-
# end
|
332
|
-
opts.on("-d", "--disabled", "Disable Quarantine instead") do
|
451
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
452
|
+
opts.banner = subcommand_usage("[name]")
|
453
|
+
opts.on(nil, "--disable", "Disable mute state instead, the same as unmute") do
|
333
454
|
params['enabled'] = false
|
334
455
|
end
|
335
|
-
build_common_options(opts, options, [:json, :dry_run, :quiet])
|
456
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
|
457
|
+
opts.footer = "Mute a check. This prevents it from creating new incidents." + "\n" +
|
458
|
+
"[name] is required. This is the name or id of a check."
|
336
459
|
end
|
337
460
|
optparse.parse!(args)
|
338
|
-
if args.count
|
461
|
+
if args.count != 1
|
339
462
|
puts optparse
|
340
|
-
|
463
|
+
return 1
|
341
464
|
end
|
342
465
|
connect(options)
|
343
|
-
|
344
466
|
begin
|
345
467
|
check = find_check_by_name_or_id(args[0])
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
468
|
+
# construct payload
|
469
|
+
payload = nil
|
470
|
+
if options[:payload]
|
471
|
+
payload = options[:payload]
|
472
|
+
else
|
473
|
+
payload = params
|
474
|
+
end
|
475
|
+
if options[:dry_run]
|
476
|
+
print_dry_run @monitoring_interface.checks.dry.quarantine(check["id"], payload)
|
477
|
+
return 0
|
351
478
|
end
|
479
|
+
json_response = @monitoring_interface.checks.quarantine(check["id"], payload)
|
480
|
+
if options[:json]
|
481
|
+
puts as_json(json_response, options)
|
482
|
+
elsif !options[:quiet]
|
483
|
+
if params['enabled']
|
484
|
+
print_green_success "Muted check #{check['name']}"
|
485
|
+
else
|
486
|
+
print_green_success "Unmuted check #{check['name']}"
|
487
|
+
end
|
488
|
+
_get(check['id'], {})
|
489
|
+
end
|
490
|
+
return 0
|
491
|
+
rescue RestClient::Exception => e
|
492
|
+
print_rest_exception(e, options)
|
493
|
+
exit 1
|
494
|
+
end
|
495
|
+
end
|
352
496
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
497
|
+
def unmute(args)
|
498
|
+
options = {}
|
499
|
+
params = {'enabled' => false}
|
500
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
501
|
+
opts.banner = subcommand_usage("[name]")
|
502
|
+
build_common_options(opts, options, [:payload, :json, :dry_run, :quiet, :remote])
|
503
|
+
opts.footer = "Unmute a check." + "\n" +
|
504
|
+
"[name] is required. This is the name or id of a check."
|
505
|
+
end
|
506
|
+
optparse.parse!(args)
|
507
|
+
if args.count != 1
|
508
|
+
puts optparse
|
509
|
+
return 1
|
510
|
+
end
|
511
|
+
connect(options)
|
358
512
|
|
513
|
+
begin
|
514
|
+
check = find_check_by_name_or_id(args[0])
|
515
|
+
# construct payload
|
516
|
+
payload = nil
|
517
|
+
if options[:payload]
|
518
|
+
payload = options[:payload]
|
519
|
+
else
|
520
|
+
payload = params
|
521
|
+
end
|
359
522
|
if options[:dry_run]
|
360
|
-
print_dry_run @monitoring_interface.checks.dry.
|
361
|
-
return
|
523
|
+
print_dry_run @monitoring_interface.checks.dry.quarantine(check["id"], payload)
|
524
|
+
return 0
|
362
525
|
end
|
363
|
-
|
364
|
-
json_response = @monitoring_interface.checks.update(check["id"], payload)
|
526
|
+
json_response = @monitoring_interface.checks.quarantine(check["id"], payload)
|
365
527
|
if options[:json]
|
366
528
|
puts as_json(json_response, options)
|
367
529
|
elsif !options[:quiet]
|
368
|
-
print_green_success "
|
530
|
+
print_green_success "Unmuted check #{check['name']}"
|
369
531
|
_get(check['id'], {})
|
370
532
|
end
|
371
|
-
|
533
|
+
return 0
|
372
534
|
rescue RestClient::Exception => e
|
373
535
|
print_rest_exception(e, options)
|
374
536
|
exit 1
|
@@ -377,12 +539,12 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
377
539
|
|
378
540
|
def remove(args)
|
379
541
|
options = {}
|
380
|
-
optparse = OptionParser.new do|opts|
|
381
|
-
opts.banner = subcommand_usage("[
|
382
|
-
build_common_options(opts, options, [:json, :dry_run, :quiet])
|
542
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
543
|
+
opts.banner = subcommand_usage("[name]")
|
544
|
+
build_common_options(opts, options, [:json, :dry_run, :quiet, :remote])
|
383
545
|
end
|
384
546
|
optparse.parse!(args)
|
385
|
-
if args.count
|
547
|
+
if args.count != 1
|
386
548
|
puts optparse
|
387
549
|
return 127
|
388
550
|
end
|
@@ -419,6 +581,77 @@ class Morpheus::Cli::MonitoringChecksCommand
|
|
419
581
|
end
|
420
582
|
end
|
421
583
|
|
584
|
+
def list_types(args)
|
585
|
+
options = {}
|
586
|
+
params = {}
|
587
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
588
|
+
opts.banner = subcommand_usage()
|
589
|
+
build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :dry_run, :remote])
|
590
|
+
opts.footer = "List monitoring check types."
|
591
|
+
end
|
592
|
+
optparse.parse!(args)
|
593
|
+
connect(options)
|
594
|
+
begin
|
595
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
596
|
+
params[k] = options[k] unless options[k].nil?
|
597
|
+
end
|
598
|
+
if options[:dry_run]
|
599
|
+
print_dry_run @monitoring_interface.checks.dry.list_check_types(params)
|
600
|
+
return
|
601
|
+
end
|
602
|
+
|
603
|
+
json_response = @monitoring_interface.checks.list_check_types(params)
|
604
|
+
if options[:include_fields]
|
605
|
+
json_response = {"checkTypes" => filter_data(json_response["checkTypes"], options[:include_fields]) }
|
606
|
+
end
|
607
|
+
if options[:json]
|
608
|
+
puts as_json(json_response, options)
|
609
|
+
return 0
|
610
|
+
elsif options[:csv]
|
611
|
+
puts records_as_csv(json_response['monitorApps'], options)
|
612
|
+
return 0
|
613
|
+
elsif options[:yaml]
|
614
|
+
puts as_yaml(json_response, options)
|
615
|
+
return 0
|
616
|
+
end
|
617
|
+
if options[:json]
|
618
|
+
if options[:include_fields]
|
619
|
+
json_response = {"checkTypes" => filter_data(json_response["checkTypes"], options[:include_fields]) }
|
620
|
+
end
|
621
|
+
puts as_json(json_response, options)
|
622
|
+
return 0
|
623
|
+
end
|
624
|
+
if options[:csv]
|
625
|
+
puts records_as_csv(json_response['checkTypes'], options)
|
626
|
+
return 0
|
627
|
+
end
|
628
|
+
check_types = json_response['checkTypes']
|
629
|
+
title = "Check Types"
|
630
|
+
subtitles = []
|
631
|
+
if params[:phrase]
|
632
|
+
subtitles << "Search: #{params[:phrase]}".strip
|
633
|
+
end
|
634
|
+
print_h1 title, subtitles
|
635
|
+
if check_types.empty?
|
636
|
+
print cyan,"No check types found.",reset,"\n"
|
637
|
+
else
|
638
|
+
# columns = [:code, :name]
|
639
|
+
columns = [
|
640
|
+
# {"ID" => lambda {|check_type| check_type['id'] } },
|
641
|
+
{"NAME" => lambda {|check_type| check_type['name'] } },
|
642
|
+
{"CODE" => lambda {|check_type| check_type['code'] } },
|
643
|
+
{"METRIC" => lambda {|check_type| check_type['metricName'] } },
|
644
|
+
{"DEFAULT INTERVAL" => lambda {|check_type| check_type['defaultInterval'] ? format_human_duration(check_type['defaultInterval'].to_i / 1000) : '' } }
|
645
|
+
]
|
646
|
+
print as_pretty_table(check_types, columns, options)
|
647
|
+
print_results_pagination(json_response, {:label => "type", :n_label => "types"})
|
648
|
+
end
|
649
|
+
print reset,"\n"
|
650
|
+
rescue RestClient::Exception => e
|
651
|
+
print_rest_exception(e, options)
|
652
|
+
exit 1
|
653
|
+
end
|
654
|
+
end
|
422
655
|
|
423
656
|
private
|
424
657
|
|