class WavefrontCli::Alert
CLI coverage for the v2 'alert' API.
Public Instance Methods
affected_hosts_for_id(id)
click to toggle source
# File lib/wavefront-cli/alert.rb, line 167 def affected_hosts_for_id(id) resp = wf.describe(id) return if options[:noop] return resp unless resp.ok? && resp.response.key?(:failingHostLabelPairs) resp.tap do |r| r.response = r.response[:failingHostLabelPairs].map { |h| h[:host] } end end
all_affected_hosts()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 158 def all_affected_hosts cannot_noop! in_state(:firing).tap do |r| r.response = r.response.items.each_with_object({}) do |alert, aggr| aggr[alert[:id]] = affected_hosts_for_id(alert[:id]).response end end end
do_affected_hosts()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 53 def do_affected_hosts if options[:'<id>'] affected_hosts_for_id(options[:'<id>']) else all_affected_hosts end end
do_clone()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 37 def do_clone wf.clone(options[:'<id>'], options[:version]&.to_i) end
do_currently()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 61 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()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 33 def do_delete smart_delete end
do_describe()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 21 def do_describe wf.describe(options[:'<id>'], options[:version]) end
do_firing()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 71 def do_firing in_state(:firing) end
do_history()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 49 def do_history wf.history(options[:'<id>'], options[:offset], options[:limit]) end
do_install()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 89 def do_install wf.install(options[:'<id>']) end
do_latest()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 45 def do_latest wf.versions(options[:'<id>']) end
do_queries()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 79 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()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 25 def do_snooze wf.snooze(options[:'<id>'], options[:time]) end
do_snoozed()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 75 def do_snoozed in_state(:snoozed) end
do_summary()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 41 def do_summary wf.summary end
do_uninstall()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 93 def do_uninstall wf.uninstall(options[:'<id>']) end
do_unsnooze()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 29 def do_unsnooze wf.unsnooze(options[:'<id>']) end
find_in_state(status)
click to toggle source
Does the work for in_state
@param status [Symbol,String] the alert status you wish to
find
@return Wavefront::Response
# File lib/wavefront-cli/alert.rb, line 116 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()
click to toggle source
# File lib/wavefront-cli/alert.rb, line 15 def import_fields %i[name condition minutes target severity displayExpression tags additionalInformation resolveAfterMinutes alertType severityList conditions acl] end
import_to_create(raw)
click to toggle source
Take a previously exported alert, and construct a hash which create() can use to re-create it.
@param raw [Hash] Ruby hash of imported data
# File lib/wavefront-cli/alert.rb, line 145 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.compact end
in_state(status)
click to toggle source
How many alerts are in the given state? If none, say so, rather than just printing nothing.
# File lib/wavefront-cli/alert.rb, line 100 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)
click to toggle source
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. @return [Integer]
# File lib/wavefront-cli/alert.rb, line 133 def state_time(item) return item[:event][:startTime] if item.key?(:event) return item[:snoozed] if item.key?(:snoozed) nil end