Class: Hawkular::Alerts::Trigger

Inherits:
Object
  • Object
show all
Defined in:
lib/hawkular/alerts/alerts_api.rb

Overview

Representation of one Trigger (22 known properties: “enabled”, “autoResolveMatch”, “name”, “memberOf”, “autoEnable”, “firingMatch”, “tags”, “id”, “source”, “tenantId”, “eventText”, “context”, “eventType”, “autoResolveAlerts”, “dataIdMap”, “eventCategory”, “autoDisable”, “type”, “description”, “severity”, “autoResolve”, “actions”])

Defined Under Namespace

Classes: Action, Condition, Dampening, GroupConditionsInfo, GroupMemberInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trigger_hash) ⇒ Trigger

Returns a new instance of Trigger



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/hawkular/alerts/alerts_api.rb', line 355

def initialize(trigger_hash)
  return if trigger_hash.nil?

  @_hash = trigger_hash
  @conditions = []
  @dampenings = []
  @actions = []
  @id = trigger_hash['id']
  @name = trigger_hash['name']
  @enabled = trigger_hash['enabled']
  @severity = trigger_hash['severity']
  @auto_resolve = trigger_hash['autoResolve']
  @auto_resolve_alerts = trigger_hash['autoResolveAlerts']
  @event_type = trigger_hash['eventType']
  @event_category = trigger_hash['eventCategory']
  @member_of = trigger_hash['memberOf']
  @data_id_map = trigger_hash['dataIdMap']
  @tenant = trigger_hash['tenantId']
  @description = trigger_hash['description']
  @auto_enable = trigger_hash['autoEnable']
  @auto_disable = trigger_hash['autoDisable']
  @context = trigger_hash['context']
  @type = trigger_hash['type']
  @tags = trigger_hash['tags']
  @firing_match = trigger_hash['firingMatch']
  @auto_resolve_match = trigger_hash['autoResolveMatch']
  # acts = trigger_hash['actions']
  # acts.each { |a| @actions.push(Action.new(a)) } unless acts.nil?
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions



349
350
351
# File 'lib/hawkular/alerts/alerts_api.rb', line 349

def actions
  @actions
end

#auto_disableObject

Returns the value of attribute auto_disable



349
350
351
# File 'lib/hawkular/alerts/alerts_api.rb', line 349

def auto_disable
  @auto_disable
end

#auto_enableObject

Returns the value of attribute auto_enable



349
350
351
# File 'lib/hawkular/alerts/alerts_api.rb', line 349

def auto_enable
  @auto_enable
end

#auto_resolveObject

Returns the value of attribute auto_resolve



350
351
352
# File 'lib/hawkular/alerts/alerts_api.rb', line 350

def auto_resolve
  @auto_resolve
end

#auto_resolve_alertsObject

Returns the value of attribute auto_resolve_alerts



350
351
352
# File 'lib/hawkular/alerts/alerts_api.rb', line 350

def auto_resolve_alerts
  @auto_resolve_alerts
end

#auto_resolve_matchObject

Returns the value of attribute auto_resolve_match



353
354
355
# File 'lib/hawkular/alerts/alerts_api.rb', line 353

def auto_resolve_match
  @auto_resolve_match
end

#conditionsObject (readonly)

Returns the value of attribute conditions



352
353
354
# File 'lib/hawkular/alerts/alerts_api.rb', line 352

def conditions
  @conditions
end

#contextObject

Returns the value of attribute context



349
350
351
# File 'lib/hawkular/alerts/alerts_api.rb', line 349

def context
  @context
end

#dampeningsObject (readonly)

Returns the value of attribute dampenings



352
353
354
# File 'lib/hawkular/alerts/alerts_api.rb', line 352

def dampenings
  @dampenings
end

#data_id_mapObject

Returns the value of attribute data_id_map



351
352
353
# File 'lib/hawkular/alerts/alerts_api.rb', line 351

def data_id_map
  @data_id_map
end

#descriptionObject

Returns the value of attribute description



351
352
353
# File 'lib/hawkular/alerts/alerts_api.rb', line 351

def description
  @description
end

#enabledObject

Returns the value of attribute enabled



353
354
355
# File 'lib/hawkular/alerts/alerts_api.rb', line 353

def enabled
  @enabled
end

#event_categoryObject

Returns the value of attribute event_category



351
352
353
# File 'lib/hawkular/alerts/alerts_api.rb', line 351

def event_category
  @event_category
end

#event_typeObject

Returns the value of attribute event_type



351
352
353
# File 'lib/hawkular/alerts/alerts_api.rb', line 351

def event_type
  @event_type
end

#firing_matchObject

Returns the value of attribute firing_match



353
354
355
# File 'lib/hawkular/alerts/alerts_api.rb', line 353

def firing_match
  @firing_match
end

#groupObject

Returns the value of attribute group



351
352
353
# File 'lib/hawkular/alerts/alerts_api.rb', line 351

def group
  @group
end

#idObject

Returns the value of attribute id



349
350
351
# File 'lib/hawkular/alerts/alerts_api.rb', line 349

def id
  @id
end

#member_ofObject

Returns the value of attribute member_of



351
352
353
# File 'lib/hawkular/alerts/alerts_api.rb', line 351

def member_of
  @member_of
end

#nameObject

Returns the value of attribute name



349
350
351
# File 'lib/hawkular/alerts/alerts_api.rb', line 349

def name
  @name
end

#severityObject

Returns the value of attribute severity



351
352
353
# File 'lib/hawkular/alerts/alerts_api.rb', line 351

def severity
  @severity
end

#tagsObject

Returns the value of attribute tags



350
351
352
# File 'lib/hawkular/alerts/alerts_api.rb', line 350

def tags
  @tags
end

#tenantObject

Returns the value of attribute tenant



351
352
353
# File 'lib/hawkular/alerts/alerts_api.rb', line 351

def tenant
  @tenant
end

#typeObject

Returns the value of attribute type



350
351
352
# File 'lib/hawkular/alerts/alerts_api.rb', line 350

def type
  @type
end

Instance Method Details

#to_hObject



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/hawkular/alerts/alerts_api.rb', line 385

def to_h
  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.each do |field|
    camelized_field = to_camel.call(field)
    field_value = __send__ field
    trigger_hash[camelized_field] = field_value unless field_value.nil?
  end

  trigger_hash['tenantId'] = @tenant unless @tenant.nil?
  trigger_hash['actions'] = []
  @actions.each { |d| trigger_hash['actions'].push d.to_h }

  trigger_hash
end