Class: WavefrontCli::Alert
Overview
CLI coverage for the v2 ‘alert’ API.
Constant Summary
Constants included
from Constants
Constants::ALL_PAGE_SIZE, Constants::DEFAULT_CONFIG, Constants::DEFAULT_OPTS, Constants::EVENT_STATE_DIR, Constants::HUMAN_TIME_FORMAT, Constants::HUMAN_TIME_FORMAT_MS, Constants::SEARCH_SPLIT
Instance Attribute Summary
Attributes inherited from Base
#klass, #klass_word, #options, #wf
Instance Method Summary
collapse
Methods included from Mixin::Acl
#_acl_action, #do_acl_clear, #do_acl_grant, #do_acl_revoke, #do_acls, #everyone_id, #grant_modify, #grant_view, #print_status, #revoke_modify, #revoke_view
Methods included from Mixin::Tag
#do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_pathsearch, #do_tag_set, #do_tags
Methods inherited from Base
#_sdk_class, #cannot_noop!, #check_response_blocks, #check_status, #cli_output_class, #conds_to_query, #dispatch, #display, #display_api_error, #display_no_api_response, #do_dump, #do_import, #do_list, #do_search, #do_set, #do_undelete, #dump_json, #dump_yaml, #extract_values, #failed_validation_message, #format_var, #handle_error, #handle_response, #hcl_fields, #import_message, #import_object, #import_update, #initialize, #item_dump_call, #load_display_class, #load_file, #load_from_stdin, #load_json, #load_yaml, #matching_method, #method_word_list, #mk_creds, #mk_opts, #name_of_do_method, #no_api_response, #ok_exit, #one_or_all, #options_and_exit, #parseable_output, #range_hash, #run, #search_key, #smart_delete, #smart_delete_message, #status_error_handler, #unsupported_format_message, #validate_id, #validate_input, #validate_opts, #validate_tags, #validator_exception, #validator_method, #warning_message
Instance Method Details
#do_clone ⇒ Object
36
37
38
|
# File 'lib/wavefront-cli/alert.rb', line 36
def do_clone
wf.clone(options[:'<id>'], options[:version]&.to_i)
end
|
#do_currently ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/wavefront-cli/alert.rb', line 52
def do_currently
state = options[:'<state>'].to_s
if wf.respond_to?(state)
in_state(state)
else
abort format("'%<state>s' is not a valid alert state.", state: state)
end
end
|
#do_delete ⇒ Object
32
33
34
|
# File 'lib/wavefront-cli/alert.rb', line 32
def do_delete
smart_delete
end
|
#do_describe ⇒ Object
20
21
22
|
# File 'lib/wavefront-cli/alert.rb', line 20
def do_describe
wf.describe(options[:'<id>'], options[:version])
end
|
#do_firing ⇒ Object
62
63
64
|
# File 'lib/wavefront-cli/alert.rb', line 62
def do_firing
in_state(:firing)
end
|
#do_history ⇒ Object
48
49
50
|
# File 'lib/wavefront-cli/alert.rb', line 48
def do_history
wf.history(options[:'<id>'], options[:offset], options[:limit])
end
|
#do_install ⇒ Object
80
81
82
|
# File 'lib/wavefront-cli/alert.rb', line 80
def do_install
wf.install(options[:'<id>'])
end
|
#do_latest ⇒ Object
44
45
46
|
# File 'lib/wavefront-cli/alert.rb', line 44
def do_latest
wf.versions(options[:'<id>'])
end
|
#do_queries ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/wavefront-cli/alert.rb', line 70
def do_queries
resp, data = one_or_all
resp.tap do |r|
r.response.items = data.map do |a|
{ id: a.id, condition: a.condition }
end
end
end
|
#do_snooze ⇒ Object
24
25
26
|
# File 'lib/wavefront-cli/alert.rb', line 24
def do_snooze
wf.snooze(options[:'<id>'], options[:time])
end
|
#do_snoozed ⇒ Object
66
67
68
|
# File 'lib/wavefront-cli/alert.rb', line 66
def do_snoozed
in_state(:snoozed)
end
|
#do_summary ⇒ Object
40
41
42
|
# File 'lib/wavefront-cli/alert.rb', line 40
def do_summary
wf.summary
end
|
#do_uninstall ⇒ Object
84
85
86
|
# File 'lib/wavefront-cli/alert.rb', line 84
def do_uninstall
wf.uninstall(options[:'<id>'])
end
|
#do_unsnooze ⇒ Object
28
29
30
|
# File 'lib/wavefront-cli/alert.rb', line 28
def do_unsnooze
wf.unsnooze(options[:'<id>'])
end
|
#find_in_state(status) ⇒ Object
Does the work for #in_state
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/wavefront-cli/alert.rb', line 107
def find_in_state(status)
search = do_search([format('status=%<status>s', status: status)])
return if options[:noop]
items = search.response.items.map do |i|
{ name: i.name, id: i.id, time: state_time(i) }
end
search.tap { |s| s.response[:items] = items }
end
|
#import_fields ⇒ Object
15
16
17
18
|
# File 'lib/wavefront-cli/alert.rb', line 15
def import_fields
%i[name condition minutes target severity displayExpression
tags additionalInformation resolveAfterMinutes]
end
|
#import_to_create(raw) ⇒ Object
Take a previously exported alert, and construct a hash which create() can use to re-create it.
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/wavefront-cli/alert.rb', line 136
def import_to_create(raw)
import_fields.each_with_object({}) { |k, a| a[k.to_sym] = raw[k] }
.tap do |ret|
if raw.key?(:resolveAfterMinutes)
ret[:resolveMinutes] = raw[:resolveAfterMinutes]
end
if raw.key?('customerTagsWithCounts')
ret[:sharedTags] = raw['customerTagsWithCounts'].keys
end
end
end
|
#in_state(status) ⇒ Object
How many alerts are in the given state? If none, say so, rather than just printing nothing.
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/wavefront-cli/alert.rb', line 91
def in_state(status)
options[:all] = true
ret = find_in_state(status)
exit if options[:noop]
return ret unless ret.is_a?(Wavefront::Response) && ret.empty?
ok_exit(format('No alerts are currently %<status>s.', status: status))
end
|
#state_time(item) ⇒ Integer
Snoozed alerts don’t have a start time, they have a “snoozed” time. This is -1 if they are snoozed forever: the formatting methods know what to do with that.
124
125
126
127
128
129
|
# File 'lib/wavefront-cli/alert.rb', line 124
def state_time(item)
return item[:event][:startTime] if item.key?(:event)
return item[:snoozed] if item.key?(:snoozed)
nil
end
|