Class: Morpheus::Cli::MonitoringAppsCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::MonitoringAppsCommand
show all
- Includes:
- CliCommand, MonitoringHelper
- Defined in:
- lib/morpheus/cli/commands/monitoring_apps_command.rb
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
#available_severities, #check_type_for_id, #check_type_for_name, #check_type_for_name_or_id, #find_alert_by_id, #find_alert_by_name, #find_alert_by_name_or_id, #find_check_by_id, #find_check_by_name, #find_check_by_name_or_id, #find_check_group_by_id, #find_check_group_by_name, #find_check_group_by_name_or_id, #find_contact_by_id, #find_contact_by_name, #find_contact_by_name_or_id, #find_incident_by_id, #find_monitoring_app_by_id, #find_monitoring_app_by_name, #find_monitoring_app_by_name_or_id, #format_health_status, #format_monitoring_check_last_metric, #format_monitoring_check_status, #format_monitoring_check_type, #format_monitoring_incident_status, #format_monitoring_issue_attachment_type, #format_monitoring_issue_status, #format_recipient_method, #format_severity, #get_available_check_types, included, #monitoring_interface, #parse_recipient_method, #print_check_group_history_table, #print_check_groups_table, #print_check_history_table, #print_check_notifications_table, #print_checks_table, #print_incident_history_table, #print_incident_issues_table, #print_incident_notifications_table, #print_incidents_table, #print_monitor_app_history_table, #print_monitoring_apps_table, #prompt_for_check_groups, #prompt_for_checks, #prompt_for_monitor_apps, #prompt_for_recipients
Methods included from CliCommand
#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands
Instance Method Details
#_get(id, options) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 104
def _get(id, options)
begin
monitor_app = find_monitoring_app_by_name_or_id(id)
@monitoring_apps_interface.setopts(options)
if options[:dry_run]
print_dry_run @monitoring_apps_interface.dry.get(monitor_app['id'])
return
end
json_response = @monitoring_apps_interface.get(monitor_app['id'])
monitor_app = json_response['monitorApp']
if options[:json]
puts as_json(json_response, options, "monitorApp")
return 0
elsif options[:yaml]
puts as_yaml(json_response, options, "monitorApp")
return 0
elsif options[:csv]
puts records_as_csv([json_response['monitorApp']], options)
return 0
end
print_h1 "Monitoring App Details", [], options
print cyan
description_cols = {
"ID" => lambda {|it| it['id'] },
"Status" => lambda {|it| format_monitoring_check_status(it, true) },
"Name" => lambda {|it| it['name'] },
"Description" => lambda {|it| it['description'] },
"Time" => lambda {|it| format_local_dt(it['lastRunDate']) },
"Availability" => lambda {|it| it['availability'] ? "#{it['availability'].to_f.round(3).to_s}%" : "N/A"},
"Response Time" => lambda {|it| it['lastTimer'] ? "#{it['lastTimer']}ms" : "N/A" }
}
print_description_list(description_cols, monitor_app, options)
checks = json_response["checks"]
if checks && !checks.empty?
print_h2 "Checks", options
print_checks_table(checks, options)
else
end
check_groups = json_response["checkGroups"]
if check_groups && !check_groups.empty?
print_h2 "Groups", options
print_check_groups_table(check_groups, options)
else
end
if (!checks || checks.empty?) && (check_groups || check_groups.empty?)
print "\n", yellow
puts "This monitor app is empty, it contains no checks or groups."
end
open_incidents = json_response["openIncidents"]
if open_incidents && !open_incidents.empty?
print_h2 "Open Incidents"
print_incidents_table(open_incidents)
else
print "\n", cyan
puts "No open incidents for this monitoring app"
end
if options[:show_history]
history_json_response = @monitoring_apps_interface.history(monitor_app["id"], {})
history_items = history_json_response["history"] || history_json_response["events"] || history_json_response["issues"]
issues = history_items
if history_items && !history_items.empty?
print_h2 "History"
print_monitor_app_history_table(history_items, options)
(history_json_response, {:label => "event", :n_label => "events"})
else
print "\n"
puts "No history found for this monitoring app"
end
end
if options[:show_statistics]
end
print reset,"\n"
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#add(args) ⇒ Object
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 272
def add(args)
options = {}
params = {'inUptime' => true, 'severity' => 'critical'}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name]")
opts.on('--name VALUE', String, "Name") do |val|
params['name'] = val
end
opts.on('--description VALUE', String, "Description") do |val|
params['description'] = val
end
opts.on('--minHappy VALUE', String, "Min Checks. This specifies the minimum number of checks within the app that must be happy to keep the app from becoming unhealthy.") do |val|
params['minHappy'] = val.to_i
end
opts.on('--severity VALUE', String, "Max Severity. Determines the maximum severity level this app can incur on an incident when failing. Default is critical") do |val|
params['severity'] = val
end
opts.on('--inUptime [on|off]', String, "Affects Availability. Default is on.") do |val|
params['inUptime'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
end
opts.on('--muted [on|off]', String, "Muted, Turns Affects Availability off.") do |val|
params['muted'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
end
opts.on('--checks LIST', Array, "Checks to include in this app, comma separated list of names or IDs.") do |list|
if list.size == 1 && ('[]' == list[0]) params['checks'] = []
else
params['checks'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
end
end
opts.on('--groups LIST', Array, "Check Groups to include in this app, comma separated list of names or IDs.") do |list|
if list.size == 1 && ('[]' == list[0]) params['checkGroups'] = []
else
params['checkGroups'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
end
end
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
opts. = "Create a new app of monitoring checks." + "\n" +
"[name] is required and can be passed as --name instead."
end
optparse.parse!(args)
if args.count > 1
print_error Morpheus::Terminal.angry_prompt
puts_error "wrong number of arguments, expected 0-1 and got #{args.count}\n#{optparse}"
return 1
end
if args[0]
params['name'] = args[0]
end
connect(options)
begin
payload = nil
if options[:payload]
payload = options[:payload]
else
params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
if params['name'].nil?
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Name', 'required' => true, 'description' => 'The name of this alert rule.'}], options[:options])
params['name'] = v_prompt['name']
end
if params['severity'].nil?
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'severity', 'type' => 'text', 'fieldLabel' => 'Severity', 'required' => false, 'description' => 'Max Severity. Determines the maximum severity level this app can incur on an incident when failing. Default is critical', 'defaultValue' => 'critical'}], options[:options])
params['severity'] = v_prompt['severity'] unless v_prompt['severity'].to_s.empty?
end
if params['inUptime'].nil? && params['muted'].nil?
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'inUptime', 'type' => 'checkbox', 'fieldLabel' => 'Affects Availability', 'required' => false, 'description' => 'Affects Availability. Default is on.', 'defaultValue' => true}], options[:options])
params['inUptime'] = v_prompt['inUptime'] unless v_prompt['inUptime'].to_s.empty?
end
prompt_results = prompt_for_checks(params, options, @api_client)
if prompt_results[:success]
params['checks'] = prompt_results[:data] unless prompt_results[:data].nil?
else
return 1
end
prompt_results = prompt_for_check_groups(params, options, @api_client)
if prompt_results[:success]
params['checkGroups'] = prompt_results[:data] unless prompt_results[:data].nil?
else
return 1
end
payload = {'monitorApp' => params}
end
@monitoring_apps_interface.setopts(options)
if options[:dry_run]
print_dry_run @monitoring_apps_interface.dry.create(payload)
return
end
json_response = @monitoring_apps_interface.create(payload)
if options[:json]
puts as_json(json_response, options)
elsif !options[:quiet]
monitor_app = json_response['monitorApp']
print_green_success "Added monitoring app #{monitor_app['name']}"
_get(monitor_app['id'], {})
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#connect(opts) ⇒ Object
register_subcommands :history
15
16
17
18
19
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 15
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@monitoring_interface = @api_client.monitoring
@monitoring_apps_interface = @api_client.monitoring.apps
end
|
#get(args) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 75
def get(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[id list]")
opts.on(nil,'--history', "Display Monitoring App History") do |val|
options[:show_history] = true
end
opts.on('-a','--all', "Display All Details (History, Notifications)") do
options[:show_history] = true
options[:show_notifications] = true
options[:show_statistics] = true
end
build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
end
optparse.parse!(args)
if args.count < 1
puts optparse
exit 1
end
connect(options)
id_list = parse_id_list(args)
return run_command_for_each_arg(id_list) do |arg|
_get(arg, options)
end
end
|
#handle(args) ⇒ Object
21
22
23
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 21
def handle(args)
handle_subcommand(args)
end
|
#history(args) ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 210
def history(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name] [options]")
opts.on('--severity LIST', Array, "Filter by severity. critical, warning, info") do |list|
params['severity'] = list
end
build_common_options(opts, options, [:list, :last_updated, :json, :yaml, :csv, :fields, :json, :dry_run, :remote])
end
optparse.parse!(args)
if args.count < 1
puts optparse
exit 1
end
connect(options)
begin
monitor_app = find_monitoring_app_by_name_or_id(args[0])
return 1 if monitor_app.nil?
[:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
params[k] = options[k] unless options[k].nil?
end
@monitoring_apps_interface.setopts(options)
if options[:dry_run]
print_dry_run @monitoring_apps_interface.dry.history(monitor_app['id'], params)
return
end
json_response = @monitoring_apps_interface.history(monitor_app['id'], params)
if options[:json]
puts as_json(json_response, options, "history")
return 0
end
if options[:csv]
puts records_as_csv(json_response['history'], options)
return 0
end
history_items = json_response['history']
title = "Monitoring App History: #{monitor_app['name']}"
subtitles = []
if params[:phrase]
subtitles << "Search: #{params[:phrase]}".strip
end
print_h1 title, subtitles
if history_items.empty?
print cyan,"No history found.",reset,"\n"
else
print_monitor_app_history_table(history_items, options)
(json_response, {:label => "event", :n_label => "events"})
end
print reset,"\n"
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#list(args) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 25
def list(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage()
opts.on('--status LIST', Array, "Filter by status. error,healthy,warning,muted") do |list|
params['status'] = list
end
build_common_options(opts, options, [:list, :query, :last_updated, :json, :yaml, :csv, :fields, :dry_run, :remote])
end
optparse.parse!(args)
connect(options)
begin
params.merge!(parse_list_options(options))
@monitoring_apps_interface.setopts(options)
if options[:dry_run]
print_dry_run @monitoring_apps_interface.dry.list(params)
return
end
json_response = @monitoring_apps_interface.list(params)
if options[:json]
puts as_json(json_response, options, "monitorApps")
return 0
elsif options[:csv]
puts records_as_csv(json_response['monitorApps'], options)
return 0
elsif options[:yaml]
puts as_yaml(json_response, options, "monitorApps")
return 0
end
monitor_apps = json_response['monitorApps']
title = "Morpheus Monitoring Apps"
subtitles = []
subtitles += parse_list_subtitles(options)
print_h1 title, subtitles
if monitor_apps.empty?
print cyan,"No monitoring apps found.",reset,"\n"
else
print_monitoring_apps_table(monitor_apps, options)
(json_response, {:label => "monitoring app", :n_label => "monitoring apps"})
end
print reset,"\n"
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#mute(args) ⇒ Object
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 482
def mute(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name]")
opts.on(nil, "--disable", "Unmute instead, the same as the unmute command") do
params['muted'] = false
params['enabled'] = false
end
opts. = "Mute a monitoring app. This prevents it from creating new incidents." + "\n" +
"[name] is required. This is the name or id of a monitoring app."
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
end
optparse.parse!(args)
if args.count < 1
puts optparse
exit 1
end
connect(options)
begin
monitor_app = find_monitoring_app_by_name_or_id(args[0])
payload = nil
if options[:payload]
payload = options[:payload]
else
payload = params
end
@monitoring_apps_interface.setopts(options)
if options[:dry_run]
print_dry_run @monitoring_apps_interface.dry.mute(monitor_app["id"], payload)
return 0
end
json_response = @monitoring_apps_interface.mute(monitor_app["id"], payload)
if options[:json]
puts as_json(json_response, options)
elsif !options[:quiet]
if params['muted'] != false
print_green_success "Muted app #{monitor_app['name']}"
else
print_green_success "Unmuted app #{monitor_app['name']}"
end
_get(monitor_app['id'], {})
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#mute_all(args) ⇒ Object
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 577
def mute_all(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage()
opts.on(nil, "--disable", "Unmute instead, the same as the unmute-all command") do
params['muted'] = false
params['enabled'] = false
end
opts. = "Mute all monitoring apps. This prevents the creation of new incidents."
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
end
optparse.parse!(args)
if args.count != 0
puts optparse
return 1
end
connect(options)
begin
payload = nil
if options[:payload]
payload = options[:payload]
else
payload = params
end
@monitoring_apps_interface.setopts(options)
if options[:dry_run]
print_dry_run @monitoring_apps_interface.dry.mute_all(payload)
return 0
end
json_response = @monitoring_apps_interface.mute_all(payload)
if options[:json]
puts as_json(json_response, options)
elsif !options[:quiet]
num_updated = json_response['updated']
if params['muted'] != false
print_green_success "Muted #{num_updated} apps"
else
print_green_success "Unmuted #{num_updated} apps"
end
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#remove(args) ⇒ Object
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 668
def remove(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name]")
build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :quiet, :remote])
end
optparse.parse!(args)
if args.count < 1
puts optparse
return 127
end
connect(options)
begin
monitor_app = find_monitoring_app_by_name_or_id(args[0])
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to delete monitoring app '#{monitor_app['name']}'?", options)
return false
end
payload = params
@monitoring_apps_interface.setopts(options)
if options[:dry_run]
print_dry_run @monitoring_apps_interface.dry.destroy(monitor_app["id"])
return
end
json_response = @monitoring_apps_interface.destroy(monitor_app["id"])
if options[:json]
puts as_json(json_response, options)
elsif !options[:quiet]
print_green_success "Deleted check app #{monitor_app['name']}"
end
return 0, nil
rescue RestClient::Exception => e
print_rest_exception(e, options)
return 1
end
end
|
#unmute(args) ⇒ Object
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 533
def unmute(args)
options = {}
params = {'muted' => false, 'enabled' => false}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name]")
build_common_options(opts, options, [:payload, :json, :dry_run, :remote, :quiet])
opts. = "Unmute a monitoring app." + "\n" +
"[name] is required. This is the name or id of a monitoring app."
end
optparse.parse!(args)
if args.count < 1
puts optparse
exit 1
end
connect(options)
begin
monitor_app = find_monitoring_app_by_name_or_id(args[0])
payload = nil
if options[:payload]
payload = options[:payload]
else
payload = params
end
@monitoring_apps_interface.setopts(options)
if options[:dry_run]
print_dry_run @monitoring_apps_interface.dry.mute(monitor_app["id"], payload)
return 0
end
json_response = @monitoring_apps_interface.mute(monitor_app["id"], payload)
if options[:json]
puts as_json(json_response, options)
elsif !options[:quiet]
print_green_success "Unmuted app #{monitor_app['name']}"
_get(monitor_app['id'], {})
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#unmute_all(args) ⇒ Object
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 626
def unmute_all(args)
options = {}
params = {'muted' => false, 'enabled' => false}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage()
build_common_options(opts, options, [:payload, :json, :dry_run, :remote, :quiet])
opts. = "Unmute all monitoring apps."
end
optparse.parse!(args)
if args.count != 0
puts optparse
return 1
end
connect(options)
begin
payload = nil
if options[:payload]
payload = options[:payload]
else
payload = params
end
@monitoring_apps_interface.setopts(options)
if options[:dry_run]
print_dry_run @monitoring_apps_interface.dry.mute_all(payload)
return 0
end
json_response = @monitoring_apps_interface.mute_all(payload)
if options[:json]
puts as_json(json_response, options)
elsif !options[:quiet]
num_updated = json_response['updated']
print_green_success "Unmuted #{num_updated} apps"
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#update(args) ⇒ Object
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
# File 'lib/morpheus/cli/commands/monitoring_apps_command.rb', line 383
def update(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name]")
opts.on('--name VALUE', String, "Name") do |val|
params['name'] = val
end
opts.on('--description VALUE', String, "Description") do |val|
params['description'] = val
end
opts.on('--minHappy VALUE', String, "Min Checks. This specifies the minimum number of checks within the app that must be happy to keep the app from becoming unhealthy.") do |val|
params['minHappy'] = val.to_i
end
opts.on('--severity VALUE', String, "Max Severity. Determines the maximum severity level this app can incur on an incident when failing. Default is critical") do |val|
params['severity'] = val
end
opts.on('--inUptime [on|off]', String, "Affects Availability. Default is on.") do |val|
params['inUptime'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
end
opts.on('--muted [on|off]', String, "Muted, Turns Affects Availability off.") do |val|
params['muted'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
end
opts.on('--checks LIST', Array, "Checks to include in this app, comma separated list of names or IDs.") do |list|
if list.size == 1 && ('[]' == list[0]) params['checks'] = []
else
params['checks'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
end
end
opts.on('--groups LIST', Array, "Check Groups to include in this app, comma separated list of names or IDs.") do |list|
if list.size == 1 && ('[]' == list[0]) params['checkGroups'] = []
else
params['checkGroups'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
end
end
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
opts. = "Update a monitoring app." + "\n" +
"[name] is required. This is the name or id of a monitoring app."
end
optparse.parse!(args)
if args.count != 1
print_error Morpheus::Terminal.angry_prompt
puts_error "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
return 1
end
connect(options)
begin
monitor_app = find_monitoring_app_by_name_or_id(args[0])
payload = nil
if options[:payload]
payload = options[:payload]
else
params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
if params['checks']
prompt_results = prompt_results(params, options, @api_client)
if prompt_results[:success]
params['checks'] = prompt_results[:data] unless prompt_results[:data].nil?
else
return 1
end
end
if params['checkGroups']
prompt_results = prompt_for_check_groups(params, options, @api_client)
if prompt_results[:success]
params['checkGroups'] = prompt_results[:data] unless prompt_results[:data].nil?
else
return 1
end
end
payload = {'monitorApp' => params}
end
@monitoring_apps_interface.setopts(options)
if options[:dry_run]
print_dry_run @monitoring_apps_interface.dry.update(monitor_app["id"], payload)
return
end
json_response = @monitoring_apps_interface.update(monitor_app["id"], payload)
if options[:json]
puts as_json(json_response, options)
elsif !options[:quiet]
print_green_success "Updated monitoring app #{monitor_app['name']}"
_get(monitor_app['id'], {})
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|