lib/hawkular/alerts/alerts_api.rb in hawkular-client-5.0.0.pre1 vs lib/hawkular/alerts/alerts_api.rb in hawkular-client-5.0.0.pre2
- old
+ new
@@ -180,15 +180,11 @@
end
# Obtains action definition/plugin from the server.
# @param [String] action_plugin Id of the action plugin to fetch. If nil, all the plugins are fetched
def get_action_definition(action_plugin = nil)
- if action_plugin.nil?
- plugins = http_get('plugins')
- else
- plugins = [action_plugin]
- end
+ plugins = action_plugin.nil? ? http_get('plugins') : [action_plugin]
ret = {}
plugins.each do |p|
ret[p] = http_get("/plugins/#{p}")
end
ret
@@ -230,11 +226,12 @@
end
# Obtain the alerts for the Trigger with the passed id
# @param [String] trigger_id Id of the trigger that has fired the alerts
# @return [Array<Alert>] List of alerts for the trigger. Can be empty
- def get_alerts_for_trigger(trigger_id) # TODO: add additional filters
+ def get_alerts_for_trigger(trigger_id)
+ # TODO: add additional filters
return [] unless trigger_id
url = '/?triggerIds=' + trigger_id
ret = http_get(url)
val = []
@@ -252,11 +249,11 @@
# List fired alerts
# @param [Hash] criteria optional query criteria
# @param [Array] tenants optional list of tenants. The elements of the array can be any object
# convertible to a string
# @return [Array<Alert>] List of alerts in the system. Can be empty
- def alerts(criteria: {}, tenants:nil)
+ def alerts(criteria: {}, tenants: nil)
query = generate_query_params(criteria)
uri = tenants ? '/admin/alerts/' : '/'
ret = http_get(uri + query, multi_tenants_header(tenants))
val = []
ret.each { |a| val.push(Alert.new(a)) }
@@ -387,11 +384,11 @@
class Trigger
attr_accessor :id, :name, :context, :actions, :auto_disable, :auto_enable
attr_accessor :auto_resolve, :auto_resolve_alerts, :tags, :type
attr_accessor :tenant, :description, :group, :severity, :event_type, :event_category, :member_of, :data_id_map
attr_reader :conditions, :dampenings
- attr_accessor :enabled, :actions, :firing_match, :auto_resolve_match
+ attr_accessor :enabled, :firing_match, :auto_resolve_match
def initialize(trigger_hash)
return if trigger_hash.nil?
@_hash = trigger_hash
@@ -425,13 +422,14 @@
trigger_hash = {}
to_camel = lambda do |x|
ret = x.to_s.split('_').collect(&:capitalize).join
ret[0, 1].downcase + ret[1..-1]
end
- fields = [:id, :name, :enabled, :severity, :auto_resolve, :auto_resolve_alerts, :event_type, :event_category,
- :description, :auto_enable, :auto_disable, :context, :type, :tags, :member_of, :data_id_map,
- :firing_match, :auto_resolve_match]
+ fields = %i[id name enabled severity auto_resolve auto_resolve_alerts
+ event_type event_category description auto_enable auto_disable
+ context type tags member_of data_id_map firing_match
+ auto_resolve_match]
fields.each do |field|
camelized_field = to_camel.call(field)
field_value = __send__ field
trigger_hash[camelized_field] = field_value unless field_value.nil?
@@ -446,10 +444,11 @@
# Representing of one Condition
class Condition
attr_accessor :condition_id, :type, :operator, :threshold
attr_accessor :trigger_mode, :data_id, :data2_id, :data2_multiplier
+ attr_accessor :alerter_id, :expression
attr_reader :condition_set_size, :condition_set_index, :trigger_id
def initialize(cond_hash)
@condition_id = cond_hash['conditionId']
@type = cond_hash['type']
@@ -459,11 +458,12 @@
@trigger_mode = cond_hash['triggerMode']
@data_id = cond_hash['dataId']
@data2_id = cond_hash['data2Id']
@data2_multiplier = cond_hash['data2Multiplier']
@trigger_id = cond_hash['triggerId']
- @interval = cond_hash['interval']
+ @alerter_id = cond_hash['alerterId']
+ @expression = cond_hash['expression']
end
def to_h
cond_hash = {}
cond_hash['conditionId'] = @condition_id
@@ -474,11 +474,12 @@
cond_hash['triggerMode'] = @trigger_mode
cond_hash['dataId'] = @data_id
cond_hash['data2Id'] = @data2_id
cond_hash['data2Multiplier'] = @data2_multiplier
cond_hash['triggerId'] = @trigger_id
- cond_hash['interval'] = @interval
+ cond_hash['alerterId'] = @alerter_id
+ cond_hash['expression'] = @expression
cond_hash
end
end
# Representing of one GroupConditionsInfo
@@ -599,11 +600,11 @@
a = @lifecycle.nil? ? [] : @lifecycle.select { |l| l['status'].eql? status }
a.empty? ? nil : a.last['user']
end
# for some API back compatibility
- alias_method :ackBy, :ack_by
- alias_method :resolvedBy, :resolved_by
+ alias ackBy ack_by
+ alias resolvedBy resolved_by
end
# Representation of one event.
# The name of the members are literally what they are in the JSON sent from the
# server and not 'rubyfied'. So 'eventId' and not 'event_id'