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::HUMAN_TIME_FORMAT, Constants::HUMAN_TIME_FORMAT_MS
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_set, #do_tags
Methods inherited from Base
#_sdk_class, #cannot_noop!, #check_status, #conds_to_query, #dispatch, #display, #display_api_error, #display_no_api_response, #do_import, #do_list, #do_search, #do_undelete, #do_update, #extract_values, #failed_validation_message, #format_var, #handle_error, #handle_response, #hcl_fields, #initialize, #load_display_class, #load_file, #load_from_stdin, #mk_creds, #mk_opts, #no_api_response, #ok_exit, #one_or_all, #options_and_exit, #parseable_output, #range_hash, #run, #search_key, #smart_delete, #smart_delete_message, #validate_id, #validate_input, #validate_opts, #validate_tags, #validator_exception, #validator_method
Instance Method Details
#do_clone ⇒ Object
34
35
36
|
# File 'lib/wavefront-cli/alert.rb', line 34
def do_clone
wf.clone(options[:'<id>'], options[:version]&.to_i)
end
|
#do_currently ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/wavefront-cli/alert.rb', line 50
def do_currently
state = options[:'<state>'].to_s
if wf.respond_to?(state)
in_state(state)
else
abort format("'%s' is not a valid alert state.", state)
end
end
|
#do_delete ⇒ Object
30
31
32
|
# File 'lib/wavefront-cli/alert.rb', line 30
def do_delete
smart_delete
end
|
#do_describe ⇒ Object
18
19
20
|
# File 'lib/wavefront-cli/alert.rb', line 18
def do_describe
wf.describe(options[:'<id>'], options[:version])
end
|
#do_firing ⇒ Object
60
61
62
|
# File 'lib/wavefront-cli/alert.rb', line 60
def do_firing
in_state(:firing)
end
|
#do_history ⇒ Object
46
47
48
|
# File 'lib/wavefront-cli/alert.rb', line 46
def do_history
wf.history(options[:'<id>'], options[:offset], options[:limit])
end
|
#do_install ⇒ Object
78
79
80
|
# File 'lib/wavefront-cli/alert.rb', line 78
def do_install
wf.install(options[:'<id>'])
end
|
#do_latest ⇒ Object
42
43
44
|
# File 'lib/wavefront-cli/alert.rb', line 42
def do_latest
wf.versions(options[:'<id>'])
end
|
#do_queries ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/wavefront-cli/alert.rb', line 68
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
22
23
24
|
# File 'lib/wavefront-cli/alert.rb', line 22
def do_snooze
wf.snooze(options[:'<id>'], options[:time])
end
|
#do_snoozed ⇒ Object
64
65
66
|
# File 'lib/wavefront-cli/alert.rb', line 64
def do_snoozed
in_state(:snoozed)
end
|
#do_summary ⇒ Object
38
39
40
|
# File 'lib/wavefront-cli/alert.rb', line 38
def do_summary
wf.summary
end
|
#do_uninstall ⇒ Object
82
83
84
|
# File 'lib/wavefront-cli/alert.rb', line 82
def do_uninstall
wf.uninstall(options[:'<id>'])
end
|
#do_unsnooze ⇒ Object
26
27
28
|
# File 'lib/wavefront-cli/alert.rb', line 26
def do_unsnooze
wf.unsnooze(options[:'<id>'])
end
|
#find_in_state(status) ⇒ Object
Does the work for #in_state
101
102
103
104
105
106
107
108
109
|
# File 'lib/wavefront-cli/alert.rb', line 101
def find_in_state(status)
search = do_search([format('status=%s', status)])
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
13
14
15
16
|
# File 'lib/wavefront-cli/alert.rb', line 13
def import_fields
%w[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.
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/wavefront-cli/alert.rb', line 127
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.
89
90
91
92
93
94
|
# File 'lib/wavefront-cli/alert.rb', line 89
def in_state(status)
options[:all] = true
ret = find_in_state(status)
ok_exit(format('No alerts are currently %s.', status)) if ret.empty?
ret
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.
116
117
118
119
120
|
# File 'lib/wavefront-cli/alert.rb', line 116
def state_time(item)
return item[:event][:startTime] if item.key?(:event)
return item[:snoozed] if item.key?(:snoozed)
nil
end
|