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.



391
392
393
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
# File 'lib/hawkular/alerts/alerts_api.rb', line 391

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.



385
386
387
# File 'lib/hawkular/alerts/alerts_api.rb', line 385

def actions
  @actions
end

#auto_disableObject

Returns the value of attribute auto_disable.



385
386
387
# File 'lib/hawkular/alerts/alerts_api.rb', line 385

def auto_disable
  @auto_disable
end

#auto_enableObject

Returns the value of attribute auto_enable.



385
386
387
# File 'lib/hawkular/alerts/alerts_api.rb', line 385

def auto_enable
  @auto_enable
end

#auto_resolveObject

Returns the value of attribute auto_resolve.



386
387
388
# File 'lib/hawkular/alerts/alerts_api.rb', line 386

def auto_resolve
  @auto_resolve
end

#auto_resolve_alertsObject

Returns the value of attribute auto_resolve_alerts.



386
387
388
# File 'lib/hawkular/alerts/alerts_api.rb', line 386

def auto_resolve_alerts
  @auto_resolve_alerts
end

#auto_resolve_matchObject

Returns the value of attribute auto_resolve_match.



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

def auto_resolve_match
  @auto_resolve_match
end

#conditionsObject (readonly)

Returns the value of attribute conditions.



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

def conditions
  @conditions
end

#contextObject

Returns the value of attribute context.



385
386
387
# File 'lib/hawkular/alerts/alerts_api.rb', line 385

def context
  @context
end

#dampeningsObject (readonly)

Returns the value of attribute dampenings.



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

def dampenings
  @dampenings
end

#data_id_mapObject

Returns the value of attribute data_id_map.



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

def data_id_map
  @data_id_map
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#enabledObject

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

#event_categoryObject

Returns the value of attribute event_category.



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

def event_category
  @event_category
end

#event_typeObject

Returns the value of attribute event_type.



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

def event_type
  @event_type
end

#firing_matchObject

Returns the value of attribute firing_match.



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

def firing_match
  @firing_match
end

#groupObject

Returns the value of attribute group.



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

def group
  @group
end

#idObject

Returns the value of attribute id.



385
386
387
# File 'lib/hawkular/alerts/alerts_api.rb', line 385

def id
  @id
end

#member_ofObject

Returns the value of attribute member_of.



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

def member_of
  @member_of
end

#nameObject

Returns the value of attribute name.



385
386
387
# File 'lib/hawkular/alerts/alerts_api.rb', line 385

def name
  @name
end

#severityObject

Returns the value of attribute severity.



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

def severity
  @severity
end

#tagsObject

Returns the value of attribute tags.



386
387
388
# File 'lib/hawkular/alerts/alerts_api.rb', line 386

def tags
  @tags
end

#tenantObject

Returns the value of attribute tenant.



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

def tenant
  @tenant
end

#typeObject

Returns the value of attribute type.



386
387
388
# File 'lib/hawkular/alerts/alerts_api.rb', line 386

def type
  @type
end

Instance Method Details

#to_hObject



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

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 = %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?
  end

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

  trigger_hash
end