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



394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/hawkular/alerts/alerts_api.rb', line 394

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

#actions ⇒ Object

Returns the value of attribute actions



388
389
390
# File 'lib/hawkular/alerts/alerts_api.rb', line 388

def actions
  @actions
end

#auto_disable ⇒ Object

Returns the value of attribute auto_disable



388
389
390
# File 'lib/hawkular/alerts/alerts_api.rb', line 388

def auto_disable
  @auto_disable
end

#auto_enable ⇒ Object

Returns the value of attribute auto_enable



388
389
390
# File 'lib/hawkular/alerts/alerts_api.rb', line 388

def auto_enable
  @auto_enable
end

#auto_resolve ⇒ Object

Returns the value of attribute auto_resolve



389
390
391
# File 'lib/hawkular/alerts/alerts_api.rb', line 389

def auto_resolve
  @auto_resolve
end

#auto_resolve_alerts ⇒ Object

Returns the value of attribute auto_resolve_alerts



389
390
391
# File 'lib/hawkular/alerts/alerts_api.rb', line 389

def auto_resolve_alerts
  @auto_resolve_alerts
end

#auto_resolve_match ⇒ Object

Returns the value of attribute auto_resolve_match



392
393
394
# File 'lib/hawkular/alerts/alerts_api.rb', line 392

def auto_resolve_match
  @auto_resolve_match
end

#conditions ⇒ Object (readonly)

Returns the value of attribute conditions



391
392
393
# File 'lib/hawkular/alerts/alerts_api.rb', line 391

def conditions
  @conditions
end

#context ⇒ Object

Returns the value of attribute context



388
389
390
# File 'lib/hawkular/alerts/alerts_api.rb', line 388

def context
  @context
end

#dampenings ⇒ Object (readonly)

Returns the value of attribute dampenings



391
392
393
# File 'lib/hawkular/alerts/alerts_api.rb', line 391

def dampenings
  @dampenings
end

#data_id_map ⇒ Object

Returns the value of attribute data_id_map



390
391
392
# File 'lib/hawkular/alerts/alerts_api.rb', line 390

def data_id_map
  @data_id_map
end

#description ⇒ Object

Returns the value of attribute description



390
391
392
# File 'lib/hawkular/alerts/alerts_api.rb', line 390

def description
  @description
end

#enabled ⇒ Object

Returns the value of attribute enabled



392
393
394
# File 'lib/hawkular/alerts/alerts_api.rb', line 392

def enabled
  @enabled
end

#event_category ⇒ Object

Returns the value of attribute event_category



390
391
392
# File 'lib/hawkular/alerts/alerts_api.rb', line 390

def event_category
  @event_category
end

#event_type ⇒ Object

Returns the value of attribute event_type



390
391
392
# File 'lib/hawkular/alerts/alerts_api.rb', line 390

def event_type
  @event_type
end

#firing_match ⇒ Object

Returns the value of attribute firing_match



392
393
394
# File 'lib/hawkular/alerts/alerts_api.rb', line 392

def firing_match
  @firing_match
end

#group ⇒ Object

Returns the value of attribute group



390
391
392
# File 'lib/hawkular/alerts/alerts_api.rb', line 390

def group
  @group
end

#id ⇒ Object

Returns the value of attribute id



388
389
390
# File 'lib/hawkular/alerts/alerts_api.rb', line 388

def id
  @id
end

#member_of ⇒ Object

Returns the value of attribute member_of



390
391
392
# File 'lib/hawkular/alerts/alerts_api.rb', line 390

def member_of
  @member_of
end

#name ⇒ Object

Returns the value of attribute name



388
389
390
# File 'lib/hawkular/alerts/alerts_api.rb', line 388

def name
  @name
end

#severity ⇒ Object

Returns the value of attribute severity



390
391
392
# File 'lib/hawkular/alerts/alerts_api.rb', line 390

def severity
  @severity
end

#tags ⇒ Object

Returns the value of attribute tags



389
390
391
# File 'lib/hawkular/alerts/alerts_api.rb', line 389

def tags
  @tags
end

#tenant ⇒ Object

Returns the value of attribute tenant



390
391
392
# File 'lib/hawkular/alerts/alerts_api.rb', line 390

def tenant
  @tenant
end

#type ⇒ Object

Returns the value of attribute type



389
390
391
# File 'lib/hawkular/alerts/alerts_api.rb', line 389

def type
  @type
end

Instance Method Details

#to_h ⇒ Object



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/hawkular/alerts/alerts_api.rb', line 424

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