Class: Morpheus::Cli::MonitoringIncidentsCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand, MonitoringHelper
Defined in:
lib/morpheus/cli/monitoring_incidents_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from MonitoringHelper

#check_type_for_id, #check_type_for_name, #check_type_for_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_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_severity, #get_available_check_types, included, #monitoring_interface, #print_check_groups_table, #print_check_history_table, #print_check_notifications_table, #print_checks_table, #print_monitoring_apps_table

Methods included from CliCommand

#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_id_list, #parse_list_options, #parse_list_subtitles, #print, #print_error, #puts, #puts_error, #raise_command_error, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!

Instance Method Details

#_close(id, options) ⇒ Object



616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 616

def _close(id, options)

  begin
    incident = find_incident_by_id(id)
    already_closed = incident['status'] == 'closed'
    if options[:dry_run]
      print_dry_run @monitoring_interface.incidents.dry.close(incident['id'])
      return
    end
    json_response = @monitoring_interface.incidents.close(incident['id'])
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    elsif !options[:quiet]
      print_green_success json_response["msg"] || "Incident #{incident['id']} is now closed"
      # _get(incident['id'] {})
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#_get(id, options) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
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
271
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
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 197

def _get(id, options)

  begin
    incident = find_incident_by_id(id)
    if options[:dry_run]
      print_dry_run @monitoring_interface.incidents.dry.get(incident['id'])
      return
    end
    json_response = @monitoring_interface.incidents.get(incident['id'])
    incident = json_response['incident']
    
    if options[:include_fields]
      json_response = {"incident" => filter_data(json_response["incident"], options[:include_fields]) }
    end
    if options[:json]
      puts as_json(json_response, options)
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options)
      return 0
    elsif options[:csv]
      puts records_as_csv(json_response['incident'], options)
      return 0
    end

    print_h1 "Incident Details"
    print cyan
    description_cols = {
      "ID" => 'id',
      "Severity" => lambda {|it| format_severity(it['severity']) },
      "Name" => lambda {|it| it['displayName'] || it['name'] || 'No Subject' },
      "Start" => lambda {|it| format_local_dt(it['startDate']) },
      "End" => lambda {|it| format_local_dt(it['endDate']) },
      "Duration" => lambda {|it| format_duration(it['startDate'], it['endDate']) },
      "Status" => lambda {|it| format_monitoring_issue_status(it) },
      "Muted" => lambda {|it| it['inUptime'] ? 'No' : 'Yes' },
      "Visibility" => 'visibility',
      "Last Check" => lambda {|it| format_local_dt(it['lastCheckTime']) },
      "Last Error" => lambda {|it| it['lastError'] },
      "Comment" => 'comment',
      "Resolution" => 'resolution'
    }
    # description_cols.delete("End") if incident['endDate'].nil?
    description_cols.delete("Comment") if incident['comment'].empty?
    description_cols.delete("Resolution") if incident['resolution'].empty?
    # description_cols.delete("Last Check") if incident['lastCheckTime'].empty?
    # description_cols.delete("Last Error") if incident['lastError'].empty?
    print_description_list(description_cols, incident)
    # puts as_vertical_table(incident, description_cols)
    ## Issues

    issues = json_response["issues"]
    if issues && !issues.empty?
      print_h2 "Issues"
      print_incident_history_table(issues, options)
    else
      print "\n"
      puts "No checks involved in this incident"
    end

    ## History (MonitorIncidentEvent)
    if options[:show_history]
      # history_items = json_response["history"]
      # gotta go get it
      history_json_response = @monitoring_interface.incidents.history(incident["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_incident_history_table(history_items, options)
        print_results_pagination(history_json_response, {:label => "event", :n_label => "events"})
      else
        print "\n"
        puts "No history found for this incident"
      end
    end

    ## Members (MonitorIncidentNotifyEvent)
    if options[:show_notifications]
      # history_items = json_response["history"]
      # gotta go get it
      notifications_json_response = @monitoring_interface.incidents.notifications(incident["id"], {max: 10})
      notification_items = notifications_json_response["notifications"]
      if notification_items && notification_items.empty?
        print_h2 "Notifications"
        print_incident_notifications_table(notification_items, options)
        print_results_pagination(notifications_json_response, {:label => "notification", :n_label => "notifications"})
      else
        print "\n"
        puts "Nobody has been notified about this incident."
      end
    end

    print reset,"\n"

  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#_reopen(id, options) ⇒ Object



660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 660

def _reopen(id, options)

  begin
    incident = find_incident_by_id(id)
    already_open = incident['status'] == 'open'
    if already_open
      print bold,yellow,"Incident #{incident['id']} is already open",reset,"\n"
      return false
    end
    if options[:dry_run]
      print_dry_run @monitoring_interface.incidents.dry.reopen(incident['id'])
      return
    end
    json_response = @monitoring_interface.incidents.reopen(incident['id'])
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    elsif !options[:quiet]
      print_green_success json_response["msg"] || "Incident #{incident['id']} is now open"
      # _get(incident['id'] {})
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#close(args) ⇒ Object



595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 595

def close(args)
  options = {}
  optparse = OptionParser.new do|opts|
    opts.banner = subcommand_usage("[id list]")
    build_common_options(opts, options, [:auto_confirm, :quiet, :json, :dry_run, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    exit 1
  end
  connect(options)
  id_list = parse_id_list(args)
  unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to close #{id_list.size == 1 ? 'incident' : 'incidents'} #{anded_list(id_list)}?", options)
    exit 1
  end
  return run_command_for_each_arg(id_list) do |arg|
    _close(arg, options)
  end
end

#connect(opts) ⇒ Object



11
12
13
14
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 11

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @monitoring_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).monitoring
end

#get(args) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 173

def get(args)
  options = {}
  optparse = OptionParser.new do|opts|
    opts.banner = subcommand_usage("[id list]")
    opts.on(nil,'--history', "Display Incident History") do |val|
      options[:show_history] = true
    end
    opts.on(nil,'--notifications', "Display Incident Notifications") do |val|
      options[:show_notifications] = 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



16
17
18
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 16

def handle(args)
  handle_subcommand(args)
end

#history(args) ⇒ Object



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
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 298

def history(args)
  options = {}
  params = {}
  optparse = OptionParser.new do|opts|
    opts.banner = subcommand_usage("[id] [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, :csv, :fields, :json, :dry_run, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    exit 1
  end
  connect(options)
  begin
    incident = find_incident_by_id(args[0])
    # return false if incident.nil?
    
    [:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
      params[k] = options[k] unless options[k].nil?
    end
    # JD: lastUpdated 500ing, incidents don't have that property ? =o  Fix it!

    if options[:dry_run]
      print_dry_run @monitoring_interface.incidents.dry.history(incident['id'], params)
      return
    end

    json_response = @monitoring_interface.incidents.history(incident['id'], params)
    if options[:json]
      if options[:include_fields]
        json_response = {"history" => filter_data(json_response["history"], options[:include_fields]) }
      end
      puts as_json(json_response, options)
      return 0
    end
    if options[:csv]
      puts records_as_csv(json_response['history'], options)
      return 0
    end
    history_items = json_response['history']
    title = "Incident History: #{incident['id']}: #{incident['displayName'] || incident['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_incident_history_table(history_items, options)
      print_results_pagination(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



20
21
22
23
24
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
74
75
76
77
78
79
80
81
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 20

def list(args)
  options = {}
  params = {}
  optparse = OptionParser.new do|opts|
    opts.banner = subcommand_usage()
    opts.on('--status LIST', Array, "Filter by status. open, closed") do |list|
      params['status'] = list
    end
    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, :dry_run, :remote])
  end
  optparse.parse!(args)
  connect(options)
  begin
    [:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
      params[k] = options[k] unless options[k].nil?
    end
    if options[:dry_run]
      print_dry_run @monitoring_interface.incidents.dry.list(params)
      return
    end
    json_response = @monitoring_interface.incidents.list(params)
    if options[:include_fields]
      json_response = {"incidents" => filter_data(json_response["incidents"], options[:include_fields]) }
    end
    if options[:json]
      puts as_json(json_response, options)
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options)
      return 0
    elsif options[:csv]
      puts records_as_csv(json_response['incidents'], options)
      return 0
    end
    incidents = json_response['incidents']
    title = "Morpheus Monitoring Incidents"
    subtitles = []
    # if group
    #   subtitles << "Group: #{group['name']}".strip
    # end
    # if cloud
    #   subtitles << "Cloud: #{cloud['name']}".strip
    # end
    if params[:phrase]
      subtitles << "Search: #{params[:phrase]}".strip
    end
    print_h1 title, subtitles
    if incidents.empty?
      print cyan,"No incidents found.",reset,"\n"
    else
      print_incidents_table(incidents, options)
      print_results_pagination(json_response, {:label => "incident", :n_label => "incidents"})
    end
    print reset,"\n"
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#mute(args) ⇒ Object



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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 503

def mute(args)
  options = {}
  params = {'enabled' => true}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[id]")
    opts.on(nil, "--disable", "Disable mute state instead, the same as unmute") do
      params['enabled'] = false
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
    opts.footer = "Mute an incident." + "\n" +
                  "[id] is required. This is the id of an incident."
  end
  optparse.parse!(args)
  if args.count != 1
    puts optparse
    return 1
  end
  connect(options)
  begin
    incident = find_incident_by_id(args[0])
    # construct payload
    payload = nil
    if options[:payload]
      payload = options[:payload]
    else
      payload = params
    end
    if options[:dry_run]
      print_dry_run @monitoring_interface.incidents.dry.quarantine(incident["id"], payload)
      return 0
    end
    json_response = @monitoring_interface.incidents.quarantine(incident["id"], payload)
    if options[:json]
      puts as_json(json_response, options)
    elsif !options[:quiet]
      if params['enabled']
        print_green_success "Muted incident #{incident['id']}"
      else
        print_green_success "Unmuted incident #{incident['id']}"
      end
      _get(incident['id'], {})
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#notifications(args) ⇒ Object



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 360

def notifications(args)
  options = {}
  optparse = OptionParser.new do|opts|
    opts.banner = subcommand_usage("[id] [options]")
    build_common_options(opts, options, [:list, :json, :csv, :fields, :json, :dry_run, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    exit 1
  end
  connect(options)
  begin
    incident = find_incident_by_id(args[0])
    # return false if incident.nil?
    params = {}
    [:phrase, :offset, :max, :sort, :direction].each do |k|
      params[k] = options[k] unless options[k].nil?
    end
    
    if options[:dry_run]
      print_dry_run @monitoring_interface.incidents.dry.notifications(incident['id'], params)
      return
    end

    json_response = @monitoring_interface.incidents.notifications(incident['id'], params)
    if options[:json]
      if options[:include_fields]
        json_response = {"notifications" => filter_data(json_response["notifications"], options[:include_fields]) }
      end
      puts as_json(json_response, options)
      return 0
    end
    if options[:csv]
      puts records_as_csv(json_response['notifications'], options)
      return 0
    end
    notification_items = json_response['notifications']
    title = "Incident Notifications: #{incident['id']}: #{incident['displayName'] || incident['name']}"
    subtitles = []
    if params[:phrase]
      subtitles << "Search: #{params[:phrase]}".strip
    end
    print_h1 title, subtitles
    if notification_items.empty?
      print cyan,"No notifications found.",reset,"\n"
    else
      print_incident_history_table(notification_items, options)
      print_results_pagination(json_response, {:label => "notification", :n_label => "notifications"})
    end
    print reset,"\n"
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#reopen(args) ⇒ Object



639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 639

def reopen(args)
  options = {}
  optparse = OptionParser.new do|opts|
    opts.banner = subcommand_usage("[id list]")
    build_common_options(opts, options, [:auto_confirm, :quiet, :json, :dry_run, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    exit 1
  end
  connect(options)
  id_list = parse_id_list(args)
  unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to reopen #{id_list.size == 1 ? 'incident' : 'incidents'} #{anded_list(id_list)}?", options)
    exit 1
  end
  return run_command_for_each_arg(id_list) do |arg|
    _reopen(arg, options)
  end
end

#stats(args) ⇒ Object

this show date range counts and current open incidents it should be perhaps called 'summary' or 'dashboard' it is not stats about a particular incident



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 86

def stats(args)
  options = {}
  optparse = OptionParser.new do|opts|
    opts.banner = subcommand_usage()
    #opts.on('-j','--json', "JSON Output") do
    opts.on( '-m', '--max MAX', "Max open incidents to display. Default is 25" ) do |max|
      if max.to_s == 'all'
        options[:max] = 10000 # 'all'
      else
        options[:max] = max.to_i
      end
    end
    opts.on( '-o', '--offset OFFSET', "Offset open incidents results for pagination." ) do |offset|
      options[:offset] = offset.to_i.abs
    end
    build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :dry_run, :remote])
  end
  optparse.parse!(args)
  connect(options)
  begin
    params = {}
    [:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
      params[k] = options[k] unless options[k].nil?
    end
    if options[:dry_run]
      print_dry_run @monitoring_interface.incidents.dry.stats(params)
      return
    end
    json_response = @monitoring_interface.incidents.stats(params)
    if options[:json]
      if options[:include_fields]
        json_response.merge!({"openIncidents" => filter_data(json_response["openIncidents"], options[:include_fields])})
      end
      puts as_json(json_response, options)
      return 0
    end
    # if options[:csv]
    #   puts records_as_csv(json_response['openIncidents'], options)
    #   return 0
    # end
    open_incidents = json_response['openIncidents']
    open_incidents_count = json_response['openIncidentCount']
    stats = json_response['incidentStats']

    print_h1 "Morpheus Incidents: Stats"
    print cyan

    # print_h2 "Counts"
    # print_description_list({
    #   "Today" => 'today',
    #   "Week" => 'week',
    #   "Month" => 'month',
    # }, stats)

    if stats
      print justify_string("Today: #{stats['today']}", 20)
      print justify_string("Week: #{stats['week']}", 20)
      print justify_string("Month: #{stats['month']}", 20)
      print "\n"
    else
      puts "No stats"
    end

    if !open_incidents || open_incidents.size() == 0
      print bold,green,"0 open incidents",reset,"\n"
    else
      if open_incidents.size() == 1
        #print bold,yellow,"#{open_incidents.size()} open incident",reset,"\n"
        print_h2 "#{open_incidents.size()} open incident"
      else
        #print bold,yellow,"#{open_incidents.size()} open incidents",reset,"\n"
        print_h2 "#{open_incidents.size()} open incidents"
      end
      options[:max] ||= 20
      
      print_incidents_table(open_incidents)
      if open_incidents.size > 0
        print_results_pagination(size: open_incidents.size, total: open_incidents_count, offset: options[:offset])
      end
    end
    print reset,"\n"
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#unmute(args) ⇒ Object



552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 552

def unmute(args)
  options = {}
  params = {'enabled' => false}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[id]")
    build_common_options(opts, options, [:payload, :json, :dry_run, :quiet, :remote])
    opts.footer = "Unmute an incident." + "\n" +
                  "[id] is required. This is the id of an incident."
  end
  optparse.parse!(args)
  if args.count != 1
    puts optparse
    return 1
  end
  connect(options)

  begin
    incident = find_incident_by_id(args[0])
    # construct payload
    payload = nil
    if options[:payload]
      payload = options[:payload]
    else
      payload = params
    end
    if options[:dry_run]
      print_dry_run @monitoring_interface.incidents.dry.quarantine(incident["id"], payload)
      return 0
    end
    json_response = @monitoring_interface.incidents.quarantine(incident["id"], payload)
    if options[:json]
      puts as_json(json_response, options)
    elsif !options[:quiet]
      print_green_success "Unmuted incident #{incident['id']}"
      _get(incident['id'], {})
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update(args) ⇒ Object



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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/morpheus/cli/monitoring_incidents_command.rb', line 417

def update(args)
  options = {}
  params = {}
  optparse = OptionParser.new do|opts|
    opts.banner = subcommand_usage("[id]")
    opts.on("-c", "--comment STRING", String, "Comment on this incident") do |val|
      params['comment'] = val == 'null' ? nil : val
    end
    opts.on("--resolution STRING", String, "Description of the resolution to this incident") do |val|
      params['resolution'] = val == 'null' ? nil : val
    end
    opts.on("--status STATUS", String, "Set status (open or closed)") do |val|
      params['status'] = val
    end
    opts.on("--severity STATUS", String, "Set severity (critical, warning or info)") do |val|
      params['severity'] = val
    end
    opts.on("--name STRING", String, "Set display name (subject)") do |val|
      params['name'] = val == 'null' ? nil : val
    end
    opts.on("--startDate TIME", String, "Set start time") do |val|
      begin
        params['startDate'] = parse_time(val).utc.iso8601
      rescue => e
        raise OptionParser::InvalidArgument.new "Failed to parse --startDate '#{val}'. Error: #{e}"
      end
    end
    opts.on("--endDate TIME", String, "Set end time") do |val|
      begin
        params['endDate'] = parse_time(val).utc.iso8601
      rescue => e
        raise OptionParser::InvalidArgument.new "Failed to parse --endDate '#{val}'. Error: #{e}"
      end
    end
    opts.on("--inUptime BOOL", String, "Set 'In Availability'") do |val|
      params['inUptime'] = ['true','on'].include?(val.to_s.strip)
    end
    build_common_options(opts, options, [:json, :dry_run, :quiet, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    exit 1
  end
  connect(options)

  begin
    incident = find_incident_by_id(args[0])

    if params['status'] == 'closed'
      unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to close the incident '#{incident['id']}'?", options)
        return false
      end
    end

    if params.empty?
      print_red_alert "Specify atleast one option to update"
      puts optparse
      exit 1
    end

    payload = {
      'incident' => {id: incident["id"]}
    }
    payload['incident'].merge!(params)

    if options[:dry_run]
      print_dry_run @monitoring_interface.incidents.dry.update(incident["id"], payload)
      return
    end

    json_response = @monitoring_interface.incidents.update(incident["id"], payload)
    if options[:json]
      puts as_json(json_response, options)
    elsif !options[:quiet]
      print_green_success "Updated incident #{incident['id']}"
      _get(incident['id'], {})
    end

  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end