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
@@ -8,11 +8,11 @@ require 'table_print'
|
|
8
8
|
require 'morpheus/cli/cli_command'
|
9
9
|
require 'morpheus/cli/mixins/provisioning_helper'
|
10
10
|
|
11
|
-
class Morpheus::Cli::
|
11
|
+
class Morpheus::Cli::MonitoringContactsCommand
|
12
12
|
include Morpheus::Cli::CliCommand
|
13
13
|
include Morpheus::Cli::MonitoringHelper
|
14
14
|
|
15
|
-
set_command_name :'
|
15
|
+
set_command_name :'monitor-contacts'
|
16
16
|
|
17
17
|
register_subcommands :list, :get, :add, :update, :remove
|
18
18
|
|
@@ -5,16 +5,10 @@ class Morpheus::Cli::MonitoringGroupsCommand
|
|
5
5
|
include Morpheus::Cli::CliCommand
|
6
6
|
include Morpheus::Cli::MonitoringHelper
|
7
7
|
|
8
|
-
set_command_name :'
|
9
|
-
register_subcommands :list, :get, :add, :update, :remove
|
10
|
-
|
11
|
-
|
12
|
-
set_command_hidden # remove me when implemented
|
8
|
+
set_command_name :'monitor-groups'
|
9
|
+
register_subcommands :list, :get, :add, :update, :remove
|
10
|
+
register_subcommands :mute, :unmute, :history #, :statistics
|
13
11
|
|
14
|
-
def initialize()
|
15
|
-
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
16
|
-
end
|
17
|
-
|
18
12
|
def connect(opts)
|
19
13
|
@api_client = establish_remote_appliance_connection(opts)
|
20
14
|
@monitoring_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).monitoring
|
@@ -24,6 +18,542 @@ class Morpheus::Cli::MonitoringGroupsCommand
|
|
24
18
|
handle_subcommand(args)
|
25
19
|
end
|
26
20
|
|
27
|
-
|
21
|
+
def list(args)
|
22
|
+
options = {}
|
23
|
+
params = {}
|
24
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
25
|
+
opts.banner = subcommand_usage()
|
26
|
+
opts.on('--status VALUE', Array, "Filter by status. error,healthy,warning,muted") do |val|
|
27
|
+
params['status'] = val
|
28
|
+
end
|
29
|
+
build_common_options(opts, options, [:list, :last_updated, :json, :yaml, :csv, :fields, :dry_run, :remote])
|
30
|
+
end
|
31
|
+
optparse.parse!(args)
|
32
|
+
connect(options)
|
33
|
+
begin
|
34
|
+
[:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
|
35
|
+
params[k] = options[k] unless options[k].nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
if options[:dry_run]
|
39
|
+
print_dry_run @monitoring_interface.groups.dry.list(params)
|
40
|
+
return
|
41
|
+
end
|
42
|
+
|
43
|
+
json_response = @monitoring_interface.groups.list(params)
|
44
|
+
if options[:include_fields]
|
45
|
+
json_response = {"checkGroups" => filter_data(json_response["checkGroups"], options[:include_fields]) }
|
46
|
+
end
|
47
|
+
if options[:json]
|
48
|
+
puts as_json(json_response, options)
|
49
|
+
return 0
|
50
|
+
elsif options[:csv]
|
51
|
+
puts records_as_csv(json_response['checkGroups'], options)
|
52
|
+
return 0
|
53
|
+
elsif options[:yaml]
|
54
|
+
puts as_yaml(json_response, options)
|
55
|
+
return 0
|
56
|
+
end
|
57
|
+
check_groups = json_response['checkGroups']
|
58
|
+
title = "Morpheus Monitoring Check Groups"
|
59
|
+
subtitles = []
|
60
|
+
# if group
|
61
|
+
# subtitles << "Group: #{group['name']}".strip
|
62
|
+
# end
|
63
|
+
# if cloud
|
64
|
+
# subtitles << "Cloud: #{cloud['name']}".strip
|
65
|
+
# end
|
66
|
+
if params[:phrase]
|
67
|
+
subtitles << "Search: #{params[:phrase]}".strip
|
68
|
+
end
|
69
|
+
print_h1 title, subtitles
|
70
|
+
if check_groups.empty?
|
71
|
+
print cyan,"No check groups found.",reset,"\n"
|
72
|
+
else
|
73
|
+
print_check_groups_table(check_groups, options)
|
74
|
+
print_results_pagination(json_response, {:label => "check group", :n_label => "check groups"})
|
75
|
+
# print_results_pagination(json_response)
|
76
|
+
end
|
77
|
+
print reset,"\n"
|
78
|
+
rescue RestClient::Exception => e
|
79
|
+
print_rest_exception(e, options)
|
80
|
+
exit 1
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def get(args)
|
85
|
+
options = {}
|
86
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
87
|
+
opts.banner = subcommand_usage("[id list]")
|
88
|
+
opts.on(nil,'--history', "Display Check Group History") do |val|
|
89
|
+
options[:show_history] = true
|
90
|
+
end
|
91
|
+
# opts.on(nil,'--statistics', "Display Statistics") do |val|
|
92
|
+
# options[:show_statistics] = true
|
93
|
+
# end
|
94
|
+
build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
|
95
|
+
end
|
96
|
+
optparse.parse!(args)
|
97
|
+
if args.count < 1
|
98
|
+
puts optparse
|
99
|
+
exit 1
|
100
|
+
end
|
101
|
+
connect(options)
|
102
|
+
id_list = parse_id_list(args)
|
103
|
+
return run_command_for_each_arg(id_list) do |arg|
|
104
|
+
_get(arg, options)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def _get(id, options)
|
109
|
+
|
110
|
+
begin
|
111
|
+
check_group = find_check_group_by_name_or_id(id)
|
112
|
+
|
113
|
+
if options[:dry_run]
|
114
|
+
print_dry_run @monitoring_interface.groups.dry.get(check_group['id'])
|
115
|
+
return
|
116
|
+
end
|
117
|
+
json_response = @monitoring_interface.groups.get(check_group['id'])
|
118
|
+
check_group = json_response['checkGroup']
|
119
|
+
if options[:include_fields]
|
120
|
+
json_response = {"checkGroup" => filter_data(json_response["checkGroup"], options[:include_fields]) }
|
121
|
+
end
|
122
|
+
if options[:json]
|
123
|
+
puts as_json(json_response, options)
|
124
|
+
return 0
|
125
|
+
elsif options[:yaml]
|
126
|
+
puts as_yaml(json_response, options)
|
127
|
+
return 0
|
128
|
+
elsif options[:csv]
|
129
|
+
puts records_as_csv([json_response['checkGroup']], options)
|
130
|
+
return 0
|
131
|
+
end
|
132
|
+
|
133
|
+
print_h1 "Check Group Details"
|
134
|
+
print cyan
|
135
|
+
description_cols = {
|
136
|
+
"ID" => lambda {|it| it['id'] },
|
137
|
+
"Status" => lambda {|it| format_monitoring_check_status(it, true) },
|
138
|
+
"Name" => lambda {|it| it['name'] },
|
139
|
+
"Time" => lambda {|it| format_local_dt(it['lastRunDate']) },
|
140
|
+
"Availability" => lambda {|it| it['availability'] ? "#{it['availability'].to_f.round(3).to_s}%" : "N/A"},
|
141
|
+
"Response Time" => lambda {|it| it['lastTimer'] ? "#{it['lastTimer']}ms" : "N/A" },
|
142
|
+
# "Last Metric" => lambda {|it| it['lastMetric'] ? "#{it['lastMetric']}" : "N/A" },
|
143
|
+
"Type" => lambda {|it| format_monitoring_check_type(it) },
|
144
|
+
}
|
145
|
+
print_description_list(description_cols, check_group)
|
146
|
+
|
147
|
+
## Chart Stats
|
148
|
+
|
149
|
+
|
150
|
+
## Activity
|
151
|
+
|
152
|
+
## Checks in this check group
|
153
|
+
checks = json_response["checks"]
|
154
|
+
if checks && !checks.empty?
|
155
|
+
print_h2 "Checks"
|
156
|
+
# print as_pretty_table(check_groups, [:id, {"Check Group" => :name}], options)
|
157
|
+
print_checks_table(checks, options)
|
158
|
+
else
|
159
|
+
# print "\n"
|
160
|
+
# puts "No checks found..."
|
161
|
+
end
|
162
|
+
|
163
|
+
## Open Incidents
|
164
|
+
|
165
|
+
open_incidents = json_response["openIncidents"]
|
166
|
+
if open_incidents && !open_incidents.empty?
|
167
|
+
print_h2 "Open Incidents"
|
168
|
+
# puts "\n(table coming soon...)\n"
|
169
|
+
puts JSON.pretty_generate(open_incidents)
|
170
|
+
# todo: move this to MonitoringHelper ?
|
171
|
+
# print_incidents_table(issues, options)
|
172
|
+
else
|
173
|
+
print "\n", cyan
|
174
|
+
puts "No open incidents for this check group"
|
175
|
+
end
|
176
|
+
|
177
|
+
## History (plain old Hash)
|
178
|
+
if options[:show_history]
|
179
|
+
# history_items = json_response["history"]
|
180
|
+
# gotta go get it
|
181
|
+
history_json_response = @monitoring_interface.groups.history(check_group["id"], {})
|
182
|
+
history_items = history_json_response["history"] || history_json_response["events"] || history_json_response["issues"]
|
183
|
+
issues = history_items
|
184
|
+
if history_items && !history_items.empty?
|
185
|
+
print_h2 "History"
|
186
|
+
print_check_history_table(history_items, options)
|
187
|
+
print_results_pagination(history_json_response, {:label => "event", :n_label => "events"})
|
188
|
+
else
|
189
|
+
print "\n"
|
190
|
+
puts "No history found for this check group"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
## Statistics (Hash)
|
195
|
+
if options[:show_statistics]
|
196
|
+
# todo....
|
197
|
+
end
|
198
|
+
|
199
|
+
print reset,"\n"
|
200
|
+
|
201
|
+
rescue RestClient::Exception => e
|
202
|
+
print_rest_exception(e, options)
|
203
|
+
exit 1
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def history(args)
|
208
|
+
options = {}
|
209
|
+
params = {}
|
210
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
211
|
+
opts.banner = subcommand_usage("[name] [options]")
|
212
|
+
# opts.on('--status LIST', Array, "Filter by status. open, closed") do |list|
|
213
|
+
# params['status'] = list
|
214
|
+
# end
|
215
|
+
opts.on('--severity LIST', Array, "Filter by severity. critical, warning, info") do |list|
|
216
|
+
params['severity'] = list
|
217
|
+
end
|
218
|
+
build_common_options(opts, options, [:list, :last_updated, :json, :yaml, :csv, :fields, :json, :dry_run, :remote])
|
219
|
+
end
|
220
|
+
optparse.parse!(args)
|
221
|
+
if args.count < 1
|
222
|
+
puts optparse
|
223
|
+
exit 1
|
224
|
+
end
|
225
|
+
connect(options)
|
226
|
+
begin
|
227
|
+
check_group = find_check_group_by_name_or_id(args[0])
|
228
|
+
return 1 if check_group.nil?
|
229
|
+
|
230
|
+
[:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
|
231
|
+
params[k] = options[k] unless options[k].nil?
|
232
|
+
end
|
233
|
+
# JD: lastUpdated 500ing, checks don't have that property ? =o Fix it!
|
234
|
+
|
235
|
+
if options[:dry_run]
|
236
|
+
print_dry_run @monitoring_interface.groups.dry.history(check_group['id'], params)
|
237
|
+
return
|
238
|
+
end
|
239
|
+
|
240
|
+
json_response = @monitoring_interface.groups.history(check_group['id'], params)
|
241
|
+
if options[:json]
|
242
|
+
if options[:include_fields]
|
243
|
+
json_response = {"history" => filter_data(json_response["history"], options[:include_fields]) }
|
244
|
+
end
|
245
|
+
puts as_json(json_response, options)
|
246
|
+
return 0
|
247
|
+
end
|
248
|
+
if options[:csv]
|
249
|
+
puts records_as_csv(json_response['history'], options)
|
250
|
+
return 0
|
251
|
+
end
|
252
|
+
history_items = json_response['history']
|
253
|
+
title = "Check Group History: #{check_group['id']}: #{check_group['displayName'] || check_group['name']}"
|
254
|
+
subtitles = []
|
255
|
+
if params[:phrase]
|
256
|
+
subtitles << "Search: #{params[:phrase]}".strip
|
257
|
+
end
|
258
|
+
print_h1 title, subtitles
|
259
|
+
if history_items.empty?
|
260
|
+
print cyan,"No history found.",reset,"\n"
|
261
|
+
else
|
262
|
+
print_check_history_table(history_items, options)
|
263
|
+
print_results_pagination(json_response, {:label => "event", :n_label => "events"})
|
264
|
+
end
|
265
|
+
print reset,"\n"
|
266
|
+
rescue RestClient::Exception => e
|
267
|
+
print_rest_exception(e, options)
|
268
|
+
exit 1
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def add(args)
|
273
|
+
options = {}
|
274
|
+
params = {'inUptime' => true, 'severity' => 'critical'}
|
275
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
276
|
+
opts.banner = subcommand_usage("[name]")
|
277
|
+
opts.on('--name VALUE', String, "Name") do |val|
|
278
|
+
params['name'] = val
|
279
|
+
end
|
280
|
+
opts.on('--description VALUE', String, "Description") do |val|
|
281
|
+
params['description'] = val
|
282
|
+
end
|
283
|
+
opts.on('--minHappy VALUE', String, "Min Checks. This specifies the minimum number of checks within the group that must be happy to keep the group from becoming unhealthy.") do |val|
|
284
|
+
params['minHappy'] = val.to_i
|
285
|
+
end
|
286
|
+
opts.on('--severity VALUE', String, "Max Severity. Determines the maximum severity level this group can incur on an incident when failing. Default is critical") do |val|
|
287
|
+
params['severity'] = val
|
288
|
+
end
|
289
|
+
opts.on('--inUptime [on|off]', String, "Affects Availability. Default is on.") do |val|
|
290
|
+
params['inUptime'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
|
291
|
+
end
|
292
|
+
opts.on('--checks LIST', Array, "Checks to include in this group, comma separated list of IDs") do |list|
|
293
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
294
|
+
params['checks'] = []
|
295
|
+
else
|
296
|
+
params['checks'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
297
|
+
end
|
298
|
+
end
|
299
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
|
300
|
+
opts.footer = "Create a new group of monitoring checks." + "\n" +
|
301
|
+
"[name] is required and can be passed as --name instead."
|
302
|
+
end
|
303
|
+
optparse.parse!(args)
|
304
|
+
if args.count > 1
|
305
|
+
print_error Morpheus::Terminal.angry_prompt
|
306
|
+
puts_error "wrong number of arguments, expected 0-1 and got #{args.count}\n#{optparse}"
|
307
|
+
return 1
|
308
|
+
end
|
309
|
+
# support [name] as first argument
|
310
|
+
if args[0]
|
311
|
+
params['name'] = args[0]
|
312
|
+
end
|
313
|
+
connect(options)
|
314
|
+
begin
|
315
|
+
# construct payload
|
316
|
+
payload = nil
|
317
|
+
if options[:payload]
|
318
|
+
payload = options[:payload]
|
319
|
+
else
|
320
|
+
# merge -O options into normally parsed options
|
321
|
+
params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
322
|
+
if params['checks']
|
323
|
+
params['checks'] = params['checks'].collect {|it| it.to_i }
|
324
|
+
end
|
325
|
+
# todo: prompt?
|
326
|
+
payload = {'checkGroup' => params}
|
327
|
+
end
|
328
|
+
if options[:dry_run]
|
329
|
+
print_dry_run @monitoring_interface.groups.dry.create(payload)
|
330
|
+
return
|
331
|
+
end
|
332
|
+
json_response = @monitoring_interface.groups.create(payload)
|
333
|
+
if options[:json]
|
334
|
+
puts as_json(json_response, options)
|
335
|
+
elsif !options[:quiet]
|
336
|
+
check_group = json_response['checkGroup']
|
337
|
+
print_green_success "Added check group #{check_group['name']}"
|
338
|
+
_get(check_group['id'], {})
|
339
|
+
end
|
340
|
+
return 0
|
341
|
+
rescue RestClient::Exception => e
|
342
|
+
print_rest_exception(e, options)
|
343
|
+
exit 1
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
|
348
|
+
def update(args)
|
349
|
+
options = {}
|
350
|
+
params = {}
|
351
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
352
|
+
opts.banner = subcommand_usage("[name]")
|
353
|
+
opts.on('--name VALUE', String, "Name for this check group") do |val|
|
354
|
+
params['name'] = val
|
355
|
+
end
|
356
|
+
opts.on('--description VALUE', String, "Description") do |val|
|
357
|
+
params['description'] = val
|
358
|
+
end
|
359
|
+
opts.on('--minHappy VALUE', String, "Min Checks. This specifies the minimum number of checks within the group that must be happy to keep the group from becoming unhealthy.") do |val|
|
360
|
+
params['minHappy'] = val.to_i
|
361
|
+
end
|
362
|
+
opts.on('--severity VALUE', String, "Max Severity. Determines the maximum severity level this group can incur on an incident when failing. Default is critical") do |val|
|
363
|
+
params['severity'] = val
|
364
|
+
end
|
365
|
+
opts.on('--inUptime [on|off]', String, "Affects Availability. Default is on.") do |val|
|
366
|
+
params['inUptime'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
|
367
|
+
end
|
368
|
+
opts.on('--checks LIST', Array, "Checks to include in this group, comma separated list of IDs") do |list|
|
369
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
370
|
+
params['checks'] = []
|
371
|
+
else
|
372
|
+
params['checks'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
373
|
+
end
|
374
|
+
end
|
375
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
|
376
|
+
opts.footer = "Update a check group." + "\n" +
|
377
|
+
"[name] is required. This is the name or id of a check group."
|
378
|
+
end
|
379
|
+
optparse.parse!(args)
|
380
|
+
if args.count != 1
|
381
|
+
print_error Morpheus::Terminal.angry_prompt
|
382
|
+
puts_error "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
|
383
|
+
return 1
|
384
|
+
end
|
385
|
+
connect(options)
|
386
|
+
begin
|
387
|
+
check_group = find_check_group_by_name_or_id(args[0])
|
388
|
+
# construct payload
|
389
|
+
payload = nil
|
390
|
+
if options[:payload]
|
391
|
+
payload = options[:payload]
|
392
|
+
else
|
393
|
+
# merge -O options into normally parsed options
|
394
|
+
params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
395
|
+
if params['checks']
|
396
|
+
params['checks'] = params['checks'].collect {|it| it.to_i }
|
397
|
+
end
|
398
|
+
# todo: prompt?
|
399
|
+
payload = {'checkGroup' => params}
|
400
|
+
end
|
401
|
+
if options[:dry_run]
|
402
|
+
print_dry_run @monitoring_interface.groups.dry.update(check_group["id"], payload)
|
403
|
+
return
|
404
|
+
end
|
405
|
+
json_response = @monitoring_interface.groups.update(check_group["id"], payload)
|
406
|
+
if options[:json]
|
407
|
+
puts as_json(json_response, options)
|
408
|
+
elsif !options[:quiet]
|
409
|
+
print_green_success "Updated check group #{check_group['name']}"
|
410
|
+
_get(check_group['id'], {})
|
411
|
+
end
|
412
|
+
return 0
|
413
|
+
rescue RestClient::Exception => e
|
414
|
+
print_rest_exception(e, options)
|
415
|
+
exit 1
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
def mute(args)
|
420
|
+
options = {}
|
421
|
+
params = {'enabled' => true}
|
422
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
423
|
+
opts.banner = subcommand_usage("[name]")
|
424
|
+
opts.on(nil, "--disable", "Disable mute, the same as unmute") do
|
425
|
+
params['enabled'] = false
|
426
|
+
end
|
427
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
|
428
|
+
opts.footer = "Mute a check group. This prevents it from creating new incidents." + "\n" +
|
429
|
+
"[name] is required. This is the name or id of a check group."
|
430
|
+
end
|
431
|
+
optparse.parse!(args)
|
432
|
+
if args.count != 1
|
433
|
+
puts optparse
|
434
|
+
return 1
|
435
|
+
end
|
436
|
+
connect(options)
|
437
|
+
begin
|
438
|
+
check_group = find_check_group_by_name_or_id(args[0])
|
439
|
+
# construct payload
|
440
|
+
payload = nil
|
441
|
+
if options[:payload]
|
442
|
+
payload = options[:payload]
|
443
|
+
else
|
444
|
+
payload = params
|
445
|
+
end
|
446
|
+
if options[:dry_run]
|
447
|
+
print_dry_run @monitoring_interface.groups.dry.quarantine(check_group["id"], payload)
|
448
|
+
return 0
|
449
|
+
end
|
450
|
+
json_response = @monitoring_interface.groups.quarantine(check_group["id"], payload)
|
451
|
+
if options[:json]
|
452
|
+
puts as_json(json_response, options)
|
453
|
+
elsif !options[:quiet]
|
454
|
+
if params['enabled']
|
455
|
+
print_green_success "Muted group #{check_group['name']}"
|
456
|
+
else
|
457
|
+
print_green_success "Unmuted group #{check_group['name']}"
|
458
|
+
end
|
459
|
+
_get(monitor_app['id'], {})
|
460
|
+
end
|
461
|
+
return 0
|
462
|
+
rescue RestClient::Exception => e
|
463
|
+
print_rest_exception(e, options)
|
464
|
+
exit 1
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
def unmute(args)
|
469
|
+
options = {}
|
470
|
+
params = {'enabled' => false}
|
471
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
472
|
+
opts.banner = subcommand_usage("[name]")
|
473
|
+
build_common_options(opts, options, [:payload, :json, :dry_run, :remote, :quiet])
|
474
|
+
opts.footer = "Unmute a check group." + "\n" +
|
475
|
+
"[name] is required. This is the name or id of a check."
|
476
|
+
end
|
477
|
+
optparse.parse!(args)
|
478
|
+
if args.count != 1
|
479
|
+
puts optparse
|
480
|
+
return 1
|
481
|
+
end
|
482
|
+
connect(options)
|
483
|
+
|
484
|
+
begin
|
485
|
+
check_group = find_check_group_by_name_or_id(args[0])
|
486
|
+
# construct payload
|
487
|
+
payload = nil
|
488
|
+
if options[:payload]
|
489
|
+
payload = options[:payload]
|
490
|
+
else
|
491
|
+
payload = params
|
492
|
+
end
|
493
|
+
if options[:dry_run]
|
494
|
+
print_dry_run @monitoring_interface.groups.dry.quarantine(check_group["id"], payload)
|
495
|
+
return 0
|
496
|
+
end
|
497
|
+
json_response = @monitoring_interface.groups.quarantine(check_group["id"], payload)
|
498
|
+
if options[:json]
|
499
|
+
puts as_json(json_response, options)
|
500
|
+
elsif !options[:quiet]
|
501
|
+
print_green_success "Unmuted group #{check_group['name']}"
|
502
|
+
_get(check_group['id'], {})
|
503
|
+
end
|
504
|
+
return 0
|
505
|
+
rescue RestClient::Exception => e
|
506
|
+
print_rest_exception(e, options)
|
507
|
+
exit 1
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
def remove(args)
|
512
|
+
options = {}
|
513
|
+
params = {}
|
514
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
515
|
+
opts.banner = subcommand_usage("[name]")
|
516
|
+
build_common_options(opts, options, [:json, :dry_run, :quiet])
|
517
|
+
end
|
518
|
+
optparse.parse!(args)
|
519
|
+
if args.count < 1
|
520
|
+
puts optparse
|
521
|
+
return 127
|
522
|
+
end
|
523
|
+
connect(options)
|
524
|
+
|
525
|
+
begin
|
526
|
+
check_group = find_check_group_by_name_or_id(args[0])
|
527
|
+
|
528
|
+
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to delete check group '#{check_group['name']}'?", options)
|
529
|
+
return false
|
530
|
+
end
|
531
|
+
|
532
|
+
# payload = {
|
533
|
+
# 'checkGroup' => {id: check_group["id"]}
|
534
|
+
# }
|
535
|
+
# payload['checkGroup'].merge!(check_group)
|
536
|
+
payload = params
|
537
|
+
|
538
|
+
if options[:dry_run]
|
539
|
+
print_dry_run @monitoring_interface.groups.dry.destroy(check_group["id"])
|
540
|
+
return
|
541
|
+
end
|
542
|
+
|
543
|
+
json_response = @monitoring_interface.groups.destroy(check_group["id"])
|
544
|
+
if options[:json]
|
545
|
+
puts as_json(json_response, options)
|
546
|
+
elsif !options[:quiet]
|
547
|
+
print_green_success "Deleted check group #{check_group['name']}"
|
548
|
+
end
|
549
|
+
return 0, nil
|
550
|
+
rescue RestClient::Exception => e
|
551
|
+
print_rest_exception(e, options)
|
552
|
+
return 1
|
553
|
+
end
|
554
|
+
end
|
555
|
+
|
556
|
+
|
557
|
+
private
|
28
558
|
|
29
559
|
end
|